Fix compare_review's use of fetch_review

fetch_review was updated to take project config information so that
projects hosted over http below some root (eg
https://gerrit.org/gerrit/here) could be properly fetched against. But
in adding this we broke the compare_review functionality which is the
other user of fetch_review.

Fix this by passing project config info into compare_review so that it
can pass that along to fetch_review.

Additionally we need to compare like types when looking at patchset
numbers so coerce them to ints when comparing.

Change-Id: I98fbf31821dc3a9162700725dec07bc7685ea5ca
This commit is contained in:
Clark Boylan 2018-01-09 15:48:20 -08:00 committed by Sorin Sbarnea
parent 51ab58f3fb
commit 3c46c33ec0
1 changed files with 15 additions and 9 deletions

View File

@ -1209,7 +1209,7 @@ def fetch_review(review, masterbranch, remote, project):
refspec = review_info['currentPatchSet']['ref'] refspec = review_info['currentPatchSet']['ref']
else: else:
refspec = [ps for ps in review_info['patchSets'] refspec = [ps for ps in review_info['patchSets']
if str(ps['number']) == patchset_number][0]['ref'] if int(ps['number']) == int(patchset_number)][0]['ref']
except IndexError: except IndexError:
raise PatchSetNotFound(review_arg) raise PatchSetNotFound(review_arg)
except KeyError: except KeyError:
@ -1248,10 +1248,11 @@ def checkout_review(branch_name, remote, remote_branch):
"git", "checkout", "-b", "git", "checkout", "-b",
branch_name, "FETCH_HEAD") branch_name, "FETCH_HEAD")
# --set-upstream-to is supported starting in git 1.8 # --set-upstream-to is supported starting in git 1.8
run_command_exc(SetUpstreamBranchFailed, if remote is not None:
"git", "branch", "--set-upstream-to", run_command_exc(SetUpstreamBranchFailed,
'%s/%s' % (remote, remote_branch), "git", "branch", "--set-upstream-to",
branch_name) '%s/%s' % (remote, remote_branch),
branch_name)
except CheckoutNewBranchFailed as e: except CheckoutNewBranchFailed as e:
if re.search("already exists\.?", e.output): if re.search("already exists\.?", e.output):
@ -1308,7 +1309,7 @@ class InvalidPatchsetsToCompare(GitReviewException):
EXIT_CODE = 39 EXIT_CODE = 39
def compare_review(review_spec, branch, remote, rebase=False): def compare_review(review_spec, branch, remote, project, rebase=False):
new_ps = None # none means latest new_ps = None # none means latest
if '-' in review_spec: if '-' in review_spec:
@ -1321,7 +1322,7 @@ def compare_review(review_spec, branch, remote, rebase=False):
old_review = build_review_number(review, old_ps) old_review = build_review_number(review, old_ps)
new_review = build_review_number(review, new_ps) new_review = build_review_number(review, new_ps)
old_branch, _ = fetch_review(old_review, branch, remote) old_branch, _ = fetch_review(old_review, branch, remote, project)
checkout_review(old_branch, None, None) checkout_review(old_branch, None, None)
if rebase: if rebase:
@ -1331,7 +1332,11 @@ def compare_review(review_spec, branch, remote, rebase=False):
print('Skipping rebase because of conflicts') print('Skipping rebase because of conflicts')
run_command_exc(CommandFailed, 'git', 'rebase', '--abort') run_command_exc(CommandFailed, 'git', 'rebase', '--abort')
new_branch, remote_branch = fetch_review(new_review, branch, remote) new_branch, remote_branch = fetch_review(
new_review,
branch,
remote,
project)
checkout_review(new_branch, remote, remote_branch) checkout_review(new_branch, remote, remote_branch)
if rebase: if rebase:
@ -1628,7 +1633,8 @@ def _main():
if options.changeidentifier: if options.changeidentifier:
if options.compare: if options.compare:
compare_review(options.changeidentifier, compare_review(options.changeidentifier,
branch, remote, options.rebase) branch, remote, config['project'],
options.rebase)
return return
local_branch, remote_branch = fetch_review(options.changeidentifier, local_branch, remote_branch = fetch_review(options.changeidentifier,
branch, remote, branch, remote,