code review with git and gerrit - devoxx 2011 - tools in action - 2011-11-14

24
Code Review with Git and Gerrit Chris Aniszczyk (Twitter) Matthias Sohn (SAP)

Upload: msohn

Post on 17-May-2015

3.169 views

Category:

Technology


3 download

DESCRIPTION

Presentation held at devoxx 2011 on 2011-11-14

TRANSCRIPT

Page 1: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

Code Review with

Git and Gerrit

Chris Aniszczyk (Twitter)

Matthias Sohn (SAP)

Page 2: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

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

Page 3: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

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

Page 4: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

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

Page 5: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

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

Page 6: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

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

Page 7: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

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

Page 8: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

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

Page 9: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

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

Page 10: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

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

Page 11: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

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

Page 12: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

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

Page 13: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

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

Page 14: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

Gerrit – Extreme Branching

Copyright © C. 2011 Aniszczyk, M. Sohn

Page 15: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

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

Page 16: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

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

Page 17: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

Gerrit - Workflow

Page 18: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

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

Page 19: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

Gerrit Review UI

http://egit.eclipse.org/r/#change,825 Copyright © C. 2011 Aniszczyk, M. Sohn

Page 20: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

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

Page 21: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

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

Page 22: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

No Free Lunch ? -- DEMO

Copyright © C. 2011 Aniszczyk, M. Sohn

Page 23: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

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

Page 24: Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14

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