Contents

Contents
Preface
 0.1 This book is a work in progress
 0.2 About the examples in this book
 0.3 Colophon—this book is Free
1 Introduction
 1.1 About revision control
  1.1.1 Why use revision control?
  1.1.2 The many names of revision control
 1.2 A short history of revision control
 1.3 Trends in revision control
 1.4 A few of the advantages of distributed revision control
  1.4.1 Advantages for open source projects
  1.4.2 Advantages for commercial projects
 1.5 Why choose Mercurial?
 1.6 Mercurial compared with other tools
  1.6.1 Subversion
  1.6.2 Git
  1.6.3 CVS
  1.6.4 Commercial tools
  1.6.5 Choosing a revision control tool
 1.7 Switching from another tool to Mercurial
2 A tour of Mercurial: the basics
 2.1 Installing Mercurial on your system
  2.1.1 Linux
  2.1.2 Solaris
  2.1.3 Mac OS X
  2.1.4 Windows
 2.2 Getting started
  2.2.1 Built-in help
 2.3 Working with a repository
  2.3.1 Making a local copy of a repository
  2.3.2 What’s in a repository?
 2.4 A tour through history
  2.4.1 Changesets, revisions, and talking to other people
  2.4.2 Viewing specific revisions
  2.4.3 More detailed information
 2.5 All about command options
 2.6 Making and reviewing changes
 2.7 Recording changes in a new changeset
  2.7.1 Setting up a username
  2.7.2 Writing a commit message
  2.7.3 Writing a good commit message
  2.7.4 Aborting a commit
  2.7.5 Admiring our new handiwork
 2.8 Sharing changes
  2.8.1 Pulling changes from another repository
  2.8.2 Updating the working directory
  2.8.3 Pushing changes to another repository
  2.8.4 Sharing changes over a network
3 A tour of Mercurial: merging work
 3.1 Merging streams of work
  3.1.1 Head changesets
  3.1.2 Performing the merge
  3.1.3 Committing the results of the merge
 3.2 Merging conflicting changes
  3.2.1 Using a graphical merge tool
  3.2.2 A worked example
 3.3 Simplifying the pull-merge-commit sequence
4 Behind the scenes
 4.1 Mercurial’s historical record
  4.1.1 Tracking the history of a single file
  4.1.2 Managing tracked files
  4.1.3 Recording changeset information
  4.1.4 Relationships between revisions
 4.2 Safe, efficient storage
  4.2.1 Efficient storage
  4.2.2 Safe operation
  4.2.3 Fast retrieval
  4.2.4 Identification and strong integrity
 4.3 Revision history, branching, and merging
 4.4 The working directory
  4.4.1 What happens when you commit
  4.4.2 Creating a new head
  4.4.3 Merging heads
 4.5 Other interesting design features
  4.5.1 Clever compression
  4.5.2 Read/write ordering and atomicity
  4.5.3 Concurrent access
  4.5.4 Avoiding seeks
  4.5.5 Other contents of the dirstate
5 Mercurial in daily use
 5.1 Telling Mercurial which files to track
  5.1.1 Explicit versus implicit file naming
  5.1.2 Aside: Mercurial tracks files, not directories
 5.2 How to stop tracking a file
  5.2.1 Removing a file does not affect its history
  5.2.2 Missing files
  5.2.3 Aside: why tell Mercurial explicitly to remove a file?
  5.2.4 Useful shorthand—adding and removing files in one step
 5.3 Copying files
  5.3.1 The results of copying during a merge
  5.3.2 Why should changes follow copies?
  5.3.3 How to make changes not follow a copy
  5.3.4 Behaviour of the “hg copy” command
 5.4 Renaming files
  5.4.1 Renaming files and merging changes
  5.4.2 Divergent renames and merging
  5.4.3 Convergent renames and merging
  5.4.4 Other name-related corner cases
 5.5 Recovering from mistakes
6 Collaborating with other people
 6.1 Mercurial’s web interface
 6.2 Collaboration models
  6.2.1 Factors to keep in mind
  6.2.2 Informal anarchy
  6.2.3 A single central repository
  6.2.4 Working with multiple branches
  6.2.5 Feature branches
  6.2.6 The release train
  6.2.7 The Linux kernel model
  6.2.8 Pull-only versus shared-push collaboration
  6.2.9 Where collaboration meets branch management
 6.3 The technical side of sharing
 6.4 Informal sharing with “hg serve
  6.4.1 A few things to keep in mind
 6.5 Using the Secure Shell (ssh) protocol
  6.5.1 How to read and write ssh URLs
  6.5.2 Finding an ssh client for your system
  6.5.3 Generating a key pair
  6.5.4 Using an authentication agent
  6.5.5 Configuring the server side properly
  6.5.6 Using compression with ssh
 6.6 Serving over HTTP using CGI
  6.6.1 Web server configuration checklist
  6.6.2 Basic CGI configuration
  6.6.3 Sharing multiple repositories with one CGI script
  6.6.4 Downloading source archives
  6.6.5 Web configuration options
