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

  • 3,030 views
Uploaded on

Presentation held at devoxx 2011 on 2011-11-14

Presentation held at devoxx 2011 on 2011-11-14

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • not much for sharing, uh slideshare? can't download this presentation
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
3,030
On Slideshare
0
From Embeds
0
Number of Embeds
4

Actions

Shares
Downloads
76
Comments
1
Likes
3

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Code Review withGit and Gerrit Chris Aniszczyk (Twitter) Matthias Sohn (SAP)
  • 2. 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
  • 3. 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
  • 4. 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
  • 5. Roles at Eclipse and Code ReviewCommitter Formally elected Can commit own changes without reviewContributor 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
  • 6. 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
  • 7. Eclipse - Review ProcessReview not done for all changesEach Eclipse.org project does it differentlyReviews tedious for contributors(and also for committers mentoring contributors) Copyright © C. 2011 Aniszczyk, M. Sohn
  • 8. Modern Code Review – What is it ? Guido van Rossum [1]•  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 elses broken code•  – Involuntary code review: Not so good; emotions may flare Copyright © C. 2011 Aniszczyk, M. Sohn [1] http://code.google.com/p/rietveld/downloads/detail?name=Mondrian2006.pdf
  • 9. Code Review – Benefits Guido van Rossum [1]•  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 Copyright © C. 2011 Aniszczyk, M. Sohn [1] http://code.google.com/p/rietveld/downloads/detail?name=Mondrian2006.pdf
  • 10. 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
  • 11. Gerrit git git git git - verify proposed changes- clone repository - continuous- fetch / push changes integration builds Developer PCPC Developer Hudson git git Copyright © C. 2011 Aniszczyk, M. Sohn
  • 12. 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
  • 13. 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
  • 14. Gerrit – Extreme Branching Copyright © C. 2011 Aniszczyk, M. Sohn
  • 15. Gerrit git git git git master change 12 submit accepted change 12 change 10 change 23 push improved fetch change 23fetch master to try itupdates change 10 Developer PC Developer PC git git git git
  • 16. 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
  • 17. Gerrit - Workflow
  • 18. 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
  • 19. Gerrit Review UICopyright © C. 2011 Aniszczyk, M. Sohn http://egit.eclipse.org/r/#change,825
  • 20. Mylyn Reviews - Gerrit ConnectorIntegrates 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
  • 21. Code Review – Our ExperienceReview all changes!Review takes time (1 day … weeks)Implies parallel workflowEvery team member should do reviews regularlyAuthors have to wait for the review to happenGit & Gerrit help a lot here Copyright © C. 2011 Aniszczyk, M. Sohn
  • 22. No Free Lunch ? -- DEMO Copyright © C. 2011 Aniszczyk, M. Sohn
  • 23. 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
  • 24. 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