Code Reviews vs. Pull Requests
-
Upload
atlassian -
Category
Technology
-
view
6.131 -
download
1
Transcript of Code Reviews vs. Pull Requests
TIM PETTERSEN • SENIOR DEVELOPER • ATLASSIAN • @KANNONBOY
Code review vs
Pull requests
Code review at Atlassian
2006
2007Atlassian acquires Cenqua, starts using Crucible
TO O L I N G T H R O W D O W N
Y O U N E E D C O D E R E V I E W
T H E V E R D I C T
Agenda
n. koâla tēaQuality
CodeReview
Photo: Yogi (Flickr)
Better Code
Shared Knowledge
Team Ownership
G = 1
R+1
Developer guilt
Team Ownership
Better Code
Shared Knowledge
Team Ownership
Types of code review
Pull requests
Code review
Post-commit
Pre-commit
master
for/master
Gerrit
Criteria
Creation Iteration HistoryCollaboration
Pull requests
Post-commit
Pre-commit
master
for/master
Gerrit
// flat fees and taxes final float customsFee = 5.5f; final float immigrationFee = 7f; final float federalTransportTax = .025f;
public float calculateAirfare(float baseFare) { float fare = baseFare; fare += immigrationFee + customsFee; fare *= return fare; }
(1 + )
AirfareCalculator.java
federalTransportTax;
Pre-commit reviewFrom: Tim Pettersen <[email protected]> Date: Mon, 12 Sep 2016 10:24:10 +1000 Subject: [PATCH] Calculate federal transport tax correctly
--- a/com/atlassian/airfare/AirfareCalculator.java +++ b/com/atlassian/airfare/AirfareCalculator.java @@ -10,7 +10,7 @@ public float calculateAirfare(float baseFare) { float fare = baseFare; fare += immigrationFee + customsFee; - fare *= federalTransportTax; + fare *= (1 + federalTransportTax); return fare; }
$ git format-patch HEAD~1 --stdout
Pre-commit review
dev maintainer
public float calculateAirfare(float baseFare) { float fare = baseFare; fare += immigrationFee + customsFee;- fare *= federalTransportTax;+ fare *= (1 + federalTransportTax); return fare;}
Subject: [PATCH] Calculate federal transport tax correctly
> > > > >
The braces are unnecessary.
Pre-commit review
dev maintainer
public float calculateAirfare(float baseFare) { float fare = baseFare; fare += immigrationFee + customsFee;- fare *= federalTransportTax;+ fare *= (1 + federalTransportTax);
return fare;}
Subject: Re: [PATCH] Calculate federal transport tax correctly
> >
> >
> > > > > > > >
Technically true, but I think they add clarity.
> >
> > > > >
The braces are unnecessary.
Pre-commit review
dev maintainer
public float calculateAirfare(float baseFare) { float fare = baseFare; fare += immigrationFee + customsFee;- fare *= federalTransportTax;+ fare *= (1 + federalTransportTax);
return fare;}
Subject: Re: Re: [PATCH] Calculate federal transport tax correctly
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
Pre-commit review
dev maintainer
Subject: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re:
Iteration
master
Pre-commit reviewLinus Torvalds*
Module maintainers
File / driver maintainers
* Gross oversimplification, check out: bit.ly/linux-dev
Pre-commit review
Junio C Hamano*
* Also an oversimplification
Pull requests
Post-commit review
Pre-commit review
master
for/master
Gerrit
Pre-commit reviewVersion control agnostic
Simple and decentralized
Easy to keep ‘000s of people in the loop
Plain text diffs
One contributor per patch
Difficult to iterate
Have to manually merge work
Flexible structure
master
master
patches & untracked files
commits
branches
specific filesmultiple repos
Iterative review in
Not an SCM
SCM host (e.g. Bitbucket)
Review host (e.g. Crucible)
Dev team
push & pull
code review
slurp
slurp
slurp
slurp
Pull requests
Post-commit review
Pre-commit review
master
for/master
Gerrit
Post-commit reviewSupports popular CVCS and DVCS
Flexible review content
Easy to iterate
Have to manually merge work
Need a separate VCS host
Hard to enforce process
Gerritand DIFFY The Kung Foo Review Cuckoo
Gerrit is very “Git-y”
$ git config -f ~/gerrit/etc/gerrit.config gerrit.canonicalWebUrl
http://localhost:8080/
for/master
master
reviewers approved?
verified (build passing)?
Dev team
fetch
push
Gerrit
From: Gerrit Code Review - A Quick Introduction
+2+10-1-2
“squash commits first”
$ git push origin HEAD:refs/for/master
# typey type type
$ git commit -am “Review feedback”
Counting objects: 2108776, done. Delta compression using up to 8 threads. Compressing objects: 100% (59/59), done. Writing objects: 100% (86/86), 893.21 KiB, done. Total 86 (delta 0), reused 0 (delta 0)
! [remote rejected] HEAD -> refs/for/master (squash commits first) error: failed to push some refs to ‘ssh://...'
“squash commits first”
for/master
push
push --force
push --force
From: Gerrit Code Review - A Quick Introduction
Pull requests
Post-commit review
Pre-commit review
master
for/master
Staging area
GerritSophisticated policy enforcement
FOSS project built in Java, on JGit
Clean commit history
Steep learning curve to use & administer
Iteration is a little awkward
Git only
One contributor per patch
Branches only
master
master
patches & untracked files
commits
branches
specific filesmultiple repos
Iterative review in
Pull requests
review before merging
> Code review
Passing build
Reviewer sign-off
Ready for deployment
Pull request == IssueIN REVIEW DONEIN PROGRESSOPEN
Branch created!
Pull request created!
Pull request merged!
Two developers about to press the “Merge” button
@kannonboy
mas
ter
Pull requests Mailing list / Gerrit
Merge Strategies
--no-ff
--ff-only
--squash --ff-only
--squash
--ff
git merge --ff
master
feature/JIRA-123
“Fast forward if you can, otherwise create a merge commit.”
git merge --no-ff
master
feature/JIRA-123“Always create a merge commit.”
git merge --ff-only
master
feature/JIRA-123“Only allow fast forwards.”
git merge --squash
“Combine commits on branch into a new commit on master.”
master
feature/JIRA-123
git merge --squash \
“Combine commits on branch into a new commit on master. Fail if master has any commits that branch doesn’t.”
master
--ff-only
Merge Commit Fast forward Squash
Concise history
Lose context of how features evolved
Which should I use?
“Ugly” history
Full traceability
Hard to screw up
mostly some
--no-ff --ff-only --squash
No merge commits
Verbose history
Requires rebasing
Pull requestsSophisticated policy enforcement
Choice of merge strategies
Multiple team members can author code under review
Git & Mercurial
Less flexible review content
Code Review vs. Pull requests
Need to review multiple repos at once
Not on Git
Heavily iterative workflow Literally everyone else
Dendrophobia
+
(Traditional)
bitbucket.org
Bitbucket
atlassian.com/crucible
Crucible
gerritcodereview.com
Gerrit
Lookingfor
more?
@kannonboy