Mercurial: The Definitive Guide

Compiled from ed4aa276463e (2010-02-21)

Bryan O'Sullivan


Table of Contents

Preface
1. Technical storytelling
2. Thank you for supporting Mercurial
3. Acknowledgments
4. Conventions Used in This Book
5. Using Code Examples
6. Safari® Books Online
7. How to Contact Us
1. How did we get here?
1.1. Why revision control? Why Mercurial?
1.1.1. Why use revision control?
1.1.2. The many names of revision control
1.2. About the examples in this book
1.3. Trends in the field
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
1.8. A short history of revision control
2. A tour of Mercurial: the basics
2.1. Installing Mercurial on your system
2.1.1. Windows
2.1.2. Mac OS X
2.1.3. Linux
2.1.4. Solaris
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. Default locations
2.8.5. Sharing changes over a network
2.9. Starting a new project
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
3.4. Renaming, copying, and merging
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 changes
4.4.4. Merging and renames
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. 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. Behavior 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
5.6. Dealing with tricky merges
5.6.1. File resolution states
5.6.2. Resolving a file merge
5.7. More useful diffs
5.8. Which files to manage, and which to avoid
5.9. Backups and mirroring
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. A hosted central repository
6.2.5. Working with multiple branches
6.2.6. Feature branches
6.2.7. The release train
6.2.8. The Linux kernel model
6.2.9. Pull-only versus shared-push collaboration
6.2.10. 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
6.7. System-wide configuration
6.7.1. Making Mercurial more trusting
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. Permanently 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 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. Backing out a merge
9.4.2. Protect yourself from escaped changes
9.4.3. What to do about sensitive changes that escape
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. A short tutorial on using hooks
10.3.1. Performing multiple actions per event
10.3.2. Controlling whether an activity can proceed
10.4. Writing your own hooks
10.4.1. Choosing how your hook should run
10.4.2. Hook parameters
10.4.3. Hook return values and activity control
10.4.4. Writing an external hook
10.4.5. Telling Mercurial to use an in-process hook
10.4.6. Writing an in-process hook
10.5. Some hook examples
10.5.1. Writing meaningful commit messages
10.5.2. Checking for trailing whitespace
10.6. Bundled hooks
10.6.1. acl—access control for parts of a repository
10.6.2. bugzilla—integration with Bugzilla
10.6.3. notify—send email notifications
10.7. Information for writers of hooks
10.7.1. In-process hook execution
10.7.2. External hook execution
10.7.3. Finding out where changesets come from
10.8. Hook reference
10.8.1. changegroup—after remote changesets added
10.8.2. commit—after a new changeset is created
10.8.3. incoming—after one remote changeset is added
10.8.4. outgoing—after changesets are propagated
10.8.5. prechangegroup—before starting to add remote changesets
10.8.6. precommit—before starting to commit a changeset
10.8.7. preoutgoing—before starting to propagate changesets
10.8.8. pretag—before tagging a changeset
10.8.9. pretxnchangegroup—before completing addition of remote changesets
10.8.10. pretxncommit—before completing commit of new changeset
10.8.11. preupdate—before updating or merging working directory
10.8.12. tag—after tagging a changeset
10.8.13. update—after updating or merging working directory
11. Customizing the output of Mercurial
11.1. Using precanned output styles
11.1.1. Setting a default style
11.2. Commands that support styles and templates
11.3. The basics of templating
11.4. Common template keywords
11.5. Escape sequences
11.6. Filtering keywords to change their results
11.6.1. Combining filters
11.7. From templates to styles
11.7.1. The simplest of style files
11.7.2. Style file syntax
11.8. Style files by example
11.8.1. Identifying mistakes in style files
11.8.2. Uniquely identifying a repository
11.8.3. Listing files on multiple lines
11.8.4. Mimicking 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. More on patch management
12.7.1. Deleting unwanted patches
12.7.2. Converting to and from permanent revisions
12.8. Getting the best performance out of MQ
12.9. Updating your patches when the underlying code changes
12.10. Identifying patches
12.11. Useful things to know about
12.12. Managing patches in a repository
12.12.1. MQ support for patch repositories
12.12.2. A few things to watch out for
12.13. Third party tools for working with patches
12.14. Good ways to work with patches
12.15. MQ cookbook
12.15.1. Manage trivial patches
12.15.2. Combining entire patches
12.15.3. Merging part of one patch into another
12.16. 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 behavior of patchbombs
A. Migrating to Mercurial
A.1. Importing history from another system
A.1.1. Converting multiple branches
A.1.2. Mapping user names
A.1.3. Tidying up the tree
A.1.4. Improving Subversion conversion performance
A.2. Migrating from Subversion
A.2.1. Philosophical differences
A.2.2. Quick reference
A.3. Useful tips for newcomers
B. Mercurial Queues reference
B.1. MQ command reference
B.1.1. qapplied—print applied patches
B.1.2. qcommit—commit changes in the queue repository
B.1.3. qdelete—delete a patch from the series file
B.1.4. qdiff—print a diff of the topmost applied patch
B.1.5. qfold—move applied patches into repository history
B.1.6. qfold—merge (fold) several patches into one
B.1.7. qheader—display the header/description of a patch
B.1.8. qimport—import a third-party patch into the queue
B.1.9. qinit—prepare a repository to work with MQ
B.1.10. qnew—create a new patch
B.1.11. qnext—print the name of the next patch
B.1.12. qpop—pop patches off the stack
B.1.13. qprev—print the name of the previous patch
B.1.14. qpush—push patches onto the stack
B.1.15. qrefresh—update the topmost applied patch
B.1.16. qrename—rename a patch
B.1.17. qseries—print the entire patch series
B.1.18. qtop—print the name of the current patch
B.1.19. qunapplied—print patches not yet applied
B.1.20. 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

List of Figures

2.1. Graphical history of the hello repository
3.1. Divergent recent histories of the my-hello and my-new-hello repositories
3.2. Repository contents after pulling from my-hello into my-new-hello
3.3. Working directory and repository during merge, and following commit
3.4. Conflicting changes to a document
3.5. Using kdiff3 to merge versions of a file
4.1. Relationships between files in working directory and filelogs in repository
4.2. Metadata relationships
4.3. Snapshot of a revlog, with incremental deltas
4.4. The conceptual structure of a revlog
4.5. The working directory can have two parents
4.6. The working directory gains new parents after a commit
4.7. The working directory, updated to an older changeset
4.8. After a commit made while synced to an older changeset
4.9. Merging two heads
6.1. Feature branches
9.1. Backing out a change using the hg backout command
9.2. Automated backout of a non-tip change using the hg backout command
9.3. Backing out a change using the hg backout command
9.4. Manually merging a backout change
9.5. A bad merge
9.6. Backing out the merge, favoring one parent
9.7. Backing out the merge, favoring the other parent
9.8. Merging the backouts
9.9. Merging the backouts
12.1. Applied and unapplied patches in the MQ patch stack

List of Tables

A.1. Subversion commands and Mercurial equivalents