Skip to content

Proposal: Drop smudge in favor of post-checkout hook #616

Closed

Description

@technoweenie

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:

  1. 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.
  2. 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.

Activity

  1. whoisj commented on Aug 28, 2015

    @whoisj

    Are post-checkout hooks invoked with actions like reset?

  2. technoweenie commented on Aug 28, 2015

    @technoweenie
    ContributorAuthor

    @whoisj I think so, but that's definitely a use case we'd need to check.

  3. ttaylorr commented on Aug 29, 2015

    @ttaylorr
    Contributor

    I've started an implementation which I'm tracking over at ttaylorr#1 😄.

  4. bozaro commented on Aug 29, 2015

    @bozaro
    Contributor

    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

  5. ttaylorr commented on Sep 2, 2015

    @ttaylorr
    Contributor

    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.

  6. technoweenie commented on Sep 3, 2015

    @technoweenie
    ContributorAuthor

    Thanks for checking this out! Let's start small:

    1. Keep the current smudge filter as the default.
    2. You had the idea in chat of passing a flag to git lfs init to swap lfs download modes: smudge filter vs post-checkout.
    3. Be upfront about all the caveats that we know about so users can make an informed decision if smudge filters take too long.
  7. ttaylorr commented on Sep 3, 2015

    @ttaylorr
    Contributor

    My pleasure! I think taking that route would be a solid move.

  8. sinbad commented on Sep 3, 2015

    @sinbad
    Contributor

    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.

  9. rubyist commented on Sep 3, 2015

    @rubyist
    Contributor

    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.

  10. sinbad commented on Sep 3, 2015

    @sinbad
    Contributor

    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.

  11. rubyist commented on Sep 3, 2015

    @rubyist
    Contributor

    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.

  12. sinbad commented on Sep 3, 2015

    @sinbad
    Contributor

    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.

  13. ttaylorr commented on Sep 3, 2015

    @ttaylorr
    Contributor

    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.

  14. technoweenie commented on Sep 4, 2015

    @technoweenie
    ContributorAuthor

    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.

  15. 14 remaining items

  16. bozaro commented on Oct 6, 2015

    @bozaro
    Contributor

    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.

  17. AndrewJDR commented on Oct 6, 2015

    @AndrewJDR
    Contributor

    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.

  18. gurugray commented on Nov 18, 2015

    @gurugray
    Contributor

    👍

  19. shuhrat commented on Nov 24, 2015

    @shuhrat

    +1

  20. flyingrobots commented on Dec 12, 2015

    @flyingrobots

    +1 plz fix

  21. my-digital-decay commented on Dec 12, 2015

    @my-digital-decay

    Does anyone have a working post-hook solution to this problem as a stop gap until a more robust solution is implemented?

  22. sinbad commented on Dec 14, 2015

    @sinbad
    Contributor

    @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.

  23. my-digital-decay commented on Dec 14, 2015

    @my-digital-decay

    Thanks! I'll give that a try.

  24. WestonThayer commented on Jan 29, 2016

    @WestonThayer

    @sinbad, can you walk me through how to do this on a new clone? I tried:

    git clone -n https://myrepo.git

    That seemed to clone without engaging the lfs downloads. Then I tried:

    git lfs install --skip-smudge
    git lfs pull

    Git 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...

  25. AndrewJDR commented on Jan 29, 2016

    @AndrewJDR
    Contributor

    @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.

  26. WestonThayer commented on Jan 29, 2016

    @WestonThayer

    @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?

  27. AndrewJDR commented on Jan 29, 2016

    @AndrewJDR
    Contributor

    @WestonThayer Add the following to your .gitconfig, and tweak concurrenttransfers to your liking:

    [lfs]
      ­­­­­­­batch = true
      concurrenttransfers = 6 
    
  28. sinbad commented on Jan 29, 2016

    @sinbad
    Contributor

    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.

  29. WestonThayer commented on Feb 23, 2016

    @WestonThayer

    Thanks I get it now. I posted a summary for others.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions