Skip to content
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

git fetch remote refs. #80

Merged
merged 3 commits into from
Sep 18, 2015
Merged

git fetch remote refs. #80

merged 3 commits into from
Sep 18, 2015

Conversation

cfelder
Copy link
Contributor

@cfelder cfelder commented Aug 10, 2015

Fetch remote references in order to check them out.
switch_revision_git already supports checking out refs if they are known in
your cloned repository but when using code review systems e.g. gerrit the
references will not be cloned from the origin. Therefore fetch the specified
reference and create it locally in fetch_upstream_git. Afterwards
switch_revision_git can switch to that reference.

@cfelder cfelder force-pushed the fetch-ref branch 2 times, most recently from 51fecf6 to 0704914 Compare August 10, 2015 11:42
@aspiers
Copy link
Member

aspiers commented Aug 10, 2015

Thanks. I think I sort of understand why you want to do this, but not completely. Please can you give a concrete example of a repository and a corresponding revision which doesn't get fetched during a clone?

Also please note I cannot merge this until you fix the test suite.

@cfelder cfelder force-pushed the fetch-ref branch 2 times, most recently from 81c63a3 to b9365b2 Compare August 10, 2015 15:01
@cfelder
Copy link
Contributor Author

cfelder commented Aug 11, 2015

I fixed the test-issue. Below is an example of a Gerrit Code Review Patch referenced by refs/changes/61/261/3 which needs to be fetched first.

felder@mbadmin:tmp % git clone https://iffwww.iff.kfa-juelich.de/review/gr
Cloning into 'gr'...
remote: Counting objects: 7852, done
remote: Finding sources: 100% (7852/7852)
remote: Total 7852 (delta 4478), reused 7405 (delta 4478)
Receiving objects: 100% (7852/7852), 26.34 MiB | 8.66 MiB/s, done.
Resolving deltas: 100% (4478/4478), done.
Checking connectivity... done.
felder@mbadmin:tmp % cd gr
felder@mbadmin:gr (master) % git rev-parse --verify refs/changes/61/261/3
fatal: Needed a single revision
felder@mbadmin:gr (master) % git fetch https://iffwww.iff.kfa-juelich.de/review/gr refs/changes/61/261/3
remote: Counting objects: 9, done
remote: Finding sources: 100% (5/5)
remote: Total 5 (delta 4), reused 5 (delta 4)
Unpacking objects: 100% (5/5), done.
From https://iffwww.iff.kfa-juelich.de/review/gr
 * branch            refs/changes/61/261/3 -> FETCH_HEAD
felder@mbadmin:gr (master) % git update-ref refs/changes/61/261/3 FETCH_HEAD
felder@mbadmin:gr (master) % git rev-parse --verify refs/changes/61/261/3
12a37e46717f1c894c4ae209a7cce86033fdff13

if revision:
# check if the reference already exists.
try:
safe_run(['git', 'rev-parse', '--verify', '--quiet', revision],
Copy link
Member

Choose a reason for hiding this comment

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

Please use subprocess.call here. safe_run is only intended to be used when you don't expect the command to fail in normal circumstances.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can change it to subprocess.call resulting in some code duplication from safe_run but I just would like to let you know that you are using it in the same way in update_cache_hg. I tried not to duplicate code and not to break the existing style.

Therefore I would like to know if this is really what you want me to do?

Copy link
Member

Choose a reason for hiding this comment

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

Haha, good catch :-) Actually I didn't write that code. But well done for copying the existing style, even if I don't like it ;-) Yeah I think it would be better not to use safe_run when the command can fail in normal circumstances.

Also I now notice that switch_revision_git currently needs to check if a revision exists. If we're adding a check here, then maybe that's no longer necessary - what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The revision check in switch_revision_git is slightly different because it checks against the revs = [x + revision for x in ['origin/', '']]. Since fetch_upstream_git does not call switch_revision_git it would be impossible to change the revision to 'origin/' + revision.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I follow you. Why would we want to change the revision to 'origin/' + revision? My point was that the following sequence contains redundancy:

  1. git clone
  2. Check if we have the revision we want.
  3. If not fetch it.
  4. Check if we have the revision we want.
  5. Switch to it.

But I suppose it could be argued that step 4 is an extra safeguard against step 3. not doing what we expect. So I'm OK with keeping that, as long as the duplicate code for steps 2. and 4. is refactored into a separate function like I already suggested to do.

@aspiers
Copy link
Member

aspiers commented Aug 11, 2015

Thanks that's extremely helpful - I understand perfectly now :)

cwd=clone_dir, interactive=sys.stdout.isatty())
except SystemExit:
# fetch reference from url and create locally
safe_run(['git', 'fetch', url, revision], cwd=clone_dir,
Copy link
Member

Choose a reason for hiding this comment

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

If you change this to

['git', 'fetch', url, revision + ':' + revision]

then you can eliminate the update-ref command below.

@cfelder cfelder force-pushed the fetch-ref branch 2 times, most recently from aa5ac53 to 94d16ba Compare August 14, 2015 09:24
@aspiers
Copy link
Member

aspiers commented Aug 14, 2015

Thanks so much - really really close to merging now! Just one more request: please can you extract a git_ref_exists function to avoid the currently duplicated code which calls git rev-parse?

@cfelder
Copy link
Contributor Author

cfelder commented Sep 17, 2015

ping

@aspiers
Copy link
Member

aspiers commented Sep 17, 2015

Sorry, I didn't notice that you updated - annoyingly, github doesn't send notifications after a push.

This now looks fantastic except for one thing - the git_ref_exists refactoring is squashed into the run_cmd, and there isn't even any mention of it in the commit message. If you can split that out into a separate commit then I think this will be ready to merge. Thanks again!

Fetch remote references in order to check them out.
switch_revision_git already supports checking out refs if they are known in
your cloned repository but when using code review systems e.g. gerrit the
references (e.g. refs/changes/61/261/3) will not be cloned from the origin.
Therefore fetch the specified reference and create it locally in fetch_upstream_git.
Afterwards switch_revision_git can switch to that reference.
In order to run commands which could fail in normal circumstances
use run_cmd with raisesysexit=False. This function will not raise
a SystemExit exception and returns a tuple of return code and command
output which used to evaluate the status of the executed command.
safe_cmd calls run_cmd with raisesysexit=True which will raise a
SystemExit exception if the return code is non-zero (previous behaviour).
In order to check for existance of git references provide a new
method git_ref_exists which will return True if the reference exists
in the local repository False otherwise.
@cfelder
Copy link
Contributor Author

cfelder commented Sep 18, 2015

Done.

@aspiers
Copy link
Member

aspiers commented Sep 18, 2015

Many thanks for your patience and hard work on this!

aspiers added a commit that referenced this pull request Sep 18, 2015
@aspiers aspiers merged commit a94d076 into openSUSE:master Sep 18, 2015
@cfelder
Copy link
Contributor Author

cfelder commented Sep 21, 2015

Thanks for merging my contributions. Are you planning a release v0.6.0?

@aspiers
Copy link
Member

aspiers commented Sep 23, 2015

Yes that makes sense, although we need to fix #82 first.

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.

2 participants