How to get the parent of patchset in gerrit with gerrit command

1,646 views
Skip to first unread message

Tao Hong

unread,
Apr 16, 2012, 10:38:31 PM4/16/12
to Repo and Gerrit Discussion
Hi,

I have used “ssh … gerrit query” command in a script. But I can only
get the revision of current patch set, while I can not get the Sha1
number of this patch set’s parent. Do you have any way I can get the
“parent” of a patch set with Gerrit command? Thanks a lot for your
kindly help!

Best Regards,
Hong Tao

Zu, Bruce

unread,
Apr 16, 2012, 11:31:24 PM4/16/12
to Hong, Tao 2, Repo and Gerrit Discussion
Hi Tao
 
e.g.
 
 
 
 
Do you want the ca1532d6ca498a7499224b42a2ccf8653cc0de9d
If so . you can:
e.g.
 
$ssh  bruc...@review.sonyericsson.net -p 29418 gerrit query --patch-sets  --format=TEXT status:open project:tools/gerrit limit:1
change I7f9f9a7d27153bf26555f4acec25bb9c63955265
  project: tools/gerrit
  branch: master
  id: I7f9f9a7d27153bf26555f4acec25bb9c63955265
  number: 245969
  subject: Add new stream event 'patchset-replicated'
  owner:
    name: Yang, Zhenhui
  createdOn: 2012-04-06 11:33:01 CEST
  lastUpdated: 2012-04-17 05:05:48 CEST
  sortKey: 001c6f790003c0d1
  open: true
  status: NEW
  patchSets:
    number: 1
    revision: d9bc87d174667e1242e4eecd26554615a9a34f3b
    ref: refs/changes/69/245969/1
    uploader:
      name: Yang, Zhenhui
      email: zhenhu...@sonymobile.com
    createdOn: 2012-04-06 11:33:01 CEST
    number: 2
    revision: 11110a47616abd82c103d5970ebc7ded80f98d66
    ref: refs/changes/69/245969/2
    uploader:
      name: Yang, Zhenhui
      email: zhenhu...@sonymobile.com
    createdOn: 2012-04-12 11:40:32 CEST
    number: 3
    revision: a227d81c7b94c1cee229ffb043b6ac994df4b568
    ref: refs/changes/69/245969/3
    uploader:
      name: Yang, Zhenhui
      email: zhenhu...@sonymobile.com
    createdOn: 2012-04-13 09:16:21 CEST
    number: 4
    revision: 3ffaf2207a8c4226c4ff18980a01c772aa8fd4ad
    ref: refs/changes/69/245969/4
    uploader:
      name: Yang, Zhenhui
      email: zhenhu...@sonymobile.com
    createdOn: 2012-04-16 05:46:56 CEST
 
type: stats
rowCount: 1
runTimeMilliseconds: 2
 
$ssh  bruc...@review.sonyericsson.net -p 29418 gerrit gsql -c  \"select ancestor_revision , change_id , patch_set_id , position from patch_set_ancestors where change_id=245969  and patch_set_id=4 \"
ancestor_revision                        | change_id | patch_set_id | position
-----------------------------------------+-----------+--------------+---------
ca1532d6ca498a7499224b42a2ccf8653cc0de9d | 245969    | 4            | 1
(1 row; 1 ms)
28850272@cnbjlx6200:~$
 
 
/B

Hong, Tao 2

unread,
Apr 16, 2012, 11:37:17 PM4/16/12
to Zu, Bruce, Repo and Gerrit Discussion
Hi, Bruce
 
Thanks for your reply. But, as you know, only Admin has the access right to use “Gerrit gsql”, the user who write the script with Gerrit command is not administrator. So he can only use “Gerrit query”. Can we get the parent of a patch set only with “gerrit query” command? If not currently, is it possible to add this small feature in “Gerrit query”? Thanks a lot for your kindly help againJ
 
Best Regards,
Hong Tao
 
_____________________________________________
From: Zu, Bruce
Sent: Tuesday, April 17, 2012 11:31 AM
To: Hong, Tao 2; Repo and Gerrit Discussion
Subject: RE: How to get the parent of patchset in gerrit with gerrit command
 
 
Hi Tao
 
e.g.
 
 
<< OLE Object: Picture (Device Independent Bitmap) >>

Zu, Bruce

unread,
Apr 17, 2012, 2:17:29 AM4/17/12
to Hong, Tao 2, Repo and Gerrit Discussion
 
Coding …Done.  In testing . J
_____________________________________________
From: Hong, Tao 2
Sent: Tuesday, April 17, 2012 11:37 AM
To: Zu, Bruce; Repo and Gerrit Discussion

Joe Hansche

unread,
May 8, 2012, 7:16:50 PM5/8/12
to repo-d...@googlegroups.com, Zu, Bruce
On Monday, April 16, 2012 11:37:17 PM UTC-4, Tao Hong wrote:
Hi, Bruce
 
JThanks for your reply. But, as you know, only Admin has the access right to use “Gerrit gsql”, the user who write the script with Gerrit command is not administrator. So he can only use “Gerrit query”. Can we get the parent of a patch set only with “gerrit query” command? If not currently, is it possible to add this small feature in “Gerrit query”? Thanks a lot for your kindly help again
 

This would be easy enough to script if you are already in a clone of that gerrit repository and you don't mind fetching the patchset revision:

 $ git fetch ssh@gerrit:29418/project/repo refs/changes/12345/1
 $ git log --format="%H" -n1 FETCH_HEAD^

- The fetch command is like the one that shows up in the download-patch section of the gerrit review (but without the acting command, like cherry-pick, checkout, etc)
- Format "%H" means print only the sha1 hash.
- FETCH_HEAD is the revision of the patchset (change number 12345, patchset number 1)
- FETCH_HEAD^ means the "parent" of that same.

The "refs/changes/12345/1" part can be obtained *via* the gerrit "query" command, as Bruce mentions above, e.g.:


  patchSets:
    number: 1
    revision: d9bc87d174667e1242e4eecd26554615a9a34f3b
    ref: refs/changes/69/245969/1
 
-Joe

Best Regards,
Hong Tao
Reply all
Reply to author
Forward
0 new messages