7 File names and pattern matching
 7.1 Simple file naming
 7.2 Running commands without any file names
 7.3 Telling you what’s going on
 7.4 Using patterns to identify files
  7.4.1 Shell-style glob patterns
  7.4.2 Regular expression matching with re patterns
 7.5 Filtering files
 7.6 Ignoring unwanted files and directories
 7.7 Case sensitivity
  7.7.1 Safe, portable repository storage
  7.7.2 Detecting case conflicts
  7.7.3 Fixing a case conflict
8 Managing releases and branchy development
 8.1 Giving a persistent name to a revision
  8.1.1 Handling tag conflicts during a merge
  8.1.2 Tags and cloning
  8.1.3 When permanent tags are too much
 8.2 The flow of changes—big picture vs. little
 8.3 Managing big-picture branches in repositories
 8.4 Don’t repeat yourself: merging across branches
 8.5 Naming branches within one repository
 8.6 Dealing with multiple named branches in a repository
 8.7 Branch names and merging
 8.8 Branch naming is generally useful
9 Finding and fixing your mistakes
 9.1 Erasing local history
  9.1.1 The accidental commit
  9.1.2 Rolling back a transaction
  9.1.3 The erroneous pull
  9.1.4 Rolling back is useless once you’ve pushed
  9.1.5 You can only roll back once
 9.2 Reverting the mistaken change
  9.2.1 File management errors
 9.3 Dealing with committed changes
  9.3.1 Backing out a changeset
  9.3.2 Backing out the tip changeset
  9.3.3 Backing out a non-tip change
  9.3.4 Gaining more control of the backout process
  9.3.5 Why “hg backout” works as it does
 9.4 Changes that should never have been
  9.4.1 Protect yourself from “escaped” changes
 9.5 Finding the source of a bug
  9.5.1 Using the “hg bisect” command
  9.5.2 Cleaning up after your search
 9.6 Tips for finding bugs effectively
  9.6.1 Give consistent input
  9.6.2 Automate as much as possible
  9.6.3 Check your results
  9.6.4 Beware interference between bugs
  9.6.5 Bracket your search lazily
10 Handling repository events with hooks
 10.1 An overview of hooks in Mercurial
 10.2 Hooks and security
  10.2.1 Hooks are run with your privileges
  10.2.2 Hooks do not propagate
  10.2.3 Hooks can be overridden
  10.2.4 Ensuring that critical hooks are run
 10.3 Care with pretxn hooks in a shared-access repository
  10.3.1 The problem illustrated
 10.4 A short tutorial on using hooks
  10.4.1 Performing multiple actions per event
  10.4.2 Controlling whether an activity can proceed
 10.5 Writing your own hooks
  10.5.1 Choosing how your hook should run
  10.5.2 Hook parameters
  10.5.3 Hook return values and activity control
  10.5.4 Writing an external hook
  10.5.5 Telling Mercurial to use an in-process hook
  10.5.6 Writing an in-process hook
 10.6 Some hook examples
  10.6.1 Writing meaningful commit messages
  10.6.2 Checking for trailing whitespace
 10.7 Bundled hooks
  10.7.1 acl—access control for parts of a repository
  10.7.2 bugzilla—integration with Bugzilla
  10.7.3 notify—send email notifications
 10.8 Information for writers of hooks
  10.8.1 In-process hook execution
  10.8.2 External hook execution
  10.8.3 Finding out where changesets come from
 10.9 Hook reference
  10.9.1 changegroup—after remote changesets added
  10.9.2 commit—after a new changeset is created
  10.9.3 incoming—after one remote changeset is added
  10.9.4 outgoing—after changesets are propagated
  10.9.5 prechangegroup—before starting to add remote changesets
  10.9.6 precommit—before starting to commit a changeset
  10.9.7 preoutgoing—before starting to propagate changesets
  10.9.8 pretag—before tagging a changeset
  10.9.9 pretxnchangegroup—before completing addition of remote changesets
  10.9.10 pretxncommit—before completing commit of new changeset
  10.9.11 preupdate—before updating or merging working directory
  10.9.12 tag—after tagging a changeset
  10.9.13 update—after updating or merging working directory
11 Customising the output of Mercurial
 .1Using precanned output styles
  .1.1Setting a default style
 .2Commands that support styles and templates
 .3The basics of templating
 .4Common template keywords
 .5Escape sequences
 .6Filtering keywords to change their results
  .6.1Combining filters
 .7From templates to styles
  .7.1The simplest of style files
  .7.2Style file syntax
 .8Style files by example
  .8.1Identifying mistakes in style files
  .8.2Uniquely identifying a repository
  .8.3Mimicking Subversion’s output
12 Managing change with Mercurial Queues
 12.1 The patch management problem
 12.2 The prehistory of Mercurial Queues
  12.2.1 A patchwork quilt
  12.2.2 From patchwork quilt to Mercurial Queues
 12.3 The huge advantage of MQ
 12.4 Understanding patches
 12.5 Getting started with Mercurial Queues
  12.5.1 Creating a new patch
  12.5.2 Refreshing a patch
  12.5.3 Stacking and tracking patches
  12.5.4 Manipulating the patch stack
  12.5.5 Pushing and popping many patches
  12.5.6 Safety checks, and overriding them
  12.5.7 Working on several patches at once
 12.6 More about patches
  12.6.1 The strip count
  12.6.2 Strategies for applying a patch
  12.6.3 Some quirks of patch representation
  12.6.4 Beware the fuzz
  12.6.5 Handling rejection
 12.7 Getting the best performance out of MQ
 12.8 Updating your patches when the underlying code changes
 12.9 Identifying patches
 12.10 Useful things to know about
 12.11 Managing patches in a repository
  12.11.1 MQ support for patch repositories
  12.11.2 A few things to watch out for
 12.12 Third party tools for working with patches
 12.13 Good ways to work with patches
 12.14 MQ cookbook
  12.14.1 Manage “trivial” patches
  12.14.2 Combining entire patches
  12.14.3 Merging part of one patch into another
 12.15 Differences between quilt and MQ
13 Advanced uses of Mercurial Queues
 13.1 The problem of many targets
  13.1.1 Tempting approaches that don’t work well
 13.2 Conditionally applying patches with guards
 13.3 Controlling the guards on a patch
 13.4 Selecting the guards to use
 13.5 MQ’s rules for applying patches
 13.6 Trimming the work environment
 13.7 Dividing up the series file
 13.8 Maintaining the patch series
  13.8.1 The art of writing backport patches
 13.9 Useful tips for developing with MQ
  13.9.1 Organising patches in directories
  13.9.2 Viewing the history of a patch
14 Adding functionality with extensions
 14.1 Improve performance with the inotify extension
 14.2 Flexible diff support with the extdiff extension
  14.2.1 Defining command aliases
 14.3 Cherrypicking changes with the transplant extension
 14.4 Send changes via email with the patchbomb extension
  14.4.1 Changing the behaviour of patchbombs
A Command reference
 A.1 hg add”—add files at the next commit
 A.2 hg diff”—print changes in history or working directory
  A.2.1 Options
 A.3 hg version”—print version and copyright information
  A.3.1 Tips and tricks
B Mercurial Queues reference
 B.1 MQ command reference
  B.1.1 hg qapplied”—print applied patches
  B.1.2 hg qcommit”—commit changes in the queue repository
  B.1.3 hg qdelete”—delete a patch from the series file
  B.1.4 hg qdiff”—print a diff of the topmost applied patch
  B.1.5 hg qfold”—merge (“fold”) several patches into one
  B.1.6 hg qheader”—display the header/description of a patch
  B.1.7 hg qimport”—import a third-party patch into the queue
  B.1.8 hg qinit”—prepare a repository to work with MQ
  B.1.9 hg qnew”—create a new patch
  B.1.10 hg qnext”—print the name of the next patch
  B.1.11 hg qpop”—pop patches off the stack
  B.1.12 hg qprev”—print the name of the previous patch
  B.1.13 hg qpush”—push patches onto the stack
  B.1.14 hg qrefresh”—update the topmost applied patch
  B.1.15 hg qrename”—rename a patch
  B.1.16 hg qrestore”—restore saved queue state
  B.1.17 hg qsave”—save current queue state
  B.1.18 hg qseries”—print the entire patch series
  B.1.19 hg qtop”—print the name of the current patch
  B.1.20 hg qunapplied”—print patches not yet applied
  B.1.21 hg strip”—remove a revision and descendants
 B.2 MQ file reference
  B.2.1 The series file
  B.2.2 The status file
C Installing Mercurial from source
 C.1 On a Unix-like system
 C.2 On Windows
D Open Publication License
 D.1 Requirements on both unmodified and modified versions
 D.2 Copyright
 D.3 Scope of license
 D.4 Requirements on modified works
 D.5 Good-practice recommendations
 D.6 License options
Bibliography
Index