code review with git and gerrit - devoxx 2011 - tools in action - 2011-11-14
DESCRIPTION
Presentation held at devoxx 2011 on 2011-11-14TRANSCRIPT
Code Review with
Git and Gerrit
Chris Aniszczyk (Twitter)
Matthias Sohn (SAP)
Git … a distributed revision control system built by the Linux project to facilitate code review Distributed means no central repository • No central authority! • Easy offline usage • Easy to branch a project • Protected against manipulation by cryptographic hashes
Really good at merging • Coordination only needed "after the fact” • Easier to rejoin (or refresh) branches
Supporting many workflows Advanced features
Copyright © C. 2011 Aniszczyk, M. Sohn
Git at Eclipse
Eclipse is moving to Git CVS has been deprecated and will be retired end of 2012
project / code repository break down as of 2011-10-31
http://eclipse.org/projects/scmcountdown.php
Copyright © C. 2011 Aniszczyk, M. Sohn
Git in Java
JGit is a lightweight Java library implementing Git • http://www.eclipse.org/jgit/
EGit is an Eclipse Team provider for Git based on JGit • http://www.eclipse.org/egit/
Gerrit Code Review is a Git server based on JGit adding permission control and review workflow • http://code.google.com/p/gerrit
Gitblit is another Git server based on JGit • browsing Gits (like GitWeb) • commit statistics and RSS feeds • http://code.google.com/p/gitblit/
Copyright © C. 2011 Aniszczyk, M. Sohn
Roles at Eclipse and Code Review Committer
Formally elected Can commit own changes without review
Contributor Small changes Reviewed by committers Bigger changes Also formal IP review by legal team In separate protected Bugzilla (IPZilla)
Review Tool
Patches attached to bug in Bugzilla Comments in Bugzilla
Copyright © C. 2011 Aniszczyk, M. Sohn
Git at Eclipse
JGit • Lightweight Java Git implementation • http://www.eclipse.org/jgit/
EGit • Eclipse Team provider for Git based on JGit • http://www.eclipse.org/egit/
Copyright © C. 2011 Aniszczyk, M. Sohn
Eclipse - Review Process Review not done for all changes Each Eclipse.org project does it differently Reviews tedious for contributors (and also for committers mentoring contributors)
Copyright © C. 2011 Aniszczyk, M. Sohn
Modern Code Review – What is it ? • When one developer writes code, another developer
is asked to review that code
• A careful line-by-line critique
• Happens in a non-threatening context
• Goal is cooperation, not fault-finding
• Integral part of coding process
• Otherwise this will happen: • Debugging someone else's broken code • – Involuntary code review: Not so good; emotions may flare
Guido van Rossum [1]
[1] http://code.google.com/p/rietveld/downloads/detail?name=Mondrian2006.pdf Copyright © C. 2011 Aniszczyk, M. Sohn
Code Review – Benefits • Four eyes catch more bugs
o Catch bugs early to save hours of debugging
• Mentoring of new developers / contributors o Learn from mistakes without breaking stuff
• Establish trust relationships o Prepare for more delegation
• Good alternative to pair programming o asynchronous and across locations
• Coding standards o Keep overall readability & code quality high
Guido van Rossum [1]
[1] http://code.google.com/p/rietveld/downloads/detail?name=Mondrian2006.pdf Copyright © C. 2011 Aniszczyk, M. Sohn
Gerrit Code Review Gerrit is a Code Review system based on JGit • http://code.google.com/p/gerrit/ • Apache 2 license (developed for Android) • Git server • access control and review workflow
Used by • Android • Google, SAP, ... • Eclipse
o JGit, EGit http://egit.eclipse.org/ o for other Eclipse projects:
…coming soon…
Copyright © C. 2011 Aniszczyk, M. Sohn
Developer PC
Gerrit
git git git git
Developer PC
git git
Hudson
- clone repository - fetch / push changes
- verify proposed changes - continuous integration builds
Copyright © C. 2011 Aniszczyk, M. Sohn
Gerrit Architecture Gerrit = Git server + Permissions + Codereview Workflow • Git based code review system • Hosts many Git repositories
• Speaks Git protocol o no Gerrit client installation required
• Provides per-project Access Permissions • Web interface for Code Review
Copyright © C. 2011 Aniszczyk, M. Sohn
When does Code Review Happen? • Code Review before changes reach the code base
• Buggy changes discovered and fixed before they get
merged • Only completed changes reach the project history
o reviewers reject unfinished changes • Only well described changes reach the code base
o commit message is also subject of the review • Project history clean and usable
Copyright © C. 2011 Aniszczyk, M. Sohn
Gerrit – Extreme Branching
Copyright © C. 2011 Aniszczyk, M. Sohn
Developer PC
git git
Gerrit
git git git git
push improved change 10
Developer PC
git git
fetch change 23 to try it
master
change 12
change 10
change 23
submit accepted change 12
fetch master updates
Integration with EGit • Gerrit is a Git server
• any Git implementation can work with Gerrit • EGit provides extra features to ease work with Gerrit
o fetching a change from Gerrit based on its ID o automatic "push to Gerrit" configuration
• Mylyn Reviews has a Gerrit connector
Copyright © C. 2011 Aniszczyk, M. Sohn
Gerrit - Workflow
Gerrit - Workflow • Every change is reviewed
o Authors can invite reviewers o Complex changes reviewed by many
• Look at the change o Comment on how to improve it o Discuss in context of the change
• Download the change o test it o improve it
• Discussion usually leads to improving the original proposal o new Git commit replaces old one (amend) o pushed as a new patchset for same Gerrit change
• Hudson also can vote
Copyright © C. 2011 Aniszczyk, M. Sohn
Gerrit Review UI
http://egit.eclipse.org/r/#change,825 Copyright © C. 2011 Aniszczyk, M. Sohn
Mylyn Reviews - Gerrit Connector
Integrates Gerrit into Eclipse • Task list integration
• Review editor,
inline comments • Publishing reviews
• EGit integration for fetching changes in review
Copyright © C. 2011 Aniszczyk, M. Sohn
Code Review – Our Experience Review all changes!
Review takes time (1 day … weeks)
Implies parallel workflow
Every team member should do reviews regularly
Authors have to wait for the review to happen
Git & Gerrit help a lot here
Copyright © C. 2011 Aniszczyk, M. Sohn
No Free Lunch ? -- DEMO
Copyright © C. 2011 Aniszczyk, M. Sohn
Conclusion
Code Review rocks ! Gerrit enables a nice code review workflow DVCS like Git are powerful Git supports convenient branching and merging Git is very fast and scales well
Copyright © C. 2011 Aniszczyk, M. Sohn
Code Review – Our Experience • Review all changes!
• Review takes time (1 day … weeks)
• Implies parallel workflow
• Every team member should do reviews regularly
• Authors have to wait for the review to happen
• Git & Gerrit help a lot here
Copyright © C. 2011 Aniszczyk, M. Sohn