Gerrit code review server workflow and principles

Source: Internet
Author: User
Tags sha1 hash git commands
Gerrit code review server workflow and principles the Google Android open-source project has two important innovations in the use of git. One is the repo introduced for multi-version library collaboration, we have discussed this in detail before. Another important innovation is Gerrit, the code review server. Gerrit is mandatory for the code review introduced by git. That is to say, the push to the GIT version library must go through the Gerrit server unless special authorization is set, A set of workflows that must be reviewed by the code can be approved and incorporated into the formal code library... 6.7 Gerrit code review server first, the contributor's code is pushed to the GIT version library under the Gerrit management through git commands (or repo encapsulation), and the push submission is converted into a code review task one by one, audit tasks can be accessed through references under refs/changes/<change-ID>. The Code reviewer can view audit tasks and code changes on the web interface, and make decisions through code review or recall on the Web interface. The tester can also test the refs/changes/<change-ID> reference acquisition (FETCH) revision, if the test passes, you can set the review task to verified ). Finally, revisions that have been reviewed and verified can be submitted to the corresponding branch of the version library through the Gerrit interface. The Code contribution flowchart of the website on the android project details the working process of the Gerrit code review server.

Code review workflow

6.7.1 implementation principle of Gerrit Git server for SSH protocolGerrit implements a set of git Servers Based on the SSH protocol. This allows for more precise control over git data push and lays the foundation for implementing mandatory review. The GIT service port provided by Gerrit is not the standard port 22, and the default port is port 29418. You can access the Gerrit Web interface to obtain this port. On the code review server for the android project, access the https://review.source.android.com/ssh_info to view the GIT Service's server domain name and open port. Below we use the curl command to view the webpage output.
$ curl -L -k http://review.source.android.com/ssh_inforeview.source.android.com 29418
Special references to Refs/For/<branch-Name> and refs/changes/nn/<task-ID>/mGerrit's git server prohibits users from pushing to references in the refs/Heads namespace (unless otherwise authorized), that is, users are not allowed to submit directly to the branch. To allow developers to submit revisions to the GIT server, the GIT server of Gerrit only allows users to push to the specially referenced refs/For/<branch-Name>, <branch-Name> is the branch of the developer. Pushing to the refs/For/<branch-Name> namespace does not create references in it. Instead, it allocates an ID for the new commit, called the task-id, create a reference refs/changes/nn/<task-ID>/m for the access to the task-ID in the following format, where:
  • Task-ID is the globally unique number assigned by Gerrit for the review task sequence.
  • NN is the last two digits of the task-id. If the number of digits is insufficient, it must be set to zero. That is, NN is the remainder of task-id divided by 100.
  • M is the revision number, and the first submitted revision number of this task-ID is 1. If the revision is rejected, the resubmit of the revision number will increase.
Git library hook script hooks/commit-MSGGerrit designed a set of methods to ensure that the submitted revisions are passed into the database after being pushed to the server by another branch, cherry-pick, and no new review tasks will be generated when pushed to the server, that is, each submission must contain a unique change-id. Because this change-ID appears in the log, it is maintained when cherry-pick is executed, once Gerrit finds that a new submission contains a change-ID that has already been processed, it will not create a new review task and task-ID for the revision, but will directly submit it to the database. To implement git commit that contains a unique change-ID, Gerrit provides a hook script that is stored in the developer's local git Library (hooks/commit-MSG ). This hook script automatically creates a "Change-ID:" and a unique identifier that contains the hash value generated by the GIT hash-object command during user submission. When Gerrit obtains the submission that the user pushes to Refs/For/<branch-Name>, it contains "Change-ID: I... "Change ID. If the change-ID has not been seen before, a new review task is created and assigned a new task-id, save the association between change-ID and task-ID in the Gerrit database. If a user's submission is required to be redone for some reason, when the developer re-pushes the changes to Gerrit, the developer must note that the same "Change-ID" is used in the submission instructions (use -- Amend to submit to maintain the submission instructions) to avoid creating new review tasks, the current Branch is also pushed to Refs/changes/nn/task-ID/m during the push. Where NN and task-ID are the same as the revisions for the previously submitted review tasks, M needs to manually select a new revision number. The above is complicated, but in actual operations, it is much easier to use the repo tool. Leave everything else to the WebAnother important component of Gerrit is the Web server, which controls the entire review workflow. For more information about Gerrit workflows, see the Gerrit workflow that appears at the beginning of this chapter. Feel the charm of Gerrit? Go directly to the Gerrit website for the android project: https://review.source.android.com /. Android project code review Website: Android Project Review website, which can be accessed anonymously. Click "merged" in the menu to display the audit tasks that have been reviewed and merged into the code base. The following interface is andorid, a historical review task that has been merged into the code base.

Android project 16993 Review

On this page, we can see:
  • The Review Task Number shown in the URL is 16993.
  • The change-ID of the review task starts with the letter I and contains a unique 40-bit sha1 hash.
  • Three people participated in the entire review task. One person verify and the other two performed code review.
  • The status of this review task is merged: "merged ".
  • The review task consists of two patch sets: Patch Set 1 and Patch Set 2.
  • The method for downloading the patch set is repo download platform/SDK 16993/2.
It is very convenient to use the repo command to obtain the patch set, because the encapsulated repo shields some Gerrit implementation details, such as the location of the patch set in the GIT library. As mentioned above, the patch set is actually saved in the 'refs/changes' namespace. Using the 'git LS-remote' command, we can see the reference name of the patch set in the code library maintained by Gerrit.
$ git ls-remote ssh://review.source.android.com:29418/platform/sdk refs/changes/93/16993*5fb1e79b01166f5192f11c5f509cf51f06ab023d        refs/changes/93/16993/1d342ef5b41f07c0202bc26e2bfff745b7c86d5a7        refs/changes/93/16993/2
Next, we will introduce how to deploy and use the Gerrit server.

Gerrit code review server workflow and principles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.