Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.

Gerrit Introduction: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(swap redirects)
m (Resized screenshots)
 
(43 intermediate revisions by 15 users not shown)
Line 1: Line 1:
[[Category:Developing_Qt]]
[[Category:Developing Qt::Process]]
[[Category:Tools::Gerrit]]


[toc align_right="yes" depth="2"]
'''Note, if you are a first time Gerrit user, please take a look at the [[Setting up Gerrit]] page.'''


= Introduction to Gerrit =
==Overview==


'''Note, if you are a first time Gerrit user, please take a look at the [[setting up Gerrit|Setting-up-Gerrit]] page.'''
NB., the screenshots were taken from a very old version of Gerrit, and consequently should be viewed as ideographic.


== Overview ==
Also, the current version of Gerrit comes with [https://codereview.qt-project.org/Documentation/intro-gerrit-walkthrough.html its own introduction].


=== Main features ===
===Main Features===


Gerrit is a web-based tool that is used for code review. Its main features are the side-by-side difference viewing and inline commenting which makes code reviews quick and simple task. It is used together with Git version control system. Gerrit allows authorized contributors to submit changes to Git repository, after reviews are done. Contributors can get their code reviewed with a little effort, and get their changes quickly through the system.
Gerrit is a web-based tool that is used for code review. Its main features are side-by-side difference viewing and inline commenting. These make code reviews a quick and simple task. It is used together with the Git version control system. Gerrit allows authorized contributors to merge changes to the Git repository, after reviews are done. Contributors can get their code reviewed with little effort, and get their changes quickly through the system.


=== Gerrit usage ===
===Basic Workflow===


There are two purposes Gerrit usage. First, the contributor can upload changes to Gerrit, and second, approvers and peer reviewers can complete a review process with the web browser. Changes are uploaded with git push command. Any Git client can be used to access Gerrit. The review process includes the following steps:
Gerrit usage has two stages: First, the contributor uploads changes to Gerrit with Git, and second, peers use the web browser to make reviews. The review process includes the following steps:


* Review changes
*Review Changes
* Publish comments
*Publish comments
* Approve or abandon changes
*Approve or abandon Changes
 
===Repository Structure===


Gerrit can manage multiple repositories (projects). Branches are fully supported by Gerrit, each repository can have any number of branches.
Gerrit can manage multiple repositories (projects). Branches are fully supported by Gerrit, each repository can have any number of branches.


[[Image:http://developer.qt.nokia.com/uploads/gerrit/1_2_Infra.png|http://developer.qt.nokia.com/uploads/gerrit/1_2_Infra.png]]
[[File:Gerrit_Intro_Structure.png]]
 
Gerrit stores changes, which are normal commits, as references in path refs/changes. When contributor pushes changes, a special reference in path refs/for/ is used. For example, when contributor uploads a commit to 'stable' branch the target ref will be refs/for/stable.


Git repositories that Gerrit operates on are accessed through Gerrit instead of git-daemon. Any other Git-related service can be used with Gerrit. However, it is recommended that all Git commands are run through Gerrit.
Gerrit stores Changes, which are normal commits, as references in the refs/changes/ namespace. When contributors push Changes, they prepend <tt>refs/for/</tt> to the target branch. For example, when contributor uploads a commit to the <tt>dev</tt> branch, the target ref will be <tt>refs/for/dev</tt>.


=== Terminology for Gerrit ===
===Terminology===


Common terms used in Gerrit:
Common terms used in Gerrit:


{|
{| class="wikitable"
!Term
!Term
!Description
!Description
|-
|-
|'''Change'''
|'''Change'''
|A single commit and unit of a review. Changes are reviewed and submitted to Git repository.
|The unit of review. Results in a single commit when merged to the Git repository.
Change numbers (identifiers) are unique and never change.
|-
|-
|'''Patch Set'''
|'''Patch Set'''
|A version of a change. After each time a change is modified, it will receive a new patch set.
|A revision of a Change. Each time a Change is modified, it will receive a new Patch Set.
Patch Set numbering starts from 1.
Technically, a Patch Set is a unique Git commit.
|-
|'''Approval Category'''
|Name for a scope that is checked during review process. Qt is using the categories <tt>Code Review</tt> and <tt>Sanity Review</tt>.
|-
|-
|'''Score'''
|'''Score'''
|A value for approval category. Indicates if change is approved and can be submitted to the Git repository.
|A value in an Approval Category. Indicates if a Change is approved and can be submitted to the Git repository.
|-
|'''Approval Category'''
|Name for a scope that is checked during review process. Qt is using categories Code Review and Sanity Review.
|-
|-
|'''Submit'''
|'''Submit'''
|An action that allows Gerrit to merge a change to Git repository.
|An action that allows Gerrit to merge a Change to the Git repository.
|-
|-
|'''Abandon'''
|'''Abandon'''
|Action that archives a change. An abandoned change can be restored later.
|Action that archives a Change. An abandoned Change can be restored later.
|-
|-
|'''Project'''
|'''Project'''
|Git repository.
|A Git repository.
|}
|}


== Contribution creation and uploading ==
==Creating and Uploading Contributions==


=== Git and Gerrit commands ===
===Preparation===


All Gerrit commands are using SSH protocol and the host port is 29418. A user can access Gerrit's Git repositories with SSH or HTTP protocols. The user must have registered in Gerrit and a public SSH key before any command line commands can be used.
Before any contribution can be created, a Git clone of the target repository must be obtained and properly configured.
Before proceeding user needs to have a SSH public key configured in Gerrit.
The necessary steps are explained in [[Setting up Gerrit]].


=== Creating a new contribution ===
===Creating a New Contribution===


All contributions will be uploaded with regular Git command, like before. Gerrit handles reviews in commit level. A single contribution can easily result in several reviewable changes in Gerrit. User, typically a contributor, prepares a contribution by following these steps:
All contributions are uploaded with a regular Git push. Gerrit handles reviews at the commit level. A single contribution can easily result in several reviewable Changes in Gerrit. The contributor prepares a contribution by following these steps:


# Cloning from the repository
#Creating or updating the local repository
# Setting up a commit message hook
#Optionally creating a topic branch
# Creating a topic branch
#Creating commits
# Doing changes
#Uploading the commit(s) to Gerrit
# Updating repository
#Soliciting feedback
# Pushing changes


See the step-by-step introductions below on how to complete a commit upload. Note that Gerrit SSH service is running in port 29418. There is no need to write this port number every time, just add the following lines to ~/.ssh/config file:
====Creating a topic branch====


<code>
Keep code organized in [http://git-scm.com/book/en/Git-Branching-Branching-Workflows topic branches.] This is what Git excels in. "next-big-thing" is used as an example topic branch below:
Host codereview.qt.io
User <username>
Port 29418
</code>


==== Cloning from repository ====
<pre>
 
$ git switch -c next-big-thing
The Qt Base Git repository can be cloned from Gerrit over SSH with the following commands:
 
<code>
$ git clone ssh://codereview.qt.io/qt/qtbase.git
Cloning into qtbase…
remote: Counting objects: 33523, done
remote: Finding sources: 100% (33523/33523)
Receiving objects: 100% (33523/33523), 69.45 MiB | 901 KiB/s, done.
remote: Total 33523 (delta 16501), reused 33523 (delta 16501)
Resolving deltas: 100% (16501/16501), done.
$
</code>
 
Note that the Qt Base repository only contains a limited part of Qt, including e.g. Qt Core, Qt GUI, Qt Network, but not Qt Webkit, Qt Script and others. If you want to clone everything, e.g. for building Qt Creator later, use
 
<code>
$ git clone ssh://codereview.qt.io/qt/qt5.git
$ cd qt5
$ ./init-repository
$ ./configure -developer-build # or your favourite setup
</code>
 
==== Setting up commit message hook ====
 
To add a Change-Id footer to your commit messages, download a message hook from Gerrit with the following command. The message hook should be downloaded for each submodule you will be editing. For qtbase, these commands work.
 
<code>
$ cd qtbase
$ scp codereview.qt.io:hooks/commit-msg .git/hooks
</code>
 
or (if you’re behind a firewall and want to use the https protocol):
 
<code>
$ cd qtbase
$ scp -P 443 codereview.qt.io:hooks/commit-msg .git/hooks
</code>
 
If you are cloning the qt5 supermodule and using the init-repository script, you will have the hooks installed automatically for you.
 
==== Creating a topic branch ====
 
Keep code organized in "topic branches.":http://git-scm.com/book/en/Git-Branching-Branching-Workflows This is what Git excels in. "next-big-thing" is used as an example topic branch below:
 
<code>
$ git checkout -b next-big-thing
Switched to a new branch 'next-big-thing'
Switched to a new branch 'next-big-thing'
$
$
</code>
</pre>
 
h4. Doing changes
 
Use your favorite editor to complete a coding task.
 
<code>
$ edit src/foo.cc
$
</code>


h4. Updating repository
====Creating Commits====


Call git add to all files that should be included in the commit that is created, and finally call git commit to create a new commit as follows:
See the [[Git Introduction]] to get started.


<code>
Here are a few notes specific to Qt/Gerrit:
$ git add src/foo.cc
$ git commit
</code>


At this point you will enter your commit message into the editor. The '''first line''' should be short and to the point, beginning with a verb like "Fix", "Optimize", "Add", etc. The '''second line''' must be blank. Following that should be a longer explanation of the change, yet still kept to the point.
*If you correctly set up the clone, the commit message editor will present you with a template for the message.
*The guidelines for creating good commit messages - and creating good commits in general, for that matter - are outlined in the [[Commit Policy]].
*On initial creation of a commit, if the commit-msg hook is set up properly, an additional line in the form of "Change-Id: …" should have been added.


A line in the form: "Task-number: QTBUG-01234" may be added to associate the commit with a bug report.
====Uploading Commits====


Save and quit the editor.
Changes are pushed to Gerrit with <tt>git push or git gpush(see below)</tt>. Note that a special target ref is used.
Gerrit reports how many Changes were created and provides links to these Changes.


<code>
<pre>
[next-big-thing c82710a] My Feature
$ git push gerrit HEAD:refs/for/dev
1 files changed, 1 insertions(+), 0 deletions(-)
Counting objects: 6, done.
  create mode 100644 src/foo.cc
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 407 bytes, done.
Total 4 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2)
remote: Processing changes: new: 1, refs: 1, done   
remote:
remote: New Changes:
remote:  https://codereview.qt-project.org/12345
remote:
To ssh://qtcontributor@codereview.qt-project.org:29418/qt/qtbase
  * [new branch] HEAD -> refs/for/dev
$
$
</code>
</pre>


After the first commit has been performed, if the commit-msg hook is set up properly, then an additional line in the form of "Change-Id: …" should have been added.
When pushing to Gerrit, a typical [http://git-scm.com/book/en/Git-Internals-The-Refspec refspec] uses HEAD as the source ref and a special Gerrit ref for the target branch. The target ref has the format <tt>refs/for/<branch name></tt>. Pushes to this target ref causes Gerrit to create new Changes for all commits pushed this way. To group your Changes, push to a [[Gerrit Introduction#Topics in Gerrit|topic]] by using the format <tt>refs/for/<branch name>/<topic name></tt>.
Note that it is possible to use any other ref as source ref instead of HEAD when necessary.
See [[Branch Guidelines]] to decide about the target branch.


To revise the latest commit message use "git commit —amend".
It is recommended that you use the git-gpush command from our [http://code.qt.io/cgit/qt/qtrepotools.git/ qtrepotools repository]  For more information on using Git Scripts see [[Git-gpush-scripts|our page on Git Scripts.]]


==== Pushing changes ====
<pre>
$ git gpush
[same output as above]
</pre>


Changes are pushed to Gerrit with Git push. Note that special target ref is used.
Once a Change has been created, it can be viewed in the web browser:
Gerrit reports how many changes were created and provides links to these changes.


<code>
[[File:QtGerritChangeLightmode.png|1000x1000px]]
$ git push ssh://codereview.qt.io/qt/qtbase HEAD:refs/for/stable
Counting objects: 6, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 407 bytes, done.
Total 4 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 0% (0/2)
To ssh://<username>@codereview.qt.io:29418/qt/qtbase
  * [new branch] HEAD -> refs/for/stable
$
</code>


When pushing to Gerrit, "a typical refspec":http://git-scm.com/book/en/Git-Internals-The-Refspec uses HEAD as source ref and special Gerrit ref for target branch. Target ref is in format <code>refs/for/<branch name></code>. Pushes to this target ref causes Gerrit to create new changes for all commits pushed in this way. To group your changes push to a [[Gerrit_Introduction#Topics_in_Gerrit|topic]] by using the format <code>refs/for/<branch name>/<topic name></code>.
====Soliciting Feedback====
Note, that it is possible to use any other ref as source ref instead of HEAD when necessary.
See [[Branch-Guidelines]] for branch information.


It is recommended that you use the git-gpush command from our "qtrepotools repositors":https://qt.gitorious.org/qt/qtrepotools (make sure to add the bin directory to your PATH for maximal convenience):
The contributor requests feedback by adding reviewers to the Change. This is typically done via the web browser. Access the Change with the web browser and use the pen icon next to the names of the "Reviewers" to add any other registered user(s) to the review.


<code>
Alternatively, reviewers can be added already when uploading a contribution. Use the git-gpush tool for that purpose:
$ git gpush
[same output as above]
</code>


==Requesting and receiving contribution feedback==
<pre>
$ git gpush +approver@example.com
[same output as above]
</pre>


===Requesting contribution feedback===
==Review Workflow==


Contributor requests feedback by adding reviewers to the change. Typically this is done through web browser. Approver or another contributor who is doing peer-review can review any change without being added as a reviewer when having review access right to the project.
It is easy to get an overview of pending contributions in the "Your" page, also known as the "Dashboard":


Access the change with web browser and use "Add Reviewer" button to add any other registered user to the review like in the picture below:
[[File:Gerrit_Intro_Dashboard.png|1200x1200px]]


[[Image:http://developer.qt.nokia.com/uploads/gerrit/3_1_Gerrit_Change.png|http://developer.qt.nokia.com/uploads/gerrit/3_1_Gerrit_Change.png]]
It is possible to find Changes by issuing [https://codereview.qt-project.org/Documentation/user-search.html search queries]. Links for the Change owner, project name and branch name in the search result listings can be used to quickly search for related Changes.


Alternatively, reviewers can be added already when uploading a contribution. When pushing a change, reviewers can be identified using receive-pack option. See example below and refer Gerrit user's guide for "more detailed instructions.":http://gerrit.googlecode.com/svn/documentation/2.1.6/user-upload.html#push_create Using cc option for receive-pack sends an e-mail notification to that user. Gerrit will avoid sending duplicate emails to the same user.
The navigation bar at the top of the Gerrit web view provides quick access to common search queries under the "Your" and "Changes" items.


<code>
===Reviewing Contributions===
$ git push —receive-pack=
  'git receive-pack —reviewer=approver@qt.io —cc qtcontributor@private.com'
  ssh://qtcontributor@codereview.qt.io/qt/qtbase HEAD:refs/for/stable
Counting objects: 7, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 404 bytes, done.
Total 4 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 0% (0/2)
To ssh://qtcontributor@codereview.qt.io/qt/qtbase
  * [new branch] HEAD-> refs/for/stable
$
</code>


It is easy to have an overview of contributions in My Changes page. Contributor can view feedback on his or her contributions by accessing the change page and reading comments file-by-file. It is possible to reply on comments and have discussion about the code review in-line. Each time in-line comments or a review scores are published, a general comment can be added.
The review process starts with choosing a Change to review. After choosing a Change, changed files can be viewed side-by-side and comments can be posted in-line to each file. Contributions are typically reviewed by Approvers, but anyone can make a review.


Contributor reads the feedback by following the steps:
The following steps are needed to complete a code review:


# Accessing My Changes page
#Opening the Change page (entered from the Dashboard or following a link in a notification mail)
# Locating comments in the change page
#Reviewing changed files
# Reading in-line comments
#Publishing comments and reviewing results
# Publishing a reply or upload new patch set


==== Accessing My Changes page ====
====Viewing the Change Overview====


It can be done by done by clicking "My" link on the top left corner and then selecting link "Changes".
Changes can have several Patch Sets. When Changes get updated after review, the Patch Set number increases.


[[Image:http://developer.qt.nokia.com/uploads/gerrit/3_2_1_accessing_my_changes_page.png|http://developer.qt.nokia.com/uploads/gerrit/3_2_1_accessing_my_changes_page.png]]
[[File:Gerrit Intro PatchSets.png]]


==== Locating comments in the change ====
====Reviewing Changed Files====


Comments are under each patch set. In the picture below the comments for Patch set 2 are examined
Changes are compared side-by-side or in the unified diff view.
The reviewer can also compare differences between specific Patch Sets (also called "inter-diffs").


[[Image:http://developer.qt.nokia.com/uploads/gerrit/3_2_2_locating_comment_in_the_change.png|http://developer.qt.nokia.com/uploads/gerrit/3_2_2_locating_comment_in_the_change.png]]
Comments are posted by double clicking on a line. Comments are saved as drafts until they are published.


==== Reading in-line comments ====
Note that comments are formatted as flowed text, discarding individual line breaks. A simple [https://wiki.hpdd.intel.com/display/PUB/2012/02/16/Comment+formatting+on+Gerrit Wiki-like syntax] is supported.


Replies can be posted by clicking the comment like in the picture beneath:
[[File:Gerrit_Intro_Commenting.png|1200x1200px]]


[[Image:http://developer.qt.nokia.com/uploads/gerrit/3_2_3_reading_in_line_comments.png|http://developer.qt.nokia.com/uploads/gerrit/3_2_3_reading_in_line_comments.png]]
[[File:Gerrit Intro CommentDrafts.png|1200x1200px]]


Note that the comments are '''not''' actually posted until you publish them.
Gerrit keeps track which files have been reviewed and which files have comments ready to be published. If an ongoing review is interrupted, the reviewer can return later and resume where they left off. Draft comments can be edited and deleted before they are published.


'''Note:''' do not reply to the notification mails you get from Gerrit. The mails you send this way will not be publicly visible and archived.
=====Downloading Changes=====


=== Reviewing contributions ===
It is also possible to download Changes for local review. The easiest way to do that is to copy the Download link from Gerrit to the command line:


The review process starts from choosing a change to review. After choosing a change, changed files can be viewed side-by-side and comments can be posted in-line to each file. Contributions are typically reviewed by approvers and possibly peer-reviewed by other contributors.
[[File:Gerrit_Intro_CheckingOut.png|1200x1200px]]


Following steps are needed to complete a code review:
[[File:DownloadPatch2.png|1200x1200px]]
<pre>
$ git fetch ssh://qtcontributor@codereview.qt-project.org:29418/qt/qtbase refs/changes/19/419/1 && git checkout FETCH_HEAD
From ssh://codereview.qt-project.org:29418/qt/qtbase
* branch refs/changes/19/419/1 -> FETCH_HEAD
Note: checking out 'FETCH_HEAD'.


# Accessing Gerrit with web browser
You are in 'detached HEAD' state. You can look around, make experimental
# Viewing change overview
changes and commit them, and you can discard any commits you make in this
# Reviewing changed files
state without impacting any branches by performing another checkout. 
# Publishing comments and reviewing results


Gerrit keeps track which files have been reviewed and which files have comments ready to be published. If an ongoing review is interrupted, reviewer can return later and continue from the point he was in before. Draft comments can be edited and deleted before they are published.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:


After review results are ready to be published, the reviewer continues to the publish comments screen with the Review button.
git checkout -b new_branch_name


The Code Review category has 5 levels. A change can only be submitted after it receives +2 score. A change cannot be be submitted if it receives a -2 score.
HEAD is now at 9a006a3... My Feature
$ git checkout -b changes/419
Switched to a new branch 'changes/419'
$
</pre>


====Accessing Gerrit via web browser====
This makes it possible to use the usual git commands to view changes, to build the code, and to run tests.


Reviewer, typically approver, logs in to see own changes and those reviews that needs to be completed from the Code review dashboard like in the picture below:
====Publishing Comments====


[[Image:http://developer.qt.nokia.com/uploads/gerrit/3_3_1_accessing_gerrit_with_web_browser.png|http://developer.qt.nokia.com/uploads/gerrit/3_3_1_accessing_gerrit_with_web_browser.png]]
When all files are reviewed, the reviewer continues to the Publish Comments screen with the Review button.


=====Viewing change overview=====
The review is completed by writing an optional cover message and giving a score. The cover message uses the same [https://wiki.hpdd.intel.com/display/PUB/2012/02/16/Comment+formatting+on+Gerrit Wiki-like syntax] as inline comments.


Changes have several patch sets. When changes get updated after review, the patch set number increases.
The Code Review category has 5 levels. A Change can only be submitted after it receives a +2 score, and cannot be be submitted if it receives a -2 score. Giving these scores is limited to Approvers; regular contributors can give only advisory scores (-1 to +1).


[[Image:http://developer.qt.nokia.com/uploads/gerrit/3_3_2_viewing_change_overview.png|http://developer.qt.nokia.com/uploads/gerrit/3_3_2_viewing_change_overview.png]]
A Sanity Review score should '''not''' be given unless the [[Early Warning System|Sanity Bot]] made a mistake and needs to be overridden.


====Reviewing changed files====
[[File:Gerrit_Intro_Publishing.png|1000x1000px]]


Changes are compared side-by-side. Reviewer can compare differences between specific patch sets by using Patch History.
[[File:Gerrit_Intro_Published.png|1200x1200px]]


Comments are posted by double clicking on a line. Comments are saved as drafts until they are published as in the pictures:
=====Publishing Review Results From The Command Line=====


[[Image:http://developer.qt.nokia.com/uploads/gerrit/3_3_3_reviewing_changed_files_1.png|http://developer.qt.nokia.com/uploads/gerrit/3_3_3_reviewing_changed_files_1.png]]
An alternative to browser-based review is to use the Gerrit ssh command line interface. Please do ''not'' do this, as scripting a step which is meant to be visual and interactive removes the additional safety net.


[[Image:http://developer.qt.nokia.com/uploads/gerrit/3_3_3_reviewing_changed_files_2.png|http://developer.qt.nokia.com/uploads/gerrit/3_3_3_reviewing_changed_files_2.png]]
===Processing Review Feedback===


====Publishing comments====
The contributor can view feedback on their contributions by accessing the Change page and reading comments file-by-file. It is possible to reply to comments and have a discussion about the code review in-line.


Comments are published and a score is assigned to complete the review. By default, +2 for Code Review and +1 for Sanity Review categories is needed for a change to get merged. In the example +2 is selected and comments are awaiting publishing. A Sanity Review score should '''not''' be given unless the [[Early_Warning_System|Sanity Bot]] made an error and needs to be overridden.
The contributor processes the feedback by following these steps:


[[Image:http://developer.qt.nokia.com/uploads/gerrit/3_3_4_publishing_comments_1.png|http://developer.qt.nokia.com/uploads/gerrit/3_3_4_publishing_comments_1.png]]
#Opening the Change page (entered from the Dashboard or following a link in a notification mail)
#Locating comments in the Change page
#Reading and writing in-line comments
#Publishing a reply and/or uploading a new Patch Set


[[Image:http://developer.qt.nokia.com/uploads/gerrit/3_3_4_publishing_comments_2.png|http://developer.qt.nokia.com/uploads/gerrit/3_3_4_publishing_comments_2.png]]
====Locating Comments in The Change====


====Downloading change====
Comments are located in their own tab next to the files tab.


Easiest way to access change is to copy Download link from Gerrit to console, as it is done in the pictures below:
[[File:Gerrit_Intro_Comments.png|1200x1200px]]


[[Image:http://developer.qt.nokia.com/uploads/gerrit/3_3_1_1_command_line_review_downloading_change.png|http://developer.qt.nokia.com/uploads/gerrit/3_3_1_1_command_line_review_downloading_change.png]]
====Reading in-line Comments====


====Reviewing change or run tests====
Replies can be posted by clicking the 'Reply' button as shown in the image below:


Use git diff to compare changes. Build the code and run tests.
[[File:Gerrit_Intro_Replying.png|1200x1200px]]


====Publishing review result from command line====
Note that the comments are '''not''' actually posted until you publish them.


An alternative to browser-based review is to use the Gerrit ssh command line interface. Please do ''not'' do this, as scripting a step which is meant to be visual and interactive removes the additional safety net.
'''Note:''' do not reply to the notification mails you get from Gerrit. The mails you send this way will not be publicly visible and archived.


===Updating a contribution with new code===
===Updating a Contribution With New Code===


Usually during review process a change must be updated with a new patch set. Contributor needs to update the change if it received some comments that require action or it did not merge with the branch tip. Each time when a change is updated, it gains a new patch set. Patch set numbering starts from 1. Change numbers will never change and they are unique.
Most Changes require multiple iterations of the review process. The contributor needs to update the Change if it received some comments that require action, or it did not merge with the branch tip. Each time a Change is updated, it gains a new Patch Set.


To access the change, the original topic branch can be used or the change can be downloaded from Gerrit. Gerrit provides a quick way to copy the download link to clipboard and paste to console.
Updating a Change is done by following these steps:


Updating a change is done by following steps:
#Accessing the Changes
#Modifying the Change(s)
#Pushing updated Changes


# Accessing change code
# Modifying commit and adding Change-Id
# Pushing updated change


After change is modified in a working tree, changes are committed with option —amend. The commit is uploaded back to Gerrit with target ref refs/for/<branch name> with updated Change-Id in commit message.
====Note for github/bitbucket/... users====


See step-by-step instructions provided below how to complete a change update:
''Note'', that in contrast to ''github'', ''bitbucket'', ''gitlab'' etc., in Gerrit the change under review is a single commit.
(In github etc. the review is about whether to merge the feature branch into master, in Gerrit the review is about whether the commit should be accepted into master.)
So in order to change the content of a review, there must be a single new commit that contains everything you would like to review.
This is not "rewriting public history" because the commits under review are not (yet) part of the "public history" -- only after they are accepted, they become part of the projects history.
The following sections explain how to create a new commit that is suitable to replace the old commit for the review.


====Accessing change code====
====Accessing The Changes====


If the original commit is available, it is possible to continue editing that. Otherwise, just download the change by using the download link provided by Gerrit:
If the original commit(s) are still available, it is possible to amend them right away. Otherwise, download the Change(s) the same way as for local review.


[[Image:http://developer.qt.nokia.com/uploads/gerrit/3_4_1_accessing_change_code.png|http://developer.qt.nokia.com/uploads/gerrit/3_4_1_accessing_change_code.png]]
If Gerrit reported a merge conflict, now would be the time to rebase the Changes:


<code>
<pre>
$ git fetch ssh://qtcontributor@codereview.qt.io:29418/qt/qtbase
$ git rebase --onto origin/dev
  refs/changes/19/419/1 &amp;&amp; git checkout FETCH_HEAD
</pre>
From ssh://codereview.qt.io:29418/qt/qtbase
  * branch refs/changes/19/419/1-> FETCH_HEAD
Note: checking out 'FETCH_HEAD'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout. 


If you want to create a new branch to retain commits you create, you may
If you are not using a separate branch, you can just use <tt>git pull --rebase</tt>.
do so (now or later) by using -b with the checkout command again. Example:


git checkout -b new_branch_name
''Note:'' Please do '''not''' rebase unnecessarily, as this makes inter-diffs much less useful.


HEAD is now at 9a006a3… My Feature
====Modifying Commits====
$ git checkout -b changes/419
Switched to a new branch 'changes/419'
$
</code>


====Modifying commit====
Modifications in the working tree are committed with the --amend option. If the contribution consists of multiple commits, you will need to use <tt>git rebase --interactive</tt> to revise earlier commits.


Always make sure that the commit is based on the latest code from the Qt repository. To avoid merge errors, fetch and rebase the change before uploading a new version of the change.
When you amend commit messages, make ''sure'' to preserve the Change-Id footer, as this is how Gerrit identifies new Patch Sets for existing Changes.


Use option —amend to change the existing commit.
<pre>
$ vim src/foo.cc
$ git add src/foo.cc
$ git commit --amend
[changes/419 2ea7773] My Feature
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 src/foo.cc
$
</pre>


<code>
Pay even more attention to copying the Change-Id when you redo commits from scratch.
$ git pull —rebase
$ git commit —amend
</code>


====Pushing updated change====
====Pushing Updated Changes====


Git push is done change ID as target ref. using to target ref <code>refs/for</code>. The correct target change is identified from the change-id footer in the commit message. After push, a new patch set will be created for the target change example can be seen below:
The commit(s) are uploaded back to Gerrit with the same target ref as before. After the push, new Patch Sets will have been created for the target Change(s):


<code>
<pre>
$ vim src/foo.cc
$ git push gerrit HEAD:refs/for/dev
$ git add src/foo.cc
Counting objects: 6, done.
$ git commit —amend
Delta compression using up to 2 threads.
[changes/419 2ea7773] My Feature
Compressing objects: 100% (3/3), done.
  1 files changed, 1 insertions(+), 0 deletions(-)
Writing objects: 100% (4/4), 419 bytes, done.
  create mode 100644 src/foo.cc
Total 4 (delta 2), reused 0 (delta 0)
$ git push origin HEAD:refs/for/master
remote: Resolving deltas: 100% (2/2)
Counting objects: 6, done.
remote: Processing changes: updated: 1, refs: 1, done
Delta compression using up to 2 threads.
To ssh://qtcontributor@codereview.qt-project.org:29418/qt/qtbase.git
Compressing objects: 100% (3/3), done.
* [new branch] HEAD -> refs/for/dev
Writing objects: 100% (4/4), 419 bytes, done.
$
Total 4 (delta 2), reused 0 (delta 0)
</pre>
remote: Resolving deltas: 0% (0/2)
To ssh://qtcontributor@codereview.qt.io:29418/qt/qtbase.git
  * [new branch] HEAD -> refs/for/master
$
</code>


[[Image:http://developer.qt.nokia.com/uploads/gerrit/3_4_3_pushing_updated_change.png|http://developer.qt.nokia.com/uploads/gerrit/3_4_3_pushing_updated_change.png]]
If anything goes wrong at this stage, please see the [[Gerrit Caveats and Hints| troubleshooting chart]]. Otherwise, when you reload the gerrit page in your browser, you should see the change, like this:


== Approving and abandoning ==
[[File:Gerrit_Intro_Updating.png|1200x1200px]]


=== Approving and submitting a contribution ===
==Integrating Changes==


Depending on the project, an approved contribution will be submitted to the CI System (Qt 5) or a Git repository (Qt Creator).
To submit a Change to the CI system press the "Stage". button on the top right
Changes are approved by reviewing and assigning them score that is high enough for submission. By default, changes required +2 for Code Review and +1 for Sanity Review categories to be approved. There are two ways to submit a change. If the project is using continuous integration system, changes will be merged to staging. Otherwise, they will be submitted directly to their destination branches.


* To submit a change to CI system press "Merge Patch Set 1 to Staging".
It is usually best when the contributor submits their own Changes.
* To submit a change to Git repository press "Submit Patch Set 1"


In order to submit a change the user must have the required access rights. Only approvers and maintainers can submit changes. For contributors, it is enough to update the change until it passes the code review and CI building and testing.
Even if there are multiple reviewers, only one +2 approval is required. However, if other reviewers have shown a specific interest in a contribution, such as by repeated comments, it is polite to give them some time to add a +1 or +2 before submitting. See the [[Review_Policy]] for more details.


[[Image:http://developer.qt.nokia.com/uploads/gerrit/4_1_approving_and_submitting_a_contribution.png|http://developer.qt.nokia.com/uploads/gerrit/4_1_approving_and_submitting_a_contribution.png]]
[[File:Gerrit_Intro_Submitting.png|1200x1200px]]


If there are multiple relevant reviewers, you only need a +2 approval from one of them before staging. However if other reviewers have shown a specific interest in the patch, such as by repeated comments, then it is polite to give them some time to add a +1 or +2 before staging.
===Continuous Integration===


=== Abandoning a contribution ===
Gerrit has been slightly customized for the Qt project. The continuous integration system that is running regular builds and tests has been incorporated to the workflow. Instead of directly submitting Changes, Changes can be merged to a staging branch. There is a staging branch for each normal branch. Staging branches are maintained by Gerrit and are not visible to the contributors.


Those changes that should not be submitted can be abandoned. An abandoned change will disappear from open changes lists and is considered closed. Abandoned changes can be restored later if they become valid again or if they were abandoned by accident.
[[File:Gerrit_Intro_Workflow.png]]


Abandoning changes is a normal operation that is used to maintain Gerrit and hide changes that will not make their way to Git repository, for any reason.
As part of the customization, Changes gained new states. Changes in the New state are waiting for a review. After review, Changes are merged to a staging branch and marked as Staged. The continuous integration system will pick staged Changes at regular intervals and move them to the Integrating state. From the Integrating state Changes are either submitted or moved back to the New state. If builds succeed and tests pass, the Changes are submitted or merged into their destination branch. Otherwise they are moved back to the New state for further analysis. The contributor of the affected Change(s) is expected to analyze the failure and upload fixes as necessary.


To abandon a change, owner, approver or maintainer can click "Abandon Change" button.
==Abandoning and Deferring Contributions==


[[Image:http://developer.qt.nokia.com/uploads/gerrit/4_2_abandoning_a_contribution_1.png|http://developer.qt.nokia.com/uploads/gerrit/4_2_abandoning_a_contribution_1.png]]
Changes which are inherently flawed or became inapplicable should be abandoned.
An abandoned Change will disappear from open Changes lists and is considered closed.
Abandoned Changes can be restored later if they become valid again or if they were abandoned by accident.


[[Image:http://developer.qt.nokia.com/uploads/gerrit/4_2_abandoning_a_contribution_2.png|http://developer.qt.nokia.com/uploads/gerrit/4_2_abandoning_a_contribution_2.png]]
Changes which have potential but will not be worked on in the near future should be deferred.
Deferred Changes are basically abandoned, but are more easily accessible via the "My Deferred Changes" menu item.


=== Finding new contributions by others ===
Abandoning is a normal operation that is used to maintain Gerrit and hide Changes that will not make their way to the Git repository, for any reason.


User can find changes by searching or by browsing projects and branches. Refer to Gerrit user's guide for detailed information how to use search queries. Links for change owner, project name and branch name in change tables can be used to access quick searches of the related changes.
To abandon a Change, its owner or an Administrator can click the "Abandon" button:


Navigation bar at the top of the Gerrit web view can be used to quickly access
[[File:Gerrit_Intro_Abandon.png|1200x1200px]]


* User's own changes
[[File:Gerrit_Intro_Abandoned.png|1200x1200px]]
* Changes the user is expected to review
* All open, merged and abandoned changes


== Continuous integration and staging ==
==Feature Branches==


=== Workflow ===
The Qt Project's handling of branches is documented by the [[Branch Guidelines]].


Gerrit has been slightly customized for the Qt project. The continuous integration system that is running regular builds and tests has been incorporated to the workflow. Instead of directly submitting changes, changes can be merged to a staging branch. There is a staging branch for each normal branch. Staging branches are maintained by Gerrit and are not visible to the contributors.
===Topics vs. Branches===


[[Image:http://developer.qt.nokia.com/uploads/gerrit/5_1_workflow.png|http://developer.qt.nokia.com/uploads/gerrit/5_1_workflow.png]]
Gerrit topics can be used as "feature branches". A topic is created when a target ref like <tt>refs/for/<branch name>/<topic name></tt> is used. It is often good enough to push a set of commits for review to a topic. However, if the contributor intends to work with others on a long-living branch, the Gerrit Administrators should be contacted for a new branch in Gerrit. Also, the QA team has to be contacted so they can include the new branch in the CI system builds. This way the code can be reviewed already when working on it in the branch.


As part of customization, changes have new states. Changes in the New state are waiting for a review. After review, changes are merged to a staging branch and marked as staged. The continuous integration system will pick staged changes with regular intervals and move them to the Integrating stage. From the Integrating state changes are either submitted or moved back to the New state. If builds succeed and tests pass, submitted or merged their destination branch. Otherwise they are moved to the New state for further analysis. Contributor from whom the code originates from is expected to analyze why test and build phase failed and upload fixes.
===Merging Feature Branches===
 
Changes can still be submitted directly from new state, but only by users who have this specific access right in Gerrit.
 
=== Web UI and CLI ===
 
From a user's perspective, staging branch mechanism introduces only minor changes to the user interface. Instead of Submit button, "Merge to Staging" button is used.
 
[[Image:http://developer.qt.nokia.com/uploads/gerrit/5_2_web_ui_and_cli.png|http://developer.qt.nokia.com/uploads/gerrit/5_2_web_ui_and_cli.png]]
 
In command line, instead of "—submit" argument, argument "—stage" is used.
 
<code>
$ ssh qtcontributor@codereview.qt.io gerrit review —stage
2ea7773885dcc193abb35996f2bf7895051d68d3
</code>
 
== Merging feature branches ==
 
=== Topics in Gerrit ===
 
Gerrit topics, or change sets, can be used as "feature branches". A topic is created when a special target ref is used. The syntax for the change set refspec is <code>refs/for/<branch name>/<topic name></code>. It is often good enough to push a set of commits for review to a topic. However, if the contributor intends to work with others on a long-living branch the Gerrit Administrator should be contacted for a new branch that can be visible in Gerrit. Also the QA team has to be contacted so they can include the new branch in the CI system builds. This way the code can be reviewed already when working on it in the branch.
 
=== Merging feature branches ===


Merges between feature branches and the mainline are like all other commits and are pushed, reviewed and staged the usual way. However, only 'Merge Masters' can push merge commits. User may recruit the merge master from outside project team if it they do not have person knowledgeable on Git available. Note: Do not create a merge from commits which have not been integrated yet.
Merges between feature branches and the mainline are like all other commits and are pushed, reviewed and staged the usual way. However, only 'Merge Masters' can push merge commits. User may recruit the merge master from outside project team if it they do not have person knowledgeable on Git available. Note: Do not create a merge from commits which have not been integrated yet.


=== Merging branches Alien to Gerrit ===
===Merging Branches Alien to Gerrit===
 
This should not happen often. Nevertheless, only a merge commit should be pushed in this case. 'Git Administrator' can be asked to import the branch into Gerrit.
 
== Access rights ==


=== Access rights are defined in the group level ===
This should not happen often. Nevertheless, only a merge commit should be pushed in this case. 'Push Master' can be asked to import the branch into Gerrit.


In Gerrit, access rights are defined in the group level. Users are placed to different groups by the Gerrit administrator. Access rights are used to control the following operations.
==Moving Changes to Different Branches==
It sometimes happens that you push a change for the wrong branch. To correct this mistake, do '''''not'''''  create a new change, but instead ask Gerrit to move the existing change to a new branch. You'll find the action in the menu opened by the "three vertical dots" button near the top right of each change.


* Access to projects and changes in these projects
Take care to make subsequent pushes of the change to the new branch, as otherwise a duplicate will be created.
* Review a change
* Merge to staging
* Submit


Access to projects, and changes they contain, can be limited to certain groups. Users outside the selected groups cannot see projects or any data belonging to these projects.
If the action cannot be executed (typically, you are not the Change's owner, or a conflicting Change exists), ask a [https://codereview.qt-project.org/#/admin/groups/1,members Gerrit Administrator] to deal with the issue.


Review rights can be limited only to selected users, for example project members. User must have review access right to publish review comments.
==Closing Remarks==


Merge to staging and submit access rights are needed to move a change forward in the workflow.
See [[Gerrit Caveats and Hints]] to avoid common traps.


== Providing feedback about the set up ==
There is a process for [[Requesting New Repositories|requesting new repositories]].


Report Bugs specific to our setup to "the bugtracker":http://bugreports.qt.nokia.com/browse/QTQAINFRA/component/19470 and any Gerrit issues "directly upstream":http://code.google.com/p/gerrit/issues/list.
Report bugs in our Gerrit to [https://bugreports.qt.io/issues/?jql=project%20%3D%20QTQAINFRA%20AND%20component%20%3D%20Gerrit the bugtracker]. Ideally, provide a link to an [http://code.google.com/p/gerrit/issues/list upstream issue] (note that the issue may be already closed, as we are typically lagging by several versions).

Latest revision as of 14:19, 8 August 2023


Note, if you are a first time Gerrit user, please take a look at the Setting up Gerrit page.

Overview

NB., the screenshots were taken from a very old version of Gerrit, and consequently should be viewed as ideographic.

Also, the current version of Gerrit comes with its own introduction.

Main Features

Gerrit is a web-based tool that is used for code review. Its main features are side-by-side difference viewing and inline commenting. These make code reviews a quick and simple task. It is used together with the Git version control system. Gerrit allows authorized contributors to merge changes to the Git repository, after reviews are done. Contributors can get their code reviewed with little effort, and get their changes quickly through the system.

Basic Workflow

Gerrit usage has two stages: First, the contributor uploads changes to Gerrit with Git, and second, peers use the web browser to make reviews. The review process includes the following steps:

  • Review Changes
  • Publish comments
  • Approve or abandon Changes

Repository Structure

Gerrit can manage multiple repositories (projects). Branches are fully supported by Gerrit, each repository can have any number of branches.

Gerrit Intro Structure.png

Gerrit stores Changes, which are normal commits, as references in the refs/changes/ namespace. When contributors push Changes, they prepend refs/for/ to the target branch. For example, when contributor uploads a commit to the dev branch, the target ref will be refs/for/dev.

Terminology

Common terms used in Gerrit:

Term Description
Change The unit of review. Results in a single commit when merged to the Git repository.

Change numbers (identifiers) are unique and never change.

Patch Set A revision of a Change. Each time a Change is modified, it will receive a new Patch Set.

Patch Set numbering starts from 1. Technically, a Patch Set is a unique Git commit.

Approval Category Name for a scope that is checked during review process. Qt is using the categories Code Review and Sanity Review.
Score A value in an Approval Category. Indicates if a Change is approved and can be submitted to the Git repository.
Submit An action that allows Gerrit to merge a Change to the Git repository.
Abandon Action that archives a Change. An abandoned Change can be restored later.
Project A Git repository.

Creating and Uploading Contributions

Preparation

Before any contribution can be created, a Git clone of the target repository must be obtained and properly configured. The necessary steps are explained in Setting up Gerrit.

Creating a New Contribution

All contributions are uploaded with a regular Git push. Gerrit handles reviews at the commit level. A single contribution can easily result in several reviewable Changes in Gerrit. The contributor prepares a contribution by following these steps:

  1. Creating or updating the local repository
  2. Optionally creating a topic branch
  3. Creating commits
  4. Uploading the commit(s) to Gerrit
  5. Soliciting feedback

Creating a topic branch

Keep code organized in topic branches. This is what Git excels in. "next-big-thing" is used as an example topic branch below:

$ git switch -c next-big-thing
Switched to a new branch 'next-big-thing'
$

Creating Commits

See the Git Introduction to get started.

Here are a few notes specific to Qt/Gerrit:

  • If you correctly set up the clone, the commit message editor will present you with a template for the message.
  • The guidelines for creating good commit messages - and creating good commits in general, for that matter - are outlined in the Commit Policy.
  • On initial creation of a commit, if the commit-msg hook is set up properly, an additional line in the form of "Change-Id: …" should have been added.

Uploading Commits

Changes are pushed to Gerrit with git push or git gpush(see below). Note that a special target ref is used. Gerrit reports how many Changes were created and provides links to these Changes.

$ git push gerrit HEAD:refs/for/dev
Counting objects: 6, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 407 bytes, done.
Total 4 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2)
remote: Processing changes: new: 1, refs: 1, done    
remote: 
remote: New Changes:
remote:   https://codereview.qt-project.org/12345
remote: 
To ssh://qtcontributor@codereview.qt-project.org:29418/qt/qtbase
 * [new branch] HEAD -> refs/for/dev
$

When pushing to Gerrit, a typical refspec uses HEAD as the source ref and a special Gerrit ref for the target branch. The target ref has the format refs/for/<branch name>. Pushes to this target ref causes Gerrit to create new Changes for all commits pushed this way. To group your Changes, push to a topic by using the format refs/for/<branch name>/<topic name>. Note that it is possible to use any other ref as source ref instead of HEAD when necessary. See Branch Guidelines to decide about the target branch.

It is recommended that you use the git-gpush command from our qtrepotools repository For more information on using Git Scripts see our page on Git Scripts.

$ git gpush
[same output as above]

Once a Change has been created, it can be viewed in the web browser:

Error creating thumbnail: File missing

Soliciting Feedback

The contributor requests feedback by adding reviewers to the Change. This is typically done via the web browser. Access the Change with the web browser and use the pen icon next to the names of the "Reviewers" to add any other registered user(s) to the review.

Alternatively, reviewers can be added already when uploading a contribution. Use the git-gpush tool for that purpose:

$ git gpush +approver@example.com
[same output as above]

Review Workflow

It is easy to get an overview of pending contributions in the "Your" page, also known as the "Dashboard":

Gerrit Intro Dashboard.png

It is possible to find Changes by issuing search queries. Links for the Change owner, project name and branch name in the search result listings can be used to quickly search for related Changes.

The navigation bar at the top of the Gerrit web view provides quick access to common search queries under the "Your" and "Changes" items.

Reviewing Contributions

The review process starts with choosing a Change to review. After choosing a Change, changed files can be viewed side-by-side and comments can be posted in-line to each file. Contributions are typically reviewed by Approvers, but anyone can make a review.

The following steps are needed to complete a code review:

  1. Opening the Change page (entered from the Dashboard or following a link in a notification mail)
  2. Reviewing changed files
  3. Publishing comments and reviewing results

Viewing the Change Overview

Changes can have several Patch Sets. When Changes get updated after review, the Patch Set number increases.

Gerrit Intro PatchSets.png

Reviewing Changed Files

Changes are compared side-by-side or in the unified diff view. The reviewer can also compare differences between specific Patch Sets (also called "inter-diffs").

Comments are posted by double clicking on a line. Comments are saved as drafts until they are published.

Note that comments are formatted as flowed text, discarding individual line breaks. A simple Wiki-like syntax is supported.

Gerrit Intro Commenting.png

Gerrit Intro CommentDrafts.png

Gerrit keeps track which files have been reviewed and which files have comments ready to be published. If an ongoing review is interrupted, the reviewer can return later and resume where they left off. Draft comments can be edited and deleted before they are published.

Downloading Changes

It is also possible to download Changes for local review. The easiest way to do that is to copy the Download link from Gerrit to the command line:

Gerrit Intro CheckingOut.png

Error creating thumbnail: File missing
$ git fetch ssh://qtcontributor@codereview.qt-project.org:29418/qt/qtbase refs/changes/19/419/1 && git checkout FETCH_HEAD
From ssh://codereview.qt-project.org:29418/qt/qtbase
 * branch refs/changes/19/419/1 -> FETCH_HEAD
Note: checking out 'FETCH_HEAD'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.  

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

git checkout -b new_branch_name

HEAD is now at 9a006a3... My Feature
$ git checkout -b changes/419
Switched to a new branch 'changes/419'
$

This makes it possible to use the usual git commands to view changes, to build the code, and to run tests.

Publishing Comments

When all files are reviewed, the reviewer continues to the Publish Comments screen with the Review button.

The review is completed by writing an optional cover message and giving a score. The cover message uses the same Wiki-like syntax as inline comments.

The Code Review category has 5 levels. A Change can only be submitted after it receives a +2 score, and cannot be be submitted if it receives a -2 score. Giving these scores is limited to Approvers; regular contributors can give only advisory scores (-1 to +1).

A Sanity Review score should not be given unless the Sanity Bot made a mistake and needs to be overridden.

Gerrit Intro Publishing.png

Gerrit Intro Published.png

Publishing Review Results From The Command Line

An alternative to browser-based review is to use the Gerrit ssh command line interface. Please do not do this, as scripting a step which is meant to be visual and interactive removes the additional safety net.

Processing Review Feedback

The contributor can view feedback on their contributions by accessing the Change page and reading comments file-by-file. It is possible to reply to comments and have a discussion about the code review in-line.

The contributor processes the feedback by following these steps:

  1. Opening the Change page (entered from the Dashboard or following a link in a notification mail)
  2. Locating comments in the Change page
  3. Reading and writing in-line comments
  4. Publishing a reply and/or uploading a new Patch Set

Locating Comments in The Change

Comments are located in their own tab next to the files tab.

Gerrit Intro Comments.png

Reading in-line Comments

Replies can be posted by clicking the 'Reply' button as shown in the image below:

Gerrit Intro Replying.png

Note that the comments are not actually posted until you publish them.

Note: do not reply to the notification mails you get from Gerrit. The mails you send this way will not be publicly visible and archived.

Updating a Contribution With New Code

Most Changes require multiple iterations of the review process. The contributor needs to update the Change if it received some comments that require action, or it did not merge with the branch tip. Each time a Change is updated, it gains a new Patch Set.

Updating a Change is done by following these steps:

  1. Accessing the Changes
  2. Modifying the Change(s)
  3. Pushing updated Changes


Note for github/bitbucket/... users

Note, that in contrast to github, bitbucket, gitlab etc., in Gerrit the change under review is a single commit. (In github etc. the review is about whether to merge the feature branch into master, in Gerrit the review is about whether the commit should be accepted into master.) So in order to change the content of a review, there must be a single new commit that contains everything you would like to review. This is not "rewriting public history" because the commits under review are not (yet) part of the "public history" -- only after they are accepted, they become part of the projects history. The following sections explain how to create a new commit that is suitable to replace the old commit for the review.

Accessing The Changes

If the original commit(s) are still available, it is possible to amend them right away. Otherwise, download the Change(s) the same way as for local review.

If Gerrit reported a merge conflict, now would be the time to rebase the Changes:

$ git rebase --onto origin/dev

If you are not using a separate branch, you can just use git pull --rebase.

Note: Please do not rebase unnecessarily, as this makes inter-diffs much less useful.

Modifying Commits

Modifications in the working tree are committed with the --amend option. If the contribution consists of multiple commits, you will need to use git rebase --interactive to revise earlier commits.

When you amend commit messages, make sure to preserve the Change-Id footer, as this is how Gerrit identifies new Patch Sets for existing Changes.

$ vim src/foo.cc
$ git add src/foo.cc
$ git commit --amend
[changes/419 2ea7773] My Feature
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 src/foo.cc
$

Pay even more attention to copying the Change-Id when you redo commits from scratch.

Pushing Updated Changes

The commit(s) are uploaded back to Gerrit with the same target ref as before. After the push, new Patch Sets will have been created for the target Change(s):

$ git push gerrit HEAD:refs/for/dev
Counting objects: 6, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 419 bytes, done.
Total 4 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2)
remote: Processing changes: updated: 1, refs: 1, done
To ssh://qtcontributor@codereview.qt-project.org:29418/qt/qtbase.git
 * [new branch] HEAD -> refs/for/dev
$

If anything goes wrong at this stage, please see the troubleshooting chart. Otherwise, when you reload the gerrit page in your browser, you should see the change, like this:

Gerrit Intro Updating.png

Integrating Changes

To submit a Change to the CI system press the "Stage". button on the top right

It is usually best when the contributor submits their own Changes.

Even if there are multiple reviewers, only one +2 approval is required. However, if other reviewers have shown a specific interest in a contribution, such as by repeated comments, it is polite to give them some time to add a +1 or +2 before submitting. See the Review_Policy for more details.

Gerrit Intro Submitting.png

Continuous Integration

Gerrit has been slightly customized for the Qt project. The continuous integration system that is running regular builds and tests has been incorporated to the workflow. Instead of directly submitting Changes, Changes can be merged to a staging branch. There is a staging branch for each normal branch. Staging branches are maintained by Gerrit and are not visible to the contributors.

Gerrit Intro Workflow.png

As part of the customization, Changes gained new states. Changes in the New state are waiting for a review. After review, Changes are merged to a staging branch and marked as Staged. The continuous integration system will pick staged Changes at regular intervals and move them to the Integrating state. From the Integrating state Changes are either submitted or moved back to the New state. If builds succeed and tests pass, the Changes are submitted or merged into their destination branch. Otherwise they are moved back to the New state for further analysis. The contributor of the affected Change(s) is expected to analyze the failure and upload fixes as necessary.

Abandoning and Deferring Contributions

Changes which are inherently flawed or became inapplicable should be abandoned. An abandoned Change will disappear from open Changes lists and is considered closed. Abandoned Changes can be restored later if they become valid again or if they were abandoned by accident.

Changes which have potential but will not be worked on in the near future should be deferred. Deferred Changes are basically abandoned, but are more easily accessible via the "My Deferred Changes" menu item.

Abandoning is a normal operation that is used to maintain Gerrit and hide Changes that will not make their way to the Git repository, for any reason.

To abandon a Change, its owner or an Administrator can click the "Abandon" button:

Gerrit Intro Abandon.png

Gerrit Intro Abandoned.png

Feature Branches

The Qt Project's handling of branches is documented by the Branch Guidelines.

Topics vs. Branches

Gerrit topics can be used as "feature branches". A topic is created when a target ref like refs/for/<branch name>/<topic name> is used. It is often good enough to push a set of commits for review to a topic. However, if the contributor intends to work with others on a long-living branch, the Gerrit Administrators should be contacted for a new branch in Gerrit. Also, the QA team has to be contacted so they can include the new branch in the CI system builds. This way the code can be reviewed already when working on it in the branch.

Merging Feature Branches

Merges between feature branches and the mainline are like all other commits and are pushed, reviewed and staged the usual way. However, only 'Merge Masters' can push merge commits. User may recruit the merge master from outside project team if it they do not have person knowledgeable on Git available. Note: Do not create a merge from commits which have not been integrated yet.

Merging Branches Alien to Gerrit

This should not happen often. Nevertheless, only a merge commit should be pushed in this case. 'Push Master' can be asked to import the branch into Gerrit.

Moving Changes to Different Branches

It sometimes happens that you push a change for the wrong branch. To correct this mistake, do not create a new change, but instead ask Gerrit to move the existing change to a new branch. You'll find the action in the menu opened by the "three vertical dots" button near the top right of each change.

Take care to make subsequent pushes of the change to the new branch, as otherwise a duplicate will be created.

If the action cannot be executed (typically, you are not the Change's owner, or a conflicting Change exists), ask a Gerrit Administrator to deal with the issue.

Closing Remarks

See Gerrit Caveats and Hints to avoid common traps.

There is a process for requesting new repositories.

Report bugs in our Gerrit to the bugtracker. Ideally, provide a link to an upstream issue (note that the issue may be already closed, as we are typically lagging by several versions).