-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compare revisions for remote git branches/tags #4386
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me but a test would be needed to merge this.
Otherwise, it will likely go away on the next (needed) refactor...
pip/vcs/git.py
Outdated
@@ -171,6 +179,12 @@ def get_revision(self, location): | |||
['rev-parse', 'HEAD'], show_stdout=False, cwd=location) | |||
return current_rev.strip() | |||
|
|||
def get_remote_revision(self, url, ref): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it is not part of VersionControl
"API", I'd rather it be called _get_remote_revision
Hi @linar-jether! Could you add a test for this? :) |
@pradyunsg Sure sorry for the delay, added tests now... @xavfernandez anything else in order to merge this? |
I would caution against this change because it adds yet another place where the ref / Currently, similar conversion logic occurs in if rev:
rev_options = self.check_rev_options(rev, dest, rev_options)
# Only do a checkout if rev_options differs from HEAD
if not self.check_version(dest, rev_options):
self.run_command(
['fetch', '-q', url] + rev_options,
cwd=dest,
)
self.run_command(
['checkout', '-q', 'FETCH_HEAD'],
cwd=dest,
) With this PR, similar but slightly different conversion logic (using So the PR introduces the following asymmetry: A couple other comments: The news item has extension "bugfix", but this looks like a performance enhancement to me (and there is no issue / bug report). Also, the tests don't do anything to check that the |
It seems like a way to address this that would be more consistent with other parts of the code (namely the initial clone case) would be to change def update(self, dest, rev_options):
# First fetch changes from the default remote
if self.get_git_version() >= parse_version('1.9.0'):
# fetch tags in addition to everything else
self.run_command(['fetch', '-q', '--tags'], cwd=dest) # <-- here
else:
self.run_command(['fetch', '-q'], cwd=dest)
# Then reset to wanted revision (maybe even origin/master) # <-- here
if rev_options:
rev_options = self.check_rev_options(
rev_options[0], dest, rev_options,
)
self.run_command(['reset', '--hard', '-q'] + rev_options, cwd=dest)
#: update submodules
self.update_submodules(dest) This is what the clone case does here: # Only do a checkout if rev_options differs from HEAD
if not self.check_version(dest, rev_options):
self.run_command(
['fetch', '-q', url] + rev_options, # <-- here
cwd=dest,
)
self.run_command(
['checkout', '-q', 'FETCH_HEAD'],
cwd=dest,
) This approach seems equivalent and possibly more efficient in some cases because you avoid an extra |
@cjerdonek I labeled it a bugfix because currently pip re-installs packages even when not necessary, if the remote is a tag name and it hasn't changed there is no reason to reinstall, not only is this slower, it's also a broken functionality.
I'm not sure what this means, it seems the update() path only happens if check_version returned false...
This only happens if |
My point in mentioning For example, if you do this, you get three results:
But your code only assumes one result. You would also have to consider things like whether there is a matching tag. So what I was cautioning against is having to duplicate this type of logic in a second code path in a slightly different way. It would be better if we can be moving in the direction of making the fresh-install and update cases more similar to each other rather than more different. |
Hello! I am an automated bot and I have noticed that this pull request is not currently able to be merged. If you are able to either merge the |
@linar-jether @cjerdonek @pypa/pip-committers What do we want to do about this PR? I haven't really looked at this closely enough to have any strong opinion. I do think though that this can be closed or at least needs to adopt a different strategy. |
While I think the intent here is good, honestly I think we should address issues like #2037 first for a couple reasons. First, the PR is suggesting a certain optimization. While it's certainly doable, I would consider the code needed somewhat complex relative to what will be gained. IIRC, it would require code analogous to what I wrote for PR #4690 (specifically the Second, I'm not sure the optimization will work in the same way depending on how #2037 is resolved, so I would rather we not bake in the optimization because it will make later issues harder and we might need to remove it (or at least rework it) later anyways. |
I'll go ahead and close this, due to lack of activity here. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Adds a simple check if the local revision is the same as the remote revision, even if the ref is a tag or branch name.
Until now branches or tags would always try to update the repository.