Download specific Patch Set for Review

Adds ability to request download and checkout
of specific review-patchset using syntax:
 git review -d <reviewId>,<patchsetNumber>

It will create and checkout the <author>/<topic>-patch<number> branch.

Change-Id: Idaf57acb1464e1e71a436d741ae889494a91d446
This commit is contained in:
Pavel Sedlák 2013-02-05 22:05:47 +01:00 committed by Jeremy Stanley
parent eae8ead205
commit e23ca3848e
4 changed files with 55 additions and 7 deletions

View File

@ -5,3 +5,4 @@ Kiall Mac Innes <kiall@managedit.ie>
Roan Kattouw <roan.kattouw@gmail.com>
Antoine Musso <hashar@free.fr>
Yuriy Taraday <yorik.sar@gmail.com>
Pavel Sedlák <psedlak@redhat.com>

View File

@ -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

View File

@ -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,

View File

@ -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