From e23ca3848e46e498e182f673d33b1855ba32edfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Sedl=C3=A1k?= Date: Tue, 5 Feb 2013 22:05:47 +0100 Subject: [PATCH] Download specific Patch Set for Review Adds ability to request download and checkout of specific review-patchset using syntax: git review -d , It will create and checkout the /-patch branch. Change-Id: Idaf57acb1464e1e71a436d741ae889494a91d446 --- AUTHORS | 1 + README.md | 4 ++++ git-review | 37 ++++++++++++++++++++++++++++++------- git-review.1 | 20 ++++++++++++++++++++ 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/AUTHORS b/AUTHORS index d148841..d651860 100644 --- a/AUTHORS +++ b/AUTHORS @@ -5,3 +5,4 @@ Kiall Mac Innes Roan Kattouw Antoine Musso Yuriy Taraday +Pavel Sedlák diff --git a/README.md b/README.md index 074c8ff..1cd5661 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,10 @@ If you want to download change 781 from gerrit to review it:: git review -d 781 +If you want to download patchset 4 for change 781 from gerrit to review it:: + + git review -d 781,4 + If you just want to do the commit message and remote setup steps:: git review -s diff --git a/git-review b/git-review index d65bc51..d43f23b 100755 --- a/git-review +++ b/git-review @@ -639,12 +639,12 @@ class CannotQueryPatchSet(CommandFailed): EXIT_CODE = 34 -class PatchSetInformationNotFound(ChangeSetException): +class ReviewInformationNotFound(ChangeSetException): "Could not fetch review information for change %s" EXIT_CODE = 35 -class PatchSetNotFound(ChangeSetException): +class ReviewNotFound(ChangeSetException): "Gerrit review %s not found" EXIT_CODE = 36 @@ -656,6 +656,11 @@ Does specified change number belong to this project?""" EXIT_CODE = 37 +class PatchSetNotFound(ChangeSetException): + "Review patchset %s not found" + EXIT_CODE = 38 + + class CheckoutNewBranchFailed(CommandFailed): "Cannot checkout to new branch" EXIT_CODE = 64 @@ -685,12 +690,19 @@ def fetch_review(review, masterbranch, remote): else: userhost = "%s@%s" % (username, hostname) + review_arg = review + patchset_number = None + patchset_opt = '--current-patch-set' + if ',' in review: + review, patchset_number = review.split(',') + patchset_opt = '--patch-sets' + review_info = None output = run_command_exc( CannotQueryPatchSet, "ssh", "-x", port, userhost, "gerrit", "query", - "--format=JSON --current-patch-set change:%s" % review) + "--format=JSON %s change:%s" % (patchset_opt, review)) review_jsons = output.split("\n") found_review = False @@ -705,12 +717,19 @@ def fetch_review(review, masterbranch, remote): if not found_review: if VERBOSE: print(output) - raise PatchSetInformationNotFound(review) + raise ReviewInformationNotFound(review) try: - refspec = review_info['currentPatchSet']['ref'] + if patchset_number is None: + refspec = review_info['currentPatchSet']['ref'] + else: + refspec = [ps for ps + in review_info['patchSets'] + if ps['number'] == patchset_number][0]['ref'] + except IndexError: + raise PatchSetNotFound(review_arg) except KeyError: - raise PatchSetNotFound(review) + raise ReviewNotFound(review) try: topic = review_info['topic'] @@ -722,7 +741,11 @@ def fetch_review(review, masterbranch, remote): author = re.sub('\W+', '_', review_info['owner']['name']).lower() except KeyError: author = 'unknown' - branch_name = "review/%s/%s" % (author, topic) + + if patchset_number is None: + branch_name = "review/%s/%s" % (author, topic) + else: + branch_name = "review/%s/%s-patch%s" % (author, topic, patchset_number) print("Downloading %s from gerrit" % refspec) run_command_exc(PatchSetGitFetchFailed, diff --git a/git-review.1 b/git-review.1 index cb531d9..4103483 100644 --- a/git-review.1 +++ b/git-review.1 @@ -46,6 +46,12 @@ designed to make it easier to apprehend Gerrit, especially for users that have recently switched to Git from another version control system. .Pp +.Ar change +can be changeNumber as obtained using +.Fl --list +option, or it can be changeNumber,patchsetNumber for fetching exact patchset from the change. +In that case local branch will get -patch[patchsetNumber] suffix. +.Pp The following options are available: .Bl -tag -width indent .It Fl d Ar change , Fl -download= Ns Ar change @@ -197,6 +203,8 @@ Cannot fetch information about the changeset to be downloaded. Changeset not found. .It 37 Particular patchset cannot be fetched from the remote git repository. +.It 38 +Specified patchset number not found in the changeset. .It 64 Cannot checkout downloaded patchset into the new branch. .It 65 @@ -239,6 +247,18 @@ $ git branch Gerrit looks up both name of the author and the topic name from Gerrit to name a local branch. This facilitates easier identification of changes. .Pp +To fetch a remote patchset number 5 from change number 3004: +.Pp +.Bd -literal -offset indent +$ git-review -d 3004,5 +Downloading refs/changes/04/3004/5 from gerrit into +review/someone/topic_name-patch5 +Switched to branch 'review/someone/topic_name-patch5 +$ git branch + master +* review/author/topic_name-patch5 +.Ed +.Pp To send a change for review and delete local branch afterwards: .Bd -literal -offset indent $ git-review -f