How Google Does Code Review
Join the DZone community and get the full member experience.Join For Free
mondrian has been talked about a lot over the years. guido van rossum, who lead the development talked in 2006 about it, and the fun he had making it:
guido was a googler then, but now he works for dropbox. a thoroughly nice guy.
this could be out of date as i only have context up to the end of 2008, but for the most part they only review commits that happen on the trunk. apart from android, google does trunk based development (tbd) everywhere. they made the review process as lean as they could, by making reviews ordinary and continuous. in google’s view, perforce’s change-lists (cls) either have or have not been reviewed. mondrian keeps track of those. releases, as such, don’t have a late cycle of reviews. indeed it feels that ‘review’ is not an entity within mondrian, but instead another artifact of a commit (a cl). as it is not an entity in itself, there is a 1:1 mapping of reviews to cls. i’m laboring it now, but change-lists are the only important noun going on here.
- more than one person can dive into a review
- some people are going to be keener than others to review the work of others
- reviews happen within minutes or hours of code-completion
- as a developer, you are naturally going to be offered reviews for things in your project (or library/framework) area..
- .. but you might also review something completely out of your assigned area
thus to google “continuous review” is merely the speedy picking up of unreviewed pending commits. by ‘pending’, i mean that the commits have not hit the trunk yet. indeed until they ‘pass’ review, they are not going to. perforce’s pending commits can have a unique number, and be extracted from the developer’s workstation even before they are allowed to be committed to the trunk for posterity (after successful review). guido had to do a lot of tooling to make that smooth though.
google’s internal mondrian has inspired two open source equivalents
unrelated to mondrian:
- atlassian’s crucible is the big commercial success (git, mercurial, subversion and perforce)
- reviewboard (open source & for subversion, git, mercurial, bazaar, perforce, clearcase & plastic)
- phabricator (open source & for git, mercurial and subversion)
- collaborator " (commercial for – git, mercurial, subversion, clearcase, perforce and tfs)
these are all installable. there are portals like github that have an built-in review mechanism, that i’m not going to go into.
enterprises other than google
most enterprises are not going to setup pre-commit reviews, but instead to a boy-scout-pledge to not break the build and review after the commit. with review as an entity, it’s not uncommon to group multiple commits into one code review. with review as a larger entity, you might have a formal workflow around it, and indeed have a formal assignment and management aspect to the review.
atlassian’s crucible is an installable tool that works like that – assignable reviews that can happen any time and are usually an aggregation of commits. crucible (which i’m going to concentrate on for the remainder of this article) can review commits on any number of branches and attempts to make sense of the ancestry.
bigger enterprises with more separate projects going on, are going to do there reviews late (if at all). industry regulators as well as internal wishes to be more professional can drive code-reviews.
problem – not knowing you’ve reviewed something already
we’re going to dive into a worked examples here, for crucible specifically, as it’s the gorilla in the room.
install your own crucible (a 30 day demo is downloadable), and launch it.
crucible with subversion
make a subversion repo with this script (create_repo.sh):
#!/bin/sh svnadmin create $2 perl -p -i -e "s/# anon-access/anon-access/g" $2/conf/svnserve.conf perl -p -i -e "s/# auth-access/auth-access/g" $2/conf/svnserve.conf perl -p -i -e "s/# password-db/password-db/g" $2/conf/svnserve.conf perl -p -i -e "s/# harry = harryssecret/harry = harry/g" $2/conf/passwd svn mkdir file:///path/to/root/directory/$2/trunk -m "create trunk" svn mkdir file://$1/$2/branches -m "create branches"
use that like so, before starting the svn server:
./create_repo.sh /path/to/root/directory repo_name sudo svnserve -d --foreground -r /path/to/root/directory
in crucible admin console add a repository for svn://127.0.0.1/repo_name
run this shell script (svn_test.sh) to populate the directory:
#!/bin/sh mkdir -p svn_workingcopy rm -rf svn_workingcopy/* rm -rf svn_workingcopy/.svn svn --username harry --password harry co $1 svn_workingcopy cd svn_workingcopy/trunk echo "** create trunk version of file" echo "efficiently unleash cross-media information without\nimmediate value. dramatically\nmaintain clicks-and-mortar solutions without\nfunctional aspects." > file.txt svn add file.txt svn --username harry --password harry commit -m "initial version on trunk" # svn --username harry --password harry copy $1/trunk $1/branches/br1 -m "branch br1 from trunk w/o mods" echo "** create branch .." svn --username harry --password harry copy $1/trunk ../branches/br1 if [ "$2" = "mod" ]; then echo "** .. with small modification during branching" perl -p -i -e "s/aspects/bits and pieces/g" ../branches/br1/file.txt fi svn --username harry --password harry commit .. -m "branch br1 from trunk with one mod" echo "** modify trunk version of file" perl -p -i -e "s/cross-media/sexed-up/g" file.txt perl -p -i -e "s/clicks-and-mortar/empirical/g" file.txt svn --username harry --password harry commit -m "follow-up change on trunk" cd ../branches svn up --username harry --password harry cd br1 echo "** modify branch version of file" perl -p -i -e "s/cross-media/socially-awkward/g" file.txt perl -p -i -e "s/immediate/any/g" file.txt svn --username harry --password harry commit -m "divergent and potentially clashing modification on the branch" svn up .. echo "** merge trunk to branch at head, preserving 'any' from the br1 ancestor, taking 'empirical' from the trunk, and choosing neither ancestor with 'tie-dyed'" svn --username harry --password harry merge --accept=postpone $1/trunk . echo "efficiently unleash tie-dyed information without\nany value. dramatically\nmaintain empirical solutions without\nfunctional aspects." > file.txt if [ "$2" = "mod" ]; then perl -p -i -e "s/aspects/bits and pieces/g" file.txt fi svn --username harry --password harry resolve --accept=working file.txt svn --username harry --password harry commit -m "merge from trunk to branch, with resolved conflict (and an auto-merge)"
then go into the web interface and take a look at the “commit graph” for the repo:
the commit i’ve highlighted (#4) created the branch. note yesterdays article raised a subversion defect – the test case i’m using made the branch ‘unchanged’ from the trunk, yet subversion registers a commit, and that commit is noisy compared to what is should be:
ph7785:svn_workingcopy paul$ svn diff -r 3:4 index: branches/br1/file.txt =================================================================== --- branches/br1/file.txt(revision 0) +++ branches/br1/file.txt(revision 4) @@ -0,0 +1,5 @@ +efficiently unleash cross-media information without +cross-media value. quickly maximize timely +deliverables for real-time schemas. dramatically +maintain clicks-and-mortar solutions without +functional solutions.
this lines didn’t change! crucible fixes that for you though, with some clever double-checking:
without that crucible fix for (or masking of) the subversion bug, you might end up reviewing everything that happened on trunk all over again, even if you reviewed it before.
there another snafu in subversion in that the merge from revision 5 on trunk, isn’t shown into revision 7 on branch br1. i’ve added a red arrow to show what that should look like:
atlassian note some limitations in an article viewing the commit graph for a repository (search for ‘subversion’ in the page). they could, i suspect, eliminate that bug.
the clashing merge (and ultimate commit) – #7
two changes to note
line 1 – versus the common ancestor which said ‘cross-media’, the trunk (before the merge) has been changed to ‘sexed-up’. versus the common ancestor, the branch br1 (before the merge) has been changed to ‘socially-awkward’. both of those counted for nothing though, as we arbitrated by choosing ‘tie-dyed’ instead.
line 3 – versus the common ancestor which had ‘clicks-and-mortar’, the trunk (before the merge) was changed to ‘empirical’ in change #5. the branch had no change versus the common ancestor. this merge shows the ‘empirical’ change as a change in #7, which technically it is (was not previously on the branch br1), but it might have been reviewed before as part of a review for #5.
it’d be great if crucible could show that it was in a previous commit and even reviewed with a different color.
one change not apparent
it’d previously happened on the branch, but ‘immediate’ (line 2) had changed to ‘any’. it’s correct that it is not shown.
crucible with git
make a new git repo inside crucible (remember the repo_name).
with this script (git_test.sh):
#!/bin/sh rm -rf git_workingcopy git clone $1 git_workingcopy cd git_workingcopy echo "** create trunk version of file" echo "efficiently unleash cross-media information without\nimmediate value. dramatically\nmaintain clicks-and-mortar solutions without\nfunctional aspects." > file.txt git add file.txt git commit -m "initial version on master" echo "** create branch .." git branch br1 git checkout br1 if [ "$2" = "mod" ]; then echo "** .. with small modification during branching" perl -p -i -e "s/aspects/bits and pieces/g" file.txt fi echo "** modify trunk version of file" git checkout master perl -p -i -e "s/cross-media/sexed-up/g" file.txt perl -p -i -e "s/clicks-and-mortar/empirical/g" file.txt git commit -am "follow-up change on master" git checkout br1 echo "** modify branch version of file" perl -p -i -e "s/cross-media/socially-awkward/g" file.txt perl -p -i -e "s/immediate/any/g" file.txt git commit -am "divergent and potentially clashing modification on the branch" echo "** merge trunk to branch at head, preserving 'any' from the br1 ancestor, taking 'empirical' from the master, and choosing neither ancestor with 'tie-dyed'" git merge --no-commit -s ours master echo "efficiently unleash tie-dyed information without\nany value. dramatically\nmaintain empirical solutions without\nfunctional aspects." > file.txt if [ "$2" = "mod" ]; then perl -p -i -e "s/aspects/bits and pieces/g" file.txt fi git commit -am "merge from trunk to branch, with resolved conflict (and an auto-merge)" echo "you'll do the push yourself - master and br1 :)"
populate the test commits in the repo:
now go to the commit graph for that:
- those lines look like they are crossing. it’s just a display glitch in cruicible – it’s a rhombus really.
- the modification to trunk, on an implied timeline looks to have happened chronologically before the branch was made, and that was not the case. again, that’s a display choice in crucible that’s harmless.
- there’s only four commits. the branch creation isn’t shown as a commit (normal git behavior), and only the first change on that branch is shown.
- unlike for subversion, crucible shows the merge line from the latest one the trunk to the latest on the branch.
let’s look at the merge commit:
arghh, it’s a nightmare, it’s not showing me the diff on the branch. the previous commit on the branch looks like this:
how can something change from ‘immediate’ to ‘any’ in two successive commits on the same branch? the problem is that, in crucible at least, the parent of the merge was the last version on the trunk, not the last version on the master branch.
crucible with perforce
same as subversion. i didn’t make a script, although it would have been only 15% longer than the subversion one due to increased command-line setup complexity. caveats: the initial branch population in crucible – clicking on the diff does nothing (can’t see anything). atlassian note there are limitations in perforce too .
no pics, as i’m all picced out for now.
with crucible and any of subversion/git/perforce there were scenarios that would lead to changes being reviewed twice. really though it’s going to be a very small percentage of cases, and you shouldn’t worry about it. i have not explored, but it could be that there are things that don’t get reviewed at all, in a multi-branch code-review design.
i can’t help but feel that google’s linear and “continuous review” is simply the most efficient way to do reviews. sure we can’t do roll-up reviews (not otherwise covered in this article) by methodically reviewing every commit soon after they happen, but i’m not sure i’d want to if i’m losing all the context that comes with the commit messages.
actually, i’m sure a trunk based development workflow (regardless of your local-branching model), with reviews of the commits on the trunk only and asap is best. “continuous review” isn’t my coin by the way, but i like it.
Published at DZone with permission of Paul Hammant, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.