You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Proposal: Drop smudge in favor of post-checkout hook #616
The improvements of the batch API and the updated fetch command are wasted on the Git smudge filters. Each checked out file has to invoke smudge, which only operates on a single file at a time. There's no parallelism here (unless Git adds it).
The post-checkout hook runs after a git checkout is run after updating the work tree. The hook can then call git lfs pull, which downloads the LFS objects for the current working directory and replaces the pointers. This means it can make full use of the batch API and concurrent transfers.
Some downsides:
Cloning is more difficult. I don't know of a way to clone with a post-checkout hook. We could solve this with a git lfs clone wrapper.
What happens if users have their own post-checkout scripts? I know that the Unreal Engine uses one, for example. Git needs a way for multiple tools to add their hooks in harmony.
Unreal Engine uses post-checkot hook for very similar usecase: they run GitDependencies.exe tool (written by Epic Games) for downloading large binaries files.
Finally got a chance to sit down with this, and there are a few issues I'd like to address. The idea was to use the post-checkout hook as a means to trigger git lfs pull, which would in effect run the smudge filter in parallel.
Once I implemented this, nearly a third of integration tests were failing. I discovered the culprit is usually cloning a bare repo, and then pulling down commits from the remote later. This edge case does not invoke the post-checkout hook. To me, this seems like a correct implementation of post-checkout since going from no commits to some commits doesn't involve a checkout. I am not immediately sure how to solve this problem beyond forcing users to run git lfs pull in that scenario.
@whoisj brings up another issue, resets in Git also do not trigger a post-checkout.
To me, these two cases together are significant for users of Git LFS. I'd like to discuss whether or not a post-checkout hook is the ideal way to implement this, and see if there are any other options.
I looked at hooks as an alternative to filters a while ago (before I started contributing to git-lfs), and found they were too full of holes on the client side, they were clearly envisioned mostly for server-side processing. I was hoping you might find something I missed but I'm not surprised you've come to this conclusion. I agree the smudge filters should remain, as much as it's not the ideal.
Bear in mind that people using git lfs fetch --recent will avoid some of the waiting involved in future, since there's a better chance that they will already have downloaded objects by the time they check out / pull, particularly if they regularly run 'git fetch' on its own (and some tools, like SourceTree, have an option to run fetch periodically in the background).
I'm in 2 minds about post-checkout, I think it might be harder to explain to people which conditions it covers and which it doesn't, rather than simply giving people the option to turn off automatic lfs pointer->content conversion entirely & saying they have to run git lfs checkout themselves always.
A while back I started to play around with this idea, but didn't get very far. It might be a bad idea, so if you think it is or prove it is, I'm fine with that 😄
The smudge filters could start and feed a daemon, similar to the way the credential cache daemon works. It could go something like this:
Smudge filter starts
Start daemon if it has not been started (maybe check for a lock file in .git/lfs or something)
Feed oid/pointer data to the daemon
Output the pointer data
Daemon runs
Receive input from a smudge filter
Download file, update git index (possible batching)
Exit after n seconds of inactivity (no active transfers, nothing received from filter)
The smudge filter can have logic on whether to do this or behave normally, depending on configuration. It could perhaps also make this choice based on object sizes, letting small objects operate normally and feeding large ones to a daemon. I don't know that that would be any benefit or not.
The immediate caveat with this approach is that the user feedback is poor. If the filters don't wait for the daemon to finish the repo will be in a weird, changing state until it finishes. There also may be a problem updating the index while the clone is running. I don't know for sure if git locks the index for the entire operation, or per file.
I think we can work around that, though. The smudge filter that starts the daemon ought to be able to look at .git/HEAD (or something, that stuff should all be there by that time) and know what ref it's checking out. It should be able to scan for lfs objects to know how many it's going to check out, and start up the daemon with those expectations. The daemon could then give better feedback and know when it's done. It could even tell each smudge command which number it is, so the last smudge filter to run could wait for the daemon to exit.
I'll admit that's fairly complicated. There may still be index updating issues and this approach may not work at all, but I thought I'd throw it out there anyway. I think it's possible, but the cost may not be worth it.
I think this is a good idea but that the unpredictable parallel behaviour will be a bitch. What files git locks while it's calling all the smudge filters is certainly one issue, but another is simply the daemon fighting with the smudge filter (one writing the pointer data, the other writing the real data) if the retrieval is fast enough. Then there's just the inevitable nastiness of using lock files & daemons on Windows (cue all sorts of crazy problems from slight delays in locks being visibly released by the OS, leading to retries and horrid edge cases).
It would be nice if we could take the idea of a background aggregation tool but make it more predictable, say by having the entire git command book-ended so that the daemon starts at the beginning, and finishes up at the end of all the smudge filters, at that point updating the working copy and the index in bulk when it knows everything else is out the way (but being able to do anything else in parallel). I can't see a way of doing that reliably without fully wrapping the git commands though. But then again, maybe that would be ok as an option for those wanting higher perf? Each wrapper command could just use goroutines for parallelism and then call out to git for everything else, all state would be contained & no need for lock files, daemons & timeouts that I'm pretty sure will bite us in the arse in random ways.
Wrapping git would make many things we do much easier. I like that we've avoided it to this point, but a higher perf clone/checkout wrapper is probably the easiest way to go. The wrapper command doesn't need to be complex, it can set an env variable which tells the smudge filters to act as a passthrough then run lfs fetch and friends after git runs. It shouldn't need any parallelism or daemons.
Yeah I think that's the pragmatic option. Although we could still probably still make a start on the required work as the smudge filters are running; either on-demand by unambiguous output messages in stderr that we see from the wrapper (and not reflecting that back to the real stderr) or even by pre-empting the process entirely and starting work that's read-only on the core git data (not not necessarily lfs data) in parallel at the beginning of the wrapper - since in a git checkout wrapper we already have all the information we need to start doing the git lfs fetch before git even starts, only the git lfs checkout has to be done at the end.
I'm with @sinbad on this one; a background worker daemon would be awesome, but super tricky to reason about. I'm sure there are a countless number of ways that a user could mess up that process, and having to recover from all of them would be very annoying.
I'm not opposed to wrapping more git commands for users that want/need higher perf out of Git LFS. I think we should still prefer the unwrapped commands, but as long as we're explicit about that and the wrapped commands have well-documented behavior, I think we'd be cool.
Agreed on all points. FWIW: one of my original plans over a year ago included adding support through hub. This was before I knew about the pre-push hook though. I was worried about adding an extra step to all pushes.
I think the implicit daemon will create a lot of problems (for example, it will block the removal of directories in Windows).
Loss of explicit complete the process of obtaining data from the server as unacceptable (mainly to build farms and build scripts). Because of this, the demon only reduces the severity of the handshake problem. But can not solve the problem of sequential queries.
So it is not clear how the demon had to deal with a filter:
TCP - is not safe in a multi-user environment;
File sockets - is platform specific.
I think it is necessary to solve the problem by updating Git API. The rest of the options seem too complicated to operate.
Yeah, ideally such things would be more of a stopgap until git apis are changed.
One issue is that this problem is far worse on windows, and the core git devs simply do not historically care about windows. I therefore do not have high hopes for the git api being changed anytime soon to accommodate this. This is why I'm proposing more drastic hacks/workarounds for this problem than I would normally entertain.
Oh well, I will just skip smudge on clone + git lfs fetch for now and hope the apis get changed one day.
@my-digital-decay Yes, you can define the env var GIT_LFS_SKIP_SMUDGE=1 then just use git lfs pull (or use fetch and checkout separately if you'd prefer) instead to download. You can also make this setting permanent for this repo, run git lfs install --skip-smudge.
@WestonThayer Assuming you're using the latest git-lfs, once you've done the git lfs install --skip-smudge, you can just git clone https://example.git and run the git lfs pull right after. no need for using -n with clone.
git lfs install --skip-smudge adds a setting to your ~/.gitconfig which git lfs checks during the git clone, so that's why this works.
@ajohnson23 thank you, I think I have my head wrapped around it now. That looked like it downloaded all my lfs files sequentially. Is there a way to parallelize at least part of it?
The default is concurrenttransfers = 3 so it should have been parallel so long as the smudge filter wasn't enabled.
Personally I prefer to leave the smudge filter enabled globally so that switching branch automatically updates my working copy, and only disable it at clone time to speed things up. To do that you just need to set the environment variable GIT_LFS_SKIP_SMUDGE=1 before git clone to have the same effect as git lfs install --skip-smudge, but just for the clone command. I don't like to have to remember to git lfs pull every time I switch branch.
Activity
whoisj commentedon Aug 28, 2015
Are post-checkout hooks invoked with actions like reset?
technoweenie commentedon Aug 28, 2015
@whoisj I think so, but that's definitely a use case we'd need to check.
ttaylorr commentedon Aug 29, 2015
I've started an implementation which I'm tracking over at ttaylorr#1 😄.
bozaro commentedon Aug 29, 2015
Unreal Engine uses post-checkot hook for very similar usecase: they run GitDependencies.exe tool (written by Epic Games) for downloading large binaries files.
I asked them about their git-lfs plans: https://answers.unrealengine.com/questions/293214/gitdependenciesexe-vs-git-lfs.html
ttaylorr commentedon Sep 2, 2015
Finally got a chance to sit down with this, and there are a few issues I'd like to address. The idea was to use the
post-checkouthook as a means to triggergit lfs pull, which would in effect run the smudge filter in parallel.Once I implemented this, nearly a third of integration tests were failing. I discovered the culprit is usually cloning a bare repo, and then pulling down commits from the remote later. This edge case does not invoke the
post-checkouthook. To me, this seems like a correct implementation ofpost-checkoutsince going from no commits to some commits doesn't involve a checkout. I am not immediately sure how to solve this problem beyond forcing users to rungit lfs pullin that scenario.@whoisj brings up another issue,
resets in Git also do not trigger a post-checkout.To me, these two cases together are significant for users of Git LFS. I'd like to discuss whether or not a
post-checkouthook is the ideal way to implement this, and see if there are any other options.technoweenie commentedon Sep 3, 2015
Thanks for checking this out! Let's start small:
git lfs initto swap lfs download modes: smudge filter vs post-checkout.ttaylorr commentedon Sep 3, 2015
My pleasure! I think taking that route would be a solid move.
sinbad commentedon Sep 3, 2015
I looked at hooks as an alternative to filters a while ago (before I started contributing to git-lfs), and found they were too full of holes on the client side, they were clearly envisioned mostly for server-side processing. I was hoping you might find something I missed but I'm not surprised you've come to this conclusion. I agree the smudge filters should remain, as much as it's not the ideal.
Bear in mind that people using
git lfs fetch --recentwill avoid some of the waiting involved in future, since there's a better chance that they will already have downloaded objects by the time they check out / pull, particularly if they regularly run 'git fetch' on its own (and some tools, like SourceTree, have an option to run fetch periodically in the background).I'm in 2 minds about post-checkout, I think it might be harder to explain to people which conditions it covers and which it doesn't, rather than simply giving people the option to turn off automatic lfs pointer->content conversion entirely & saying they have to run
git lfs checkoutthemselves always.rubyist commentedon Sep 3, 2015
A while back I started to play around with this idea, but didn't get very far. It might be a bad idea, so if you think it is or prove it is, I'm fine with that 😄
The smudge filters could start and feed a daemon, similar to the way the credential cache daemon works. It could go something like this:
.git/lfsor something)nseconds of inactivity (no active transfers, nothing received from filter)The smudge filter can have logic on whether to do this or behave normally, depending on configuration. It could perhaps also make this choice based on object sizes, letting small objects operate normally and feeding large ones to a daemon. I don't know that that would be any benefit or not.
The immediate caveat with this approach is that the user feedback is poor. If the filters don't wait for the daemon to finish the repo will be in a weird, changing state until it finishes. There also may be a problem updating the index while the clone is running. I don't know for sure if git locks the index for the entire operation, or per file.
I think we can work around that, though. The smudge filter that starts the daemon ought to be able to look at
.git/HEAD(or something, that stuff should all be there by that time) and know what ref it's checking out. It should be able to scan for lfs objects to know how many it's going to check out, and start up the daemon with those expectations. The daemon could then give better feedback and know when it's done. It could even tell each smudge command which number it is, so the last smudge filter to run could wait for the daemon to exit.I'll admit that's fairly complicated. There may still be index updating issues and this approach may not work at all, but I thought I'd throw it out there anyway. I think it's possible, but the cost may not be worth it.
sinbad commentedon Sep 3, 2015
I think this is a good idea but that the unpredictable parallel behaviour will be a bitch. What files git locks while it's calling all the smudge filters is certainly one issue, but another is simply the daemon fighting with the smudge filter (one writing the pointer data, the other writing the real data) if the retrieval is fast enough. Then there's just the inevitable nastiness of using lock files & daemons on Windows (cue all sorts of crazy problems from slight delays in locks being visibly released by the OS, leading to retries and horrid edge cases).
It would be nice if we could take the idea of a background aggregation tool but make it more predictable, say by having the entire git command book-ended so that the daemon starts at the beginning, and finishes up at the end of all the smudge filters, at that point updating the working copy and the index in bulk when it knows everything else is out the way (but being able to do anything else in parallel). I can't see a way of doing that reliably without fully wrapping the git commands though. But then again, maybe that would be ok as an option for those wanting higher perf? Each wrapper command could just use goroutines for parallelism and then call out to git for everything else, all state would be contained & no need for lock files, daemons & timeouts that I'm pretty sure will bite us in the arse in random ways.
rubyist commentedon Sep 3, 2015
Wrapping git would make many things we do much easier. I like that we've avoided it to this point, but a higher perf clone/checkout wrapper is probably the easiest way to go. The wrapper command doesn't need to be complex, it can set an env variable which tells the smudge filters to act as a passthrough then run
lfs fetchand friends after git runs. It shouldn't need any parallelism or daemons.sinbad commentedon Sep 3, 2015
Yeah I think that's the pragmatic option. Although we could still probably still make a start on the required work as the smudge filters are running; either on-demand by unambiguous output messages in stderr that we see from the wrapper (and not reflecting that back to the real stderr) or even by pre-empting the process entirely and starting work that's read-only on the core git data (not not necessarily lfs data) in parallel at the beginning of the wrapper - since in a
git checkoutwrapper we already have all the information we need to start doing thegit lfs fetchbefore git even starts, only thegit lfs checkouthas to be done at the end.ttaylorr commentedon Sep 3, 2015
I'm with @sinbad on this one; a background worker daemon would be awesome, but super tricky to reason about. I'm sure there are a countless number of ways that a user could mess up that process, and having to recover from all of them would be very annoying.
I'm not opposed to wrapping more git commands for users that want/need higher perf out of Git LFS. I think we should still prefer the unwrapped commands, but as long as we're explicit about that and the wrapped commands have well-documented behavior, I think we'd be cool.
technoweenie commentedon Sep 4, 2015
Agreed on all points. FWIW: one of my original plans over a year ago included adding support through hub. This was before I knew about the
pre-pushhook though. I was worried about adding an extra step to all pushes.14 remaining items
bozaro commentedon Oct 6, 2015
I think the implicit daemon will create a lot of problems (for example, it will block the removal of directories in Windows).
Loss of explicit complete the process of obtaining data from the server as unacceptable (mainly to build farms and build scripts). Because of this, the demon only reduces the severity of the handshake problem. But can not solve the problem of sequential queries.
So it is not clear how the demon had to deal with a filter:
I think it is necessary to solve the problem by updating Git API. The rest of the options seem too complicated to operate.
AndrewJDR commentedon Oct 6, 2015
Yeah, ideally such things would be more of a stopgap until git apis are changed.
One issue is that this problem is far worse on windows, and the core git devs simply do not historically care about windows. I therefore do not have high hopes for the git api being changed anytime soon to accommodate this. This is why I'm proposing more drastic hacks/workarounds for this problem than I would normally entertain.
Oh well, I will just skip smudge on clone + git lfs fetch for now and hope the apis get changed one day.
gurugray commentedon Nov 18, 2015
👍
shuhrat commentedon Nov 24, 2015
+1
flyingrobots commentedon Dec 12, 2015
+1 plz fix
my-digital-decay commentedon Dec 12, 2015
Does anyone have a working post-hook solution to this problem as a stop gap until a more robust solution is implemented?
sinbad commentedon Dec 14, 2015
@my-digital-decay Yes, you can define the env var
GIT_LFS_SKIP_SMUDGE=1then just usegit lfs pull(or usefetchandcheckoutseparately if you'd prefer) instead to download. You can also make this setting permanent for this repo, rungit lfs install --skip-smudge.my-digital-decay commentedon Dec 14, 2015
Thanks! I'll give that a try.
WestonThayer commentedon Jan 29, 2016
@sinbad, can you walk me through how to do this on a new clone? I tried:
git clone -n https://myrepo.gitThat seemed to clone without engaging the lfs downloads. Then I tried:
git lfs install --skip-smudgegit lfs pullGit lfs then downloaded the files as one batch, but then error'd out. I'm guessing this is because the HEAD wasn't checked out by git clone -n...
AndrewJDR commentedon Jan 29, 2016
@WestonThayer Assuming you're using the latest git-lfs, once you've done the
git lfs install --skip-smudge, you can justgit clone https://example.gitand run thegit lfs pullright after. no need for using -n with clone.git lfs install --skip-smudgeadds a setting to your ~/.gitconfig which git lfs checks during the git clone, so that's why this works.WestonThayer commentedon Jan 29, 2016
@ajohnson23 thank you, I think I have my head wrapped around it now. That looked like it downloaded all my lfs files sequentially. Is there a way to parallelize at least part of it?
AndrewJDR commentedon Jan 29, 2016
@WestonThayer Add the following to your .gitconfig, and tweak concurrenttransfers to your liking:
sinbad commentedon Jan 29, 2016
The default is
concurrenttransfers = 3so it should have been parallel so long as the smudge filter wasn't enabled.Personally I prefer to leave the smudge filter enabled globally so that switching branch automatically updates my working copy, and only disable it at clone time to speed things up. To do that you just need to set the environment variable
GIT_LFS_SKIP_SMUDGE=1beforegit cloneto have the same effect asgit lfs install --skip-smudge, but just for the clone command. I don't like to have to remember togit lfs pullevery time I switch branch.WestonThayer commentedon Feb 23, 2016
Thanks I get it now. I posted a summary for others.