Fast, Flexible and Fun: Revision Control with Mercurial
Total Page:16
File Type:pdf, Size:1020Kb
Fast, Flexible and Fun: Revision Control with Mercurial Martin Geisler [email protected] JAOO Geek Night in Aarhus August 25, 2009 Outline Introduction Basic Concepts Historic Context Subversion in Detail Using Mercurial The Underlying Model Workflows Using History Cool Extensions Changing History Talking to Other Systems Third-Party Tools Wrapping Up Alternatives Unsolved Problems Conclusion 2 / 45 Outline Introduction Basic Concepts Historic Context Subversion in Detail Using Mercurial The Underlying Model Workflows Using History Cool Extensions Changing History Talking to Other Systems Third-Party Tools Wrapping Up Alternatives Unsolved Problems Conclusion 3 / 45 Common features: ñ collaboration ñ branches ñ tags Not so common features: ñ speed! ñ much more, as you will see. Features in Version Control Systems Universal features: ñ let you save changes ñ browser the history 4 / 45 Not so common features: ñ speed! ñ much more, as you will see. Features in Version Control Systems Universal features: ñ let you save changes ñ browser the history Common features: ñ collaboration ñ branches ñ tags 4 / 45 Features in Version Control Systems Universal features: ñ let you save changes ñ browser the history Common features: ñ collaboration ñ branches ñ tags Not so common features: ñ speed! ñ much more, as you will see. 4 / 45 The Repository The database that holds your history: ñ series of project-wide snapshots ñ called changesets or revisions in Mercurial ñ changesets encapsulate a delta between two snapshots ñ each changeset has a parent changeset Repository 5 / 45 The Working Directory Holds your files: Alice Bob hello.c hello.c Makefile goodbye.c Makefile ñ you edit files in the working directory ñ reflects a changeset (the parent changeset) ñ also called a working copy 6 / 45 Branches A key concept: ñ parallel lines of development ñ used to track releases ñ used to isolate disruptive changes 7 / 45 Branches A key concept: ñ parallel lines of development ñ used to track releases ñ used to isolate disruptive changes time 7 / 45 Branches A key concept: ñ parallel lines of development ñ used to track releases ñ used to isolate disruptive changes 1.0 time 7 / 45 Branches A key concept: ñ parallel lines of development ñ used to track releases ñ used to isolate disruptive changes 1.0 time 7 / 45 Branches A key concept: ñ parallel lines of development ñ used to track releases ñ used to isolate disruptive changes 1.0.1 1.0 time 7 / 45 Branches A key concept: ñ parallel lines of development ñ used to track releases ñ used to isolate disruptive changes 1.0.1 1.0.2 1.0 time 7 / 45 Merging The opposite of branching: ñ combines two branches ñ used to merge back bugfixes ñ used to integrate feature branches 1.0.1 1.0.2 1.0 time 8 / 45 Merging The opposite of branching: ñ combines two branches ñ used to merge back bugfixes ñ used to integrate feature branches 1.0.1 1.0.2 1.0 time 8 / 45 Merging The opposite of branching: ñ combines two branches ñ used to merge back bugfixes ñ used to integrate feature branches 1.0.1 1.0.2 1.0 time 8 / 45 Centralized Revision Control Subversion use a single server: Repository trunk/ branches/ trunk/ hello.c bob/ hello.c Makefile hello.c Makefile Alice Makefile Carla Bob 9 / 45 Distributed Revision Control Mercurial duplicates the history on many servers: Alice Bob Carla 10 / 45 Distributed Revision Control Mercurial duplicates the history on many servers: Alice’s Alice Laptop Bob Carla 10 / 45 Distributed Revision Control Mercurial duplicates the history on many servers: Alice’s Alice Laptop Server Bob Carla 10 / 45 Distributed Revision Control Mercurial duplicates the history on many servers: Alice’s Alice Laptop Server Bob Carla 10 / 45 Revision Control System (RCS) Version control from the 1980s: ñ store changes (date, commit message) ñ browse history 11 / 45 Revision Control System (RCS) Version control from the 1980s: ñ store changes (date, commit message) ñ browse history hello.c: Makefile: 11 / 45 Revision Control System (RCS) Version control from the 1980s: ñ store changes (date, commit message) ñ browse history hello.c: Makefile: 11 / 45 Revision Control System (RCS) Version control from the 1980s: ñ store changes (date, commit message) ñ browse history hello.c: Makefile: 11 / 45 Revision Control System (RCS) Version control from the 1980s: ñ store changes (date, commit message) ñ browse history hello.c: Makefile: 11 / 45 Revision Control System (RCS) Version control from the 1980s: ñ store changes (date, commit message) ñ browse history hello.c: Makefile: 11 / 45 Revision Control System (RCS) Version control from the 1980s: ñ store changes (date, commit message) ñ browse history hello.c: Makefile: 11 / 45 CVS Server Alice Bob hello.c hello.c: hello.c Makefile Makefile: Makefile Concurrent Versions System (CVS) Version control in the 1990s: ñ collaboration over the network ñ several working copies ñ one central repository 12 / 45 Concurrent Versions System (CVS) Version control in the 1990s: ñ collaboration over the network ñ several working copies ñ one central repository CVS Server Alice Bob hello.c hello.c: hello.c Makefile Makefile: Makefile 12 / 45 Concurrent Versions System (CVS) Version control in the 1990s: ñ collaboration over the network ñ several working copies ñ one central repository CVS Server Alice Bob hello.c commit hello.c: hello.c Makefile Makefile: Makefile 12 / 45 Concurrent Versions System (CVS) Version control in the 1990s: ñ collaboration over the network ñ several working copies ñ one central repository CVS Server Alice Bob hello.c hello.c: update hello.c Makefile Makefile: Makefile 12 / 45 So, everything is good? CVS has many limitations: ñ no atomic commits ñ no rename information ñ branches? I hope you have a CVS guru at hand. 13 / 45 Subversion (SVN) Version control from this millennia — “CVS done right”: ñ atomic commits ñ tracks renames ñ supports some operations without network access ñ clean and simple design compared to CVS 14 / 45 Merging in Subversion SVN is a centralized system: Repository hello.c hello.c Makefile Makefile Alice Eve hello.c hello.c Makefile hello.c Makefile Makefile Bob Dan Carla ñ merging takes place in client ñ merging takes place on server(!) 15 / 45 What if you want to abandon a merge? ñ you can revert files with conflicts to their old state ñ but other files may have been updated ñ beware of mixed revisions. SVN Merge in Client When you do svn update, you merge: ñ this can of course result in conflicts ñ you must resolve the merge before you go on ñ might be difficult to handle everything at once 16 / 45 SVN Merge in Client When you do svn update, you merge: ñ this can of course result in conflicts ñ you must resolve the merge before you go on ñ might be difficult to handle everything at once What if you want to abandon a merge? ñ you can revert files with conflicts to their old state ñ but other files may have been updated ñ beware of mixed revisions. 16 / 45 They both have mixed revisions in their working copies: hello.c (r2) hello.c (r1) Makefile (r1) Makefile (r3) Alice Bob Difficult for Carla to reproduce either working copy. Mixed Revisions?! SVN lets you work with an inconsistent working copy: ñ Alice and Bob have revision 1 ñ Alice changes hello.c ! revision 2 ñ Bob changes Makefile ! revision 3 17 / 45 Mixed Revisions?! SVN lets you work with an inconsistent working copy: ñ Alice and Bob have revision 1 ñ Alice changes hello.c ! revision 2 ñ Bob changes Makefile ! revision 3 They both have mixed revisions in their working copies: hello.c (r2) hello.c (r1) Makefile (r1) Makefile (r3) Alice Bob Difficult for Carla to reproduce either working copy. 17 / 45 Server-Side Merges Mixed revisions are a result of allowing server-side merges ñ can we forbid server-side merges? ñ not really — it would ruin branches in SVN 18 / 45 Branches in SVN Subversion knows nothing about branches! ñ but SVN has a cheap copy mechanism ñ used for tags and branches 19 / 45 Branches in SVN Subversion knows nothing about branches! ñ but SVN has a cheap copy mechanism ñ used for tags and branches r10 trunk/ hello.c Makefile branches/ tags/ 19 / 45 Branches in SVN Subversion knows nothing about branches! ñ but SVN has a cheap copy mechanism ñ used for tags and branches r10 r11 trunk/ trunk/ hello.c hello.c Makefile Makefile branches/ branches/ tags/ goodbye/ hello.c Makefile tags/ 19 / 45 Branches in SVN Subversion knows nothing about branches! ñ but SVN has a cheap copy mechanism ñ used for tags and branches r10 r11 r12 trunk/ trunk/ trunk/ hello.c hello.c hello.c Makefile Makefile Makefile branches/ branches/ branches/ tags/ goodbye/ goodbye/ hello.c hello.c Makefile goodbye.c tags/ Makefile tags/ 19 / 45 The bottom line is that Subversion’s merge-tracking feature has an extremely complex internal implementation, and the svn:mergeinfo property is the only window the user has into the machinery. Because the feature is relatively new, a numbers of edge cases and possible unexpected behaviors may pop up. —Version Control with Subversion (Mercurial has robust built-in support for merging branches.) Merging Branches in SVN Branches are only interesting if you can merge them: ñ before SVN 1.5: no built-in support for merging(!) ñ SVN 1.5 and later: tracks info needed for merging 20 / 45 Merging Branches in SVN Branches are only interesting if you can merge them: ñ before SVN 1.5: no built-in support for merging(!) ñ SVN 1.5 and later: tracks info needed for merging The bottom line is that Subversion’s merge-tracking feature has an extremely complex internal implementation, and the svn:mergeinfo property is the only window the user has into the machinery.