Slide 1: Distributed Source Control With Mercurial
Or, How I Learned to Stop Worrying and Love the Merge
Ted Naleid - Lead Developer at Carol.com
Slide 2: Overview
• • • • •
Introduction SVN (centralized VCS) vs DVCS Current Popular DVCS Alternatives Mercurial (hg) examples Hands on with hg
Slide 3: checkout add remove update log commit merge ...
remote central repos
Build Server
Centralized VCS (SVN)
Slide 4: Alice's repos add remove update log commit diff merge ... push pull push pull push pull Dave's repos
Bob's repos
build repos
Build Server
Distributed VCS (Mercurial)
Slide 5: SVN Limitations
DVCS/Mercurial Strengths
Slide 6: Branching is easy, but merging is painful Branching is easy, merging is (relatively) easy
Slide 7: Active net connection required to interact If your computer is on, you have access to the repository
Slide 8: Unable to share changes with others without sharing with everyone
(including the build server)
Sharing changes with selected people is easy
(hg serve/hg push/hg pull)
Slide 9: Fails to merge changes when something is renamed
Aware of file history and can merge into renamed file
Slide 10: .svn files are littered throughout your source tree
Single .hg directory at root of source tree
Slide 11: Slow over-the-wire performance
Fast performance; you’re working on local filesystem
Slide 12: Discourages experimentation
Cheap to create/throw away local experimental branch
Slide 13: SVN Strengths
DVCS/Mercurial Limitations
Slide 14: Familiar to most developers
Most developers will need to learn to think differently
Slide 15: Relatively easy to grasp
Better understanding of version control concepts required
Slide 16: Everyone knows where the trunk is because there’s only one server Need to define and adhere to convention to know where the trunk is
Slide 17: Well established tool support and integration
Tool support and integration isn’t quite as far along
Slide 18: There is a winner among free, centralized VCS systems: Subversion DVCS systems are still new and a clear winner has not been established
Slide 19: Popular 2nd Gen DVCS Systems
Git - Bazaar - Mercurial
Slide 20: Git
Created by Linus Torvalds in 2005 after the BitKeeper “debacle”
Slide 21: Git - Website & Hosting
• •
Website: http://git.or.cz/ Hosting:
• •
http://github.com http://repo.or.cz
Slide 22: Git - Use in the Wild
• • • • •
Linux Kernel One Laptop Per Child (OLPC) Ruby on Rails Lots of other Ruby stuff Written mostly in C
Slide 23: Git - Common Wisdom
• • • • •
Fastest of the DVCS systems Unfriendly to non-Linux/Unix systems Complex, with ~150 commands added to path Very popular in the Linux/Ruby communities Probably the most “buzz” off all DVCS systems right now
Slide 24: Bazaar (bzr)
Created by Canonical, Ltd. (creators of Ubuntu) in 2005
Slide 25: Bazaar - Website & Hosting
• •
Website: http://bazaar-vcs.org/ Hosting: https://launchpad.net/
Slide 26: Bazaar - Use in the Wild
• • •
Ubuntu Drupal Fairly big in Python community
•
it’s written mostly in Python
Slide 27: Bazaar - Common Wisdom
• • • • •
Has gone through lots of revisions/changed formats Slowest of the 3 Migration of an existing SVN repository is REALLY slow Made to be friendly, similar to SVN Smallest market share
Slide 28: Mercurial (hg)
Created by Matt Mackall in 2005 after the BitKeeper “debacle”
Slide 29: Mercurial - Website & Hosting
• •
Website: http://www.selenic.com/mercurial/ Hosting:
• •
http://freehg.org/ http://sharesource.org/
Slide 30: Mercurial - Use in the Wild
• • • • •
OpenJDK (Java) OpenSolaris Mozilla NetBeans Many others (largely Java/Python related)
•
Like Bazaar, it’s mostly written in Python
Slide 31: Mercurial - Common Wisdom
• • • • •
Similar syntax to SVN Slightly slower than Git, but faster than Bazaar Good cross-platform support Getting good support from large Java projects (OpenJDK, NetBeans, etc) Lower maintenance and easier learning curve than Git
Slide 32: Why did I choose Mercurial over Git/Bazaar?
Slide 33: Similar commands to SVN
• • • • • •
hg add hg remove hg update hg log hg status It’s like SVN but with the ability to “push” and “pull”
Slide 34: Better cross platform support and growing tool integration
Slide 35: No “packing” of the repository is necessary
Slide 36: Local revision numbers are “friendly”
Slide 37: It’s used by a number of big Java projects
Slide 38: It’s the first one I tried :)
Slide 39: All 3 of these tools look fantastic.
Slide 40: Mercurial Usage Examples
How do I do X?
Slide 41: portal/** local file system hg init hg addremove hg commit
portal/.hg local repos
Create a new repository
Slide 42: portal/** local file system creates tip files on filesystem
portal/.hg
http://hg01/repos/portal remote repos
local repos
hg clone
hg clone http://hg01/repos/portal
“Checkout” an Existing Repository
Slide 43: portal/** local file system
portal/.hg
http://hg01/repos/portal hg pull remote repos
hg update
local repos
"hg pull -u" will do this in one command
Pull down the latest changes
(no conflicts with local changes)
Slide 44: local file changes hg commit local file system
conflict! files unchanged!
portal/.hg hg update hg pull local repos
http://hg01/repos/portal remote repos
hg merge hg commit
"hg fetch" will pull->update->merge->commit in one command
Pull down the latest changes
(conflicts detected with local changes)
Slide 45: local file changes portal/.hg local file system hg add hg remove hg addremove hg commit http://hg01/repos/portal remote repos hg push
local repos
Push changes to another repository
(by default, push will refuse to run if it would require a merge)
Slide 46: portal/.hg local repos hg incoming hg outgoing
http://hg01/repos/portal remote repos
Do a push/pull dry run
Slide 47: portal/.hg
Branching is done by simply cloning a repository portal-clone/** local file system creates tip files on filesystem
local repos hg clone
hg clone portal portal-clone
portal-clone/.hg local repos
Create a new “branch”
(experimenting is cheap and easy)
Slide 48: local file changes portal/.hg local file system hg diff hg status hg identify local repos
Compare file system with repository
Slide 49: portal/.hg hg log hg annotate hg cat hg grep hg serve local repos
Query repository for info
Slide 50: Hands on with Hg
Slide 51: Creating new repository
Slide 52: Cloning repository/ branching
Slide 53: Pushing changes to another repository
Slide 54: Merging conflicting changes
Slide 55: Creating a tag
Slide 56: Searching through history
Slide 57: Viewing repository through a web browser
Slide 58: A quick way to stick your toes in and try Mercurial out: use it as a “Super Client” for SVN
Slide 59: Web Resources
• • • • •
Choosing a distributed version control system
http://www.dribin.org/dave/blog/archives/2007/12/28/dvcs/
Understanding Mercurial
http://www.selenic.com/mercurial/wiki/index.cgi/UnderstandingMercurial
Version Control and the “80%” (DVCS counterpoint)
http://blog.red-bean.com/sussman/?p=79
Mercurial Book
http://hgbook.red-bean.com/hgbook.html
Video of Bryan O’Sullivan (creator of the Mercurial Book)
http://video.google.com/videoplay?docid=-7724296011317502612
Slide 60: Questions?