Mrrl: h fntv Gd

rn OSllvn

OEIY eiig • Camige • aam • Kö • Seasoo • aiei • okyo bl f Cntnt

rf ...... xv

. A rf tr f vn Cntrl ...... Why Revision Control? Why ? 1 Why Use Revision Control? 1 The Many Names of Revision Control 2 This Book Is a Work in Progress 3 About the Examples in This Book 3 Trends in the Field 3 A Few Advantages of Distributed Revision Control 4 Advantages for Open Source Projects 5 Advantages for Commercial Projects 6 Why Choose Mercurial? 6 Mercurial Compared with Other Tools 7 Subversion 7 8 CVS 9 Commercial Tools 10 Choosing a Revision Control Tool 10 Switching from Another Tool to Mercurial 10 A Short History of Revision Control 11

2. A r f Mrrl: h ...... Installing Mercurial on Your System 13 Windows 13 Mac OS X 13 Linux 13 Solaris 14 Getting Started 14 Built-In Help 14 Working with a Repository 15 Making a Local Copy of a Repository 15 Wht n ptr? 6 6 A r hrh tr Chnt, vn, nd ln t Othr pl n Spf vn 8 Mr tld Infrtn All Abt Cnd Optn 20 Mn nd vn Chn 2 rdn Chn n Chnt 2 Sttn Up Urn 2 Wrtn Ct M 24 Wrtn Gd Ct M 2 Abrtn Ct 26 Adrn Or ndr 26 Shrn Chn 26 lln Chn fr Anthr ptr 26 Updtn th Wrn rtr 28 hn Chn t Anthr ptr 2 flt tn 0 Shrn Chn vr tr 0 Strtn rjt

. A r f Mrrl: Mrn Wr ...... Mrn Str f Wr d Chnt 4 rfrn th Mr Cttn th lt f th Mr Mrn Cnfltn Chn 8 Un Grphl Mr l 8 A Wrd Expl 40 Splfn th llMrCt Sn 42 nn, Cpn, nd Mrn 4

4. hnd th Sn ...... 4 Mrrl trl rd 4 rn th tr f Snl l 4 Mnn rd l 46 rdn Chnt Infrtn 46 ltnhp tn vn 46 Sf, Effnt Str 4 Effnt Str 4 Sf Oprtn 4 t trvl 48 Idntftn nd Strn Intrt 48

v I ae o Coes Revision History, Branching, and Merging 49 The Working Directory 50 What Happens When You Commit 50 Creating a New Head 53 Merging Changes 54 Merging and Renames 56 Other Interesting Design Features 56 Clever Compression 56 Read/Write Ordering and Atomicity 57 Concurrent Access 57 Avoiding Seeks 58 Other Contents of the Dirstate 58

. Mrrl n l U ...... 6 Telling Mercurial Which Files to Track 61 Explicit Versus Implicit File Naming 62 Mercurial Tracks Files, Not Directories 62 How to Stop Tracking a File 63 Removing a File Does Not Affect Its History 63 Missing Files 64 Useful Shorthand: Adding and Removing Files in One Step 64 Copying Files 65 The Results of Copying During a Merge 65 Why Should Changes Follow Copies? 66 How to Make Changes Not Follow a Copy 67 Behavior of the hg copy Command 67 Renaming Files 68 Renaming Files and Merging Changes 69 Divergent Renames and Merging 69 Convergent Renames and Merging 70 Other Name-Related Corner Cases 70 Recovering from Mistakes 71 Dealing with Tricky Merges 71 File Resolution States 73 Resolving a File Merge 73 More Useful Diffs 73 Which Files to Manage, and Which to Avoid 74 Backups and Mirroring 76

6. Cllbrtn th Othr pl ...... Mercurial's Web Interface 77 Collaboration Models 78 Factors to Keep in Mind 78

fbl f Cntnt I v Informal Anarchy 79 A Single Central Repository 79 A Hosted Central Repository 80 Working with Multiple Branches 80 Feature Branches 82 The Release Train 83 The Linux Kernel Model 83 Pull-Only Versus Shared-Push Collaboration 84 Where Collaboration Meets Branch Management 85 The Technical Side of Sharing 85 Informal Sharing with hg serve 85 A Few Things to Keep in Mind 86 Using the Secure Shell Protocol 86 How to Read and Write ssh URLs 86 Finding an ssh Client for Your System 87 Generating a Key Pair 87 Using an Authentication Agent 88 Configuring the Server Side Properly 88 Using Compression with ssh 90 Serving Over HTTP Using CGI 91 Web Server Configuration Checklist 92 Basic CGI Configuration 92 Sharing Multiple Repositories with One CGI Script 94 Downloading Source Archives 96 Web Configuration Options 96 System-Wide Configuration 99 Making Mercurial More Trusting 99

. ln nd ttrn Mthn ...... 0 Simple File Naming 101 Running Commands Without Any Filenames 101 Telling You What's Going On 103 Using Patterns to Identify Files 103 Shell-Style Glob Patterns 104 Regular Expression Matching with Re Patterns 105 Filtering Files 105 Permanently Ignoring Unwanted Files and Directories 106 Gase Sensitivity 107 Safe, Portable Repository Storage 107 Detecting Gase Conflicts 107 Fixing a Gase Conflict 108

v I aeoCoes 8. Mnn l nd rnh vlpnt ...... 0 Giving a Persistent Name to a Revision 109 Handling Tag Conflicts During a Merge 112 Tags and Cloning 112 When Permanent Tags Are Too Much 112 The Flow of Changes: Big Picture Versus Little Picture 113 Managing Big-Picture Branches in Repositories 113 Don't Repeat Yourself: Merging Across Branches 114 Naming Branches Within One Repository 115 Dealing with Multiple Named Branches in a Repository 117 Branch Names and Merging 118 Branch Naming Is Generally Useful 119

. ndn nd xn Mt ...... 2 Erasing Local History 121 The Accidental Commit 121 Rolling Back a Transaction 121 The Erroneous Pull 122 Rolling Back Is Useless Once You've Pushed 123 You Can Only Roll Back Once 123 Reverting the Mistaken Change 123 File Management Errors 125 Dealing with Committed Changes 126 Backing Out a Changeset 126 Backing Out the Tip Changeset 126 Backing Out a Non-Tip Change 127 Gaining More Control of the Backout Process 129 Why hg backout Works As lt Does 131 Changes That Should Never Have Been 132 Backing Out a Merge 133 Protect Yourself from "Escaped" Changes 134 What to Do About Sensitive Changes That Escape 135 Finding the Source of a Bug 137 Using the hg bisect Command 139 Cleaning Up After Your Search 142 Tips for Finding Bugs Effectively 142 Give Consistent Input 142 Automate As Much As Possible 142 Check Your Results 143 Beware Interference Between Bugs 143 Bracket Your Search Lazily 143

blfCntnt I x 0. ndln ptr Evnt th ...... 4 An Ovrv f n Mrrl 4 nd Srt 46 Ar n th Yr rvl 46 t rpt 4 Cn Ovrrddn 4 Enrn ht Crtl Ar n 4 A Shrt trl n Un 48 rfrn Mltpl Atn r Evnt 48 Cntrlln Whthr n Atvt Cn rd 4 Wrtn Yr On 4 Chn Yr Shld n 0 rtr 0 trn l nd Atvt Cntrl 0 Wrtn n Extrnl lln Mrrl t U n Inr Wrtn n Inr S Expl 2 Wrtn Mnnfl Ct M 2 Chn fr rln Whtp 2 ndld 4 l—A Cntrl fr rt f ptr 4 bzll—Intrtn th zll 6 ntf—Snd El tftn 60 Infrtn fr Wrtr f 62 Inr Extn 62 Extrnl Extn 62 ndn Ot Whr Chnt C r 6 frn 64 hnrp—Aftr t Chnt Addd 64 t—Aftr Chnt I Crtd 64 nn—Aftr On t Chnt I Addd 6 tn—Aftr Chnt Ar rptd 6 prhnrpfr Strtn t Add t Chnt 66 prt—fr Strtn t Ct Chnt 66 prtn—fr Strtn t rpt Chnt 6 prt—fr n Chnt 6 prtxnhnrp—fr Cpltn Addtn f t Chn t 6 prtxnt—fr Cpltn Ct f Chnt 68 prpdt—fr Updtn r Mrn Wrn rtr 6 t—Aftr n Chnt 6 pdt—Aftr Updtn r Mrn Wrn rtr 6

x I bl f Cntnt . Ctzn th Otpt f Mrrl ...... Using Precanned Output Styles 171 Setting a Default Style 172 Commands That Support Styles and Templates 172 The Basics of Templating 173 Common Template Keywords 173 Escape Sequences 175 Filtering Keywords to Change Their Results 175 Combining Filters 178 From Templates to Styles 178 The Simplest of Style Files 178 Style File Syntax 179 Style Files by Example 179 Identifying Mistakes in Style Files 179 Uniquely Identifying a Repository 180 Listing Files on Multiple Lines 180 Mimicking Subversion's Output 181

2. Mnn Chn th Mrrl Q ...... 8 The Management Problem 183 The Prehistory of Mercurial Queues 184 A Patchwork Quilt 184 From Patchwork Quilt to Mercurial Queues 185 The Huge Advantage of MQ 185 Understanding Patches 186 Getting Started with Mercurial Queues 187 Creating a New Patch 187 Refreshing a Patch 188 Stacking and Tracking Patches 189 Manipulating the Patch Stack 190 Pushing and Popping Many Patches 191 Safety Checks, and Overriding Them 192 Working on Several Patches at Once 192 More About Patches 192 The Strip Count 192 Strategies for Applying a Patch 193 Some Quirks of Patch Representation 194 Beware the Fuzz 194 Handling Rejection 195 More on Patch Management 195 Deleting Unwanted Patches 196 Converting to and from Permanent Revisions 196 Getting the Best Performance Out of MQ 197

bl f Cntnt I x Updating Your Patches When the Underlying Code Changes 197 Identifying Patches 198 Useful Things to Know About 200 Managing Patches in a Repository 200 MQ Support for Patch Repositories 201 A Few Things to Watch Out For 201 Third-Party Tools for Working with Patches 202 Good Ways to Work with Patches 202 MQ Cookbook 203 Managing "Trivial" Patches 203 Combining Entire Patches 205 Merging Part of One Patch into Another 205 Differences Between Quilt and MQ 206

. Advnd U f Mrrl Q ...... 20 The Problem of Many Targets 207 Tempting Approaches That Don't Work Well 208 Conditionally Applying Patches with Guards 208 Controlling the Guards on a Patch 209 Selecting the Guards to Use 210 MQ's Rules for Applying Patches 211 Trimming the Work Environment 211 Dividing Up the Series File 211 Maintaining the Patch Series 212 The Art of Writing Backport Patches 213 Useful Tips for Developing with MQ 213 Organizing Patches in Directories 213 Viewing the History of a Patch 214

4. Addn ntnlt th Extnn ...... 2 Improve Performance with the inotify Extension 217 Flexible Diff Support with the extdiff Extension 220 Defining Command Aliases 222 Cherry-Picking Changes with the transplant Extension 222 Sending Changes via Email with the patchbomb Extension 223 Changing the Behavior of Patchbombs 224

A. Mrtn t Mrrl ...... 22

. Mrrl Q frn ...... 2

C. Intlln Mrrl fr Sr ...... 24

_____ x I bl f Cntnt . Opn bltn n ...... 24

Indx ...... 24

ae o Coes iii