Skip to content

Add metadata headers when uploading blobs - #850

Closed
noamt wants to merge 9 commits into
git-lfs:masterfrom
noamt:upload-metadata-headers
Closed

noamt wants to merge 9 commits into
git-lfs:masterfrom
noamt:upload-metadata-headers

Conversation

@noamt

@noamt noamt commented Nov 21, 2015

Copy link
Copy Markdown
Contributor

Adding the following metadata headers to the upload request:

  • Object ID
  • Original file name
  • Git branch
  • Git ref

Adding these headers will benefit smart remote repositories and will help improve BLOB management and tracking.

…d request.

I call UploadObject with an Uploadable instead of an object reference. This gives me access to the blob's original file name. It's cleaner to add the parent object that already contains the information rather than passing through another individual variable
-Object ID
-Original file name
-Git branch
-Git ref

Adding these headers will benefit smart remote repositories and will help improve BLOB management and tracking
@noamt noamt changed the title Upload metadata headers Add metadata headers when uploading blobs Nov 21, 2015
@technoweenie

Copy link
Copy Markdown
Contributor

Nice idea, but I prefer adding it to the batch api json document as suggested in #845. Why would you want this on the storage upload requests, and not the batch API? LFS was designed to use a custom LFS API against a potentially generic storage backend (such as S3), which would ignore the extra headers. Would implementing #845 be enough, or do you need these headers?

Calling git.CurrentRef() AND git.CurrentBranch() is unnecessary. CurrentRef() returns more information. Both functions also invoke git rev-parse. We don't want to add 1 or 2 extra redundant git rev-parse calls to every file that gets uploaded. Might be better to add extra properties to *Uploadable instead, that get passed in somewhere at a higher level.

Super nitpicky: the X- prefix on custom headers is unnecessary. I'd probably go with header keys like Git-Lfs-*.

Comment thread lfs/client.go

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the type of error collecting thing that the commands package should take care of. The lfs package is more of a library with functions that should bubble errors up. The commands package is the CLI layer that prints and logs errors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. My reason for doing this was thinking that the headers are not critical to the operation, so the operation shouldn't fail if any problems come up.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a tracerx package that logs stuff if you have pass GIT_TRACE=1 to git lfs. This actually piggy backs on a core git feature, so running with git tracing on will show you all kinds of stuff :)

@noamt

noamt commented Nov 24, 2015

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback, you're right. It's more fitting in the batch API.
This also means that the batch API responses can be smarter in handling blob/path duplication.

I'd still like to have this feature, so if I understand you correctly you'd like to:

  • Move this info to the batch API JSON.
  • Drop the invocation of git.CurrentBranch().
  • Move the collection of git information up the stack.

Should I close this and open a new pull request?

@technoweenie

Copy link
Copy Markdown
Contributor
  • Move this info to the batch API JSON.
  • Drop the invocation of git.CurrentBranch().
  • Move the collection of git information up the stack.

👍 If you could update the batch api docs to go with it, that'd be cool too. Depends how involved you want to get with the project. Also, as you're messing around in the lfs client code, there IS an issue focused on cleaning it up: #779. So, don't hesitate to call out anything gross or weird.

Should I close this and open a new pull request?

You're welcome to do whatever you're most comfortable with. If it was me, I'd just keep hacking on this PR.

I appreciate you taking the time to dig in! Feel free to jump in chat if you want to talk. It's a very low volume channel, especially during a US holiday week like this week :)

@noamt

noamt commented Nov 25, 2015

Copy link
Copy Markdown
Contributor Author

Cheers, I'll get right on it.

@noamt

noamt commented Nov 26, 2015

Copy link
Copy Markdown
Contributor Author

OK, so I've shuffled things around and now each object of the batch request will contain the original file name and the batch request itself will contain the git revision.

So now I'd like to resolve and pass down the current branch. Assuming I'm at commands/command_pre_push.go:72, what do you think would be the best way to do that?

Comment thread lfs/client.go

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should introduce some kind struct here instead?

type BatchRequest struct {
  Operation string
  Rev string
}

// example pseudo code
ref, _ := git.CurrentRef()
req := lfs.NewRequest("download", objects)
req.Ref = ref.Name
lfs.Batch(req)

@technoweenie

Copy link
Copy Markdown
Contributor

So now I'd like to resolve and pass down the current branch. Assuming I'm at commands/command_pre_push.go:72, what do you think would be the best way to do that?

Probably call git.CurrentRef() in the command, and pass it to the uploadQueue. Maybe some kind of generic struct to represent the current state of the git repo, like the current ref. Or maybe all it needs is the ref?

Getting the filename may be tricky though. It'd have to come from lfs.ScanRefs(), and then passed to the uploadable.

// example
u, _ := lfs.NewUploadable(pointer.Oid, pointer.Name)
// it is possible for a single pointer to match multiple filenames
u.Filenames = pointer.Filenames

@noamt

noamt commented Nov 27, 2015

Copy link
Copy Markdown
Contributor Author

So yeah I've actually got the file name from the pointer and I enter it into each individual object so that's fine.

…into a new struct TransferMetadata instead of polluting the call stack with these individual parameters.

Also added helper methods "newDownloadTransferMetadata" and "newUploadTransferMetadata" for creating the new struct
@noamt

noamt commented Nov 27, 2015

Copy link
Copy Markdown
Contributor Author

OK I think I nailed it. Added a new struct object TransferMetadata to the queue instead of polluting all these methods as the amount of data will also probably grow.
If it looks good I'll continue on to add tests and documentation.

…oad operations

* Clarifying the names of the TransferMetadata
* Pass all TransferMetadata  object by value and not by pointer
@noamt

noamt commented Nov 29, 2015

Copy link
Copy Markdown
Contributor Author

Done and done

@noamt

noamt commented Dec 2, 2015

Copy link
Copy Markdown
Contributor Author

Though it's possible I don't think I've come across many instances of that case (local branch name != remote branch name) out in the wild , but I agree that it's better

@dluksza

dluksza commented Dec 2, 2015

Copy link
Copy Markdown

'ref' property can be used in Gerrit for branch based permissions, it would create a security hole if it is name of local branch not destination branch :)

@noamt

noamt commented Dec 6, 2015

Copy link
Copy Markdown
Contributor Author

Fixed. Thanks for the feedback @dluksza

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants