Skip to content

major pre-push optimization - #576

Closed
billygor wants to merge 1 commit into
git-lfs:masterfrom
billygor:major-pre-push-optimization
Closed

billygor wants to merge 1 commit into
git-lfs:masterfrom
billygor:major-pre-push-optimization

Conversation

@billygor

Copy link
Copy Markdown
Contributor

this change improves drastically pre-push behaviour, by not sending
lfs objects which are already on a remote. Works perfectly with
pushing new branches and tags.

currently pre-push command analyse "local sha1" vs "remote sha1" of the
ref being pushed and if "remote sha1" is available locally tries to send
only lfs objects introduced with new commits.

why this is broken:

  • remote branch might have moved forward (local repo is not up to date).
    In this case you have no chance to isolate new lfs objects ("remote sha1"
    does not exist locally) and git-lfs sends everything from the local
    branch history.
  • remote branch does not exist (or new tag is pushed). Same consequences.

But what is important - local repository always have remote references,
from which user created his local branch and started making some local
changes. So, all we have to do is to identify new lfs objects which do
not exist on remote references. And all this can be easily achieved with
the same all mighty git rev-list command.

This change makes git-lfs usable with gerrit, where changes are uploaded
by using magic gerrit branches which does not really exist. i.e.
git push origin master:refs/for/master

in this case "refs/for/master" does not exist and git feeds all 0-s as
"remote sha1".

this change improves drastically pre-push behaviour, by not sending
lfs objects which are already on a remote. Works perfectly with
pushing new branches and tags.

currently pre-push command analyse "local sha1" vs "remote sha1" of the
ref being pushed and if "remote sha1" is available locally tries to send
only lfs objects introduced with new commits.

why this is broken:
- remote branch might have moved forward (local repo is not up to date).
  In this case you have no chance to isolate new lfs objects ("remote sha1"
  does not exist locally) and git-lfs sends everything from the local
  branch history.
- remote branch does not exist (or new tag is pushed). Same consequences.

But what is important - local repository always have remote references,
from which user created his local branch and started making some local
changes. So, all we have to do is to identify new lfs objects which do
not exist on remote references. And all this can be easily achieved with
the same all mighty git rev-list command.

This change makes git-lfs usable with gerrit, where changes are uploaded
by using magic gerrit branches which does not really exist. i.e.
git push origin master:refs/for/master

in this case "refs/for/master" does not exist and git feeds all 0-s as
"remote sha1".
Comment thread lfs/scanner.go

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'm using just "--remotes" here. Another option would be to use --remotes=<remote_name_from_pre-push_arg_1>. But since we only have one git-lfs server and single lfs.url configuration option, it is safe to assume that the same git lfs server is used for all remotes. So, we can do a better jobs isolating only lfs objects introduced locally.

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.

But since we only have one git-lfs server and single lfs.url configuration option, it is safe to assume that the same git lfs server is used for all remotes. So, we can do a better jobs isolating only lfs objects introduced locally.

Not necessarily. You can also configure an lfs server at remote.{name}.lfsurl. Ideally, each git host has its own lfs host too that's automatically configured. It should be easy to push and pull between different git hosts.

There is one big issue with this right now. Git doesn't tell us what remote we should be using in the smudge or post-checkout hooks. So pulling from a non-origin remote doesn't quite work.

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.

ok, here is the change which makes use of current remote only: #578
I'll be happy with either of those 2.

@sinbad

sinbad commented Aug 11, 2015

Copy link
Copy Markdown
Contributor

There is one big issue with this right now. Git doesn't tell us what remote we should be using in the smudge or post-checkout hooks. So pulling from a non-origin remote doesn't quite work.

I was thinking that perhaps the fetch & pull lfs commands should have a remote as their first arguments, but didn't add them yet. For smudge / post-checkout I suggest we use the default remote as chosen by git pull, which is:

  1. Check if the current branch is tracking a remote branch (git branch -vv) and if so use the remote it's tracking (this applies to pull, not push so for example in forks you'd usually track the read-only upstream on a secondary remote to pull from, and push to origin as your fork)
  2. Use origin if it exists
  3. Fail

I agree the pre-push should be specific about what remote it's comparing with.

@technoweenie

Copy link
Copy Markdown
Contributor

@sinbad: I like your suggestion.

I also prefer #578 to this PR.

@sinbad

sinbad commented Aug 14, 2015

Copy link
Copy Markdown
Contributor

I've submitted PR #583 to implement the remote arguments & refinement to the default remote.

@billygor

Copy link
Copy Markdown
Contributor Author

superseded by #578

@billygor billygor closed this Aug 17, 2015
@billygor
billygor deleted the major-pre-push-optimization branch August 18, 2015 09:12
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