annotate en/undo.tex @ 131:153efeaa8f57

Fix stupid build bugs.
author Bryan O'Sullivan <bos@serpentine.com>
date Thu, 28 Dec 2006 14:10:23 -0800
parents 26b7a4e943aa
children 9bba958be4c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
1 \chapter{Finding and fixing your mistakes}
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
2 \label{chap:undo}
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
3
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
4 To err might be human, but to really handle the consequences well
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
5 takes a top-notch revision control system. In this chapter, we'll
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
6 discuss some of the techniques you can use when you find that a
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
7 problem has crept into your project. Mercurial has some highly
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
8 capable features that will help you to isolate the sources of
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
9 problems, and to handle them appropriately.
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
10
122
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
11 \section{Erasing local history}
121
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
12
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
13 \subsection{The accidental commit}
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
14
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
15 I have the occasional but persistent problem of typing rather more
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
16 quickly than I can think, which sometimes results in me committing a
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
17 changeset that is either incomplete or plain wrong. In my case, the
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
18 usual kind of incomplete changeset is one in which I've created a new
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
19 source file, but forgotten to \hgcmd{add} it. A ``plain wrong''
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
20 changeset is not as common, but no less annoying.
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
21
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
22 \subsection{Rolling back a transaction}
126
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
23 \label{sec:undo:rollback}
121
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
24
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
25 In section~\ref{sec:concepts:txn}, I mentioned that Mercurial treats
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
26 each modification of a repository as a \emph{transaction}. Every time
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
27 you commit a changeset or pull changes from another repository,
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
28 Mercurial remembers what you did. You can undo, or \emph{roll back},
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
29 exactly one of these actions using the \hgcmd{rollback} command.
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
30
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
31 Here's a mistake that I often find myself making: committing a change
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
32 in which I've created a new file, but forgotten to \hgcmd{add} it.
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
33 \interaction{rollback.commit}
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
34 Looking at the output of \hgcmd{status} after the commit immediately
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
35 confirms the error.
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
36 \interaction{rollback.status}
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
37 The commit captured the changes to the file \filename{a}, but not the
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
38 new file \filename{b}. If I were to push this changeset to a
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
39 repository that I shared with a colleague, the chances are high that
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
40 something in \filename{a} would refer to \filename{b}, which would not
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
41 be present in their repository when they pulled my changes. I would
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
42 thus become the object of some indignation.
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
43
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
44 However, luck is with me---I've caught my error before I pushed the
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
45 changeset. I use the \hgcmd{rollback} command, and Mercurial makes
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
46 that last changeset vanish.
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
47 \interaction{rollback.rollback}
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
48 Notice that the changeset is no longer present in the repository's
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
49 history, and the working directory once again thinks that the file
122
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
50 \filename{a} is modified. The commit and rollback have left the
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
51 working directory exactly as it was prior to the commit; the changeset
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
52 has been completely erased. I can now safely \hgcmd{add} the file
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
53 \filename{b}, and rerun my commit.
121
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
54 \interaction{rollback.add}
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
55
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
56 \subsection{The erroneous pull}
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
57
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
58 It's common practice with Mercurial to maintain separate development
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
59 branches of a project in different repositories. Your development
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
60 team might have one shared repository for your project's ``0.9''
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
61 release, and another, containing different changes, for the ``1.0''
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
62 release.
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
63
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
64 Given this, you can imagine that the consequences could be messy if
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
65 you had a local ``0.9'' repository, and accidentally pulled changes
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
66 from the shared ``1.0'' repository into it. At worst, you could be
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
67 paying insufficient attention, and push those changes into the shared
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
68 ``0.9'' tree, confusing your entire team (but don't worry, we'll
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
69 return to this horror scenario later). However, it's more likely that
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
70 you'll notice immediately, because Mercurial will display the URL it's
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
71 pulling from, or you will see it pull a suspiciously large number of
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
72 changes into the repository.
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
73
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
74 The \hgcmd{rollback} command will work nicely to expunge all of the
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
75 changesets that you just pulled. Mercurial groups all changes from
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
76 one \hgcmd{pull} into a single transaction, so one \hgcmd{rollback} is
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
77 all you need to undo this mistake.
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
78
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
79 \subsection{Rolling back is useless once you've pushed}
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
80
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
81 The value of the \hgcmd{rollback} command drops to zero once you've
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
82 pushed your changes to another repository. Rolling back a change
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
83 makes it disappear entirely, but \emph{only} in the repository in
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
84 which you perform the \hgcmd{rollback}. Because a rollback eliminates
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
85 history, there's no way for the disappearance of a change to propagate
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
86 between repositories.
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
87
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
88 If you've pushed a change to another repository---particularly if it's
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
89 a shared repository---it has essentially ``escaped into the wild,''
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
90 and you'll have to recover from your mistake in a different way. What
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
91 will happen if you push a changeset somewhere, then roll it back, then
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
92 pull from the repository you pushed to, is that the changeset will
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
93 reappear in your repository.
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
94
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
95 (If you absolutely know for sure that the change you want to roll back
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
96 is the most recent change in the repository that you pushed to,
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
97 \emph{and} you know that nobody else could have pulled it from that
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
98 repository, you can roll back the changeset there, too, but you really
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
99 should really not rely on this working reliably. If you do this,
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
100 sooner or later a change really will make it into a repository that
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
101 you don't directly control (or have forgotten about), and come back to
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
102 bite you.)
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
103
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
104 \subsection{You can only roll back once}
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
105
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
106 Mercurial stores exactly one transaction in its transaction log; that
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
107 transaction is the most recent one that occurred in the repository.
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
108 This means that you can only roll back one transaction. If you expect
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
109 to be able to roll back one transaction, then its predecessor, this is
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
110 not the behaviour you will get.
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
111 \interaction{rollback.twice}
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
112 Once you've rolled back one transaction in a repository, you can't
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
113 roll back again in that repository until you perform another commit or
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
114 pull.
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
115
122
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
116 \section{Reverting the mistaken change}
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
117
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
118 If you make a modification to a file, and decide that you really
124
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
119 didn't want to change the file at all, and you haven't yet committed
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
120 your changes, the \hgcmd{revert} command is the one you'll need. It
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
121 looks at the changeset that's the parent of the working directory, and
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
122 restores the contents of the file to their state as of that changeset.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
123 (That's a long-winded way of saying that, in the normal case, it
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
124 undoes your modifications.)
122
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
125
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
126 Let's illustrate how the \hgcmd{revert} command works with yet another
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
127 small example. We'll begin by modifying a file that Mercurial is
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
128 already tracking.
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
129 \interaction{daily.revert.modify}
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
130 If we don't want that change, we can simply \hgcmd{revert} the file.
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
131 \interaction{daily.revert.unmodify}
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
132 The \hgcmd{revert} command provides us with an extra degree of safety
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
133 by saving our modified file with a \filename{.orig} extension.
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
134 \interaction{daily.revert.status}
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
135
124
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
136 Here is a summary of the cases that the \hgcmd{revert} command can
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
137 deal with. We will describe each of these in more detail in the
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
138 section that follows.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
139 \begin{itemize}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
140 \item If you modify a file, it will restore the file to its unmodified
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
141 state.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
142 \item If you \hgcmd{add} a file, it will undo the ``added'' state of
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
143 the file, but leave the file itself untouched.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
144 \item If you delete a file without telling Mercurial, it will restore
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
145 the file to its unmodified contents.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
146 \item If you use the \hgcmd{remove} command to remove a file, it will
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
147 undo the ``removed'' state of the file, and restore the file to its
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
148 unmodified contents.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
149 \end{itemize}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
150
122
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
151 \subsection{File management errors}
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
152 \label{sec:undo:mgmt}
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
153
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
154 The \hgcmd{revert} command is useful for more than just modified
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
155 files. It lets you reverse the results of all of Mercurial's file
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
156 management commands---\hgcmd{add}, \hgcmd{remove}, and so on.
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
157
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
158 If you \hgcmd{add} a file, then decide that in fact you don't want
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
159 Mercurial to track it, use \hgcmd{revert} to undo the add. Don't
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
160 worry; Mercurial will not modify the file in any way. It will just
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
161 ``unmark'' the file.
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
162 \interaction{daily.revert.add}
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
163
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
164 Similarly, if you ask Mercurial to \hgcmd{remove} a file, you can use
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
165 \hgcmd{revert} to restore it to the contents it had as of the parent
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
166 of the working directory.
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
167 \interaction{daily.revert.remove}
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
168 This works just as well for a file that you deleted by hand, without
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
169 telling Mercurial (recall that in Mercurial terminology, this kind of
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
170 file is called ``missing'').
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
171 \interaction{daily.revert.missing}
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
172
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
173 If you revert a \hgcmd{copy}, the copied-to file remains in your
123
f954c6f6eaa1 Progress.
Bryan O'Sullivan <bos@serpentine.com>
parents: 122
diff changeset
174 working directory afterwards, untracked. Since a copy doesn't affect
f954c6f6eaa1 Progress.
Bryan O'Sullivan <bos@serpentine.com>
parents: 122
diff changeset
175 the copied-from file in any way, Mercurial doesn't do anything with
f954c6f6eaa1 Progress.
Bryan O'Sullivan <bos@serpentine.com>
parents: 122
diff changeset
176 the copied-from file.
122
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
177 \interaction{daily.revert.copy}
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
178
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
179 \subsubsection{A slightly special case: reverting a rename}
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
180
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
181 If you \hgcmd{rename} a file, there is one small detail that
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
182 you should remember. When you \hgcmd{revert} a rename, it's not
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
183 enough to provide the name of the renamed-to file, as you can see
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
184 here.
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
185 \interaction{daily.revert.rename}
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
186 As you can see from the output of \hgcmd{status}, the renamed-to file
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
187 is no longer identified as added, but the renamed-\emph{from} file is
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
188 still removed! This is counter-intuitive (at least to me), but at
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
189 least it's easy to deal with.
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
190 \interaction{daily.revert.rename-orig}
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
191 So remember, to revert a \hgcmd{rename}, you must provide \emph{both}
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
192 the source and destination names.
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
193
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
194 (By the way, if you rename a file, then modify the renamed-to file,
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
195 then revert both components of the rename, when Mercurial restores the
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
196 file that was removed as part of the rename, it will be unmodified.
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
197 If you need the modifications in the renamed-to file to show up in the
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
198 renamed-from file, don't forget to copy them over.)
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
199
123
f954c6f6eaa1 Progress.
Bryan O'Sullivan <bos@serpentine.com>
parents: 122
diff changeset
200 These fiddly aspects of reverting a rename arguably constitute a small
122
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
201 bug in Mercurial.
3af28630fe8c How to goodbye depression by reverting one thousand times daily.
Bryan O'Sullivan <bos@serpentine.com>
parents: 121
diff changeset
202
124
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
203 \section{Dealing with committed changes}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
204
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
205 Consider a case where you have committed a change $a$, and another
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
206 change $b$ on top of it; you then realise that change $a$ was
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
207 incorrect. Mercurial lets you ``back out'' an entire changeset
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
208 automatically, and building blocks that let you reverse part of a
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
209 changeset by hand.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
210
126
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
211 Before you read this section, here's something to keep in mind: the
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
212 \hgcmd{backout} command undoes changes by \emph{adding} history, not
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
213 by modifying or erasing it. It's the right tool to use if you're
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
214 fixing bugs, but not if you're trying to undo some change that has
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
215 catastrophic consequences. To deal with those, see
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
216 section~\ref{sec:undo:aaaiiieee}.
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
217
124
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
218 \subsection{Backing out a changeset}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
219
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
220 The \hgcmd{backout} command lets you ``undo'' the effects of an entire
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
221 changeset in an automated fashion. Because Mercurial's history is
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
222 immutable, this command \emph{does not} get rid of the changeset you
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
223 want to undo. Instead, it creates a new changeset that
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
224 \emph{reverses} the effect of the to-be-undone changeset.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
225
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
226 The operation of the \hgcmd{backout} command is a little intricate, so
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
227 let's illustrate it with some examples. First, we'll create a
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
228 repository with some simple changes.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
229 \interaction{backout.init}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
230
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
231 The \hgcmd{backout} command takes a single changeset ID as its
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
232 argument; this is the changeset to back out. Normally,
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
233 \hgcmd{backout} will drop you into a text editor to write a commit
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
234 message, so you can record why you're backing the change out. In this
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
235 example, we provide a commit message on the command line using the
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
236 \hgopt{backout}{-m} option.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
237
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
238 \subsection{Backing out the tip changeset}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
239
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
240 We're going to start by backing out the last changeset we committed.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
241 \interaction{backout.simple}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
242 You can see that the second line from \filename{myfile} is no longer
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
243 present. Taking a look at the output of \hgcmd{log} gives us an idea
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
244 of what the \hgcmd{backout} command has done.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
245 \interaction{backout.simple.log}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
246 Notice that the new changeset that \hgcmd{backout} has created is a
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
247 child of the changeset we backed out. It's easier to see this in
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
248 figure~\ref{fig:undo:backout}, which presents a graphical view of the
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
249 change history. As you can see, the history is nice and linear.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
250
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
251 \begin{figure}[htb]
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
252 \centering
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
253 \grafix{undo-simple}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
254 \caption{Backing out a change using the \hgcmd{backout} command}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
255 \label{fig:undo:backout}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
256 \end{figure}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
257
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
258 \subsection{Backing out a non-tip change}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
259
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
260 If you want to back out a change other than the last one you
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
261 committed, pass the \hgopt{backout}{--merge} option to the
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
262 \hgcmd{backout} command.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
263 \interaction{backout.non-tip.clone}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
264 This makes backing out any changeset a ``one-shot'' operation that's
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
265 usually simple and fast.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
266 \interaction{backout.non-tip.backout}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
267
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
268 If you take a look at the contents of \filename{myfile} after the
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
269 backout finishes, you'll see that the first and third changes are
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
270 present, but not the second.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
271 \interaction{backout.non-tip.cat}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
272
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
273 As the graphical history in figure~\ref{fig:undo:backout-non-tip}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
274 illustrates, Mercurial actually commits \emph{two} changes in this
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
275 kind of situation (the box-shaped nodes are the ones that Mercurial
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
276 commits automatically). Before Mercurial begins the backout process,
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
277 it first remembers what the current parent of the working directory
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
278 is. It then backs out the target changeset, and commits that as a
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
279 changeset. Finally, it merges back to the previous parent of the
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
280 working directory, and commits the result of the merge.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
281
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
282 \begin{figure}[htb]
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
283 \centering
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
284 \grafix{undo-non-tip}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
285 \caption{Automated backout of a non-tip change using the \hgcmd{backout} command}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
286 \label{fig:undo:backout-non-tip}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
287 \end{figure}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
288
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
289 The result is that you end up ``back where you were'', only with some
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
290 extra history that undoes the effect of the changeset you wanted to
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
291 back out.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
292
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
293 \subsubsection{Always use the \hgopt{backout}{--merge} option}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
294
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
295 In fact, since the \hgopt{backout}{--merge} option will do the ``right
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
296 thing'' whether or not the changeset you're backing out is the tip
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
297 (i.e.~it won't try to merge if it's backing out the tip, since there's
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
298 no need), you should \emph{always} use this option when you run the
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
299 \hgcmd{backout} command.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
300
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
301 \subsection{Gaining more control of the backout process}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
302
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
303 While I've recommended that you always use the
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
304 \hgopt{backout}{--merge} option when backing out a change, the
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
305 \hgcmd{backout} command lets you decide how to merge a backout
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
306 changeset. Taking control of the backout process by hand is something
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
307 you will rarely need to do, but it can be useful to understand what
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
308 the \hgcmd{backout} command is doing for you automatically. To
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
309 illustrate this, let's clone our first repository, but omit the
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
310 backout change that it contains.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
311
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
312 \interaction{backout.manual.clone}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
313 As with our earlier example, We'll commit a third changeset, then back
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
314 out its parent, and see what happens.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
315 \interaction{backout.manual.backout}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
316 Our new changeset is again a descendant of the changeset we backout
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
317 out; it's thus a new head, \emph{not} a descendant of the changeset
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
318 that was the tip. The \hgcmd{backout} command was quite explicit in
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
319 telling us this.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
320 \interaction{backout.manual.log}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
321
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
322 Again, it's easier to see what has happened by looking at a graph of
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
323 the revision history, in figure~\ref{fig:undo:backout-manual}. This
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
324 makes it clear that when we use \hgcmd{backout} to back out a change
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
325 other than the tip, Mercurial adds a new head to the repository (the
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
326 change it committed is box-shaped).
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
327
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
328 \begin{figure}[htb]
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
329 \centering
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
330 \grafix{undo-manual}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
331 \caption{Backing out a change using the \hgcmd{backout} command}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
332 \label{fig:undo:backout-manual}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
333 \end{figure}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
334
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
335 After the \hgcmd{backout} command has completed, it leaves the new
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
336 ``backout'' changeset as the parent of the working directory.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
337 \interaction{backout.manual.parents}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
338 Now we have two isolated sets of changes.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
339 \interaction{backout.manual.heads}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
340
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
341 Let's think about what we expect to see as the contents of
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
342 \filename{myfile} now. The first change should be present, because
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
343 we've never backed it out. The second change should be missing, as
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
344 that's the change we backed out. Since the history graph shows the
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
345 third change as a separate head, we \emph{don't} expect to see the
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
346 third change present in \filename{myfile}.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
347 \interaction{backout.manual.cat}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
348 To get the third change back into the file, we just do a normal merge
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
349 of our two heads.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
350 \interaction{backout.manual.merge}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
351 Afterwards, the graphical history of our repository looks like
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
352 figure~\ref{fig:undo:backout-manual-merge}.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
353
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
354 \begin{figure}[htb]
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
355 \centering
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
356 \grafix{undo-manual-merge}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
357 \caption{Manually merging a backout change}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
358 \label{fig:undo:backout-manual-merge}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
359 \end{figure}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
360
126
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
361 \subsection{Why \hgcmd{backout} works as it does}
124
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
362
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
363 Here's a brief description of how the \hgcmd{backout} command works.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
364 \begin{enumerate}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
365 \item It ensures that the working directory is ``clean'', i.e.~that
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
366 the output of \hgcmd{status} would be empty.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
367 \item It remembers the current parent of the working directory. Let's
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
368 call this changeset \texttt{orig}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
369 \item It does the equivalent of a \hgcmd{update} to sync the working
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
370 directory to the changeset you want to back out. Let's call this
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
371 changeset \texttt{backout}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
372 \item It finds the parent of that changeset. Let's call that
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
373 changeset \texttt{parent}.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
374 \item For each file that the \texttt{backout} changeset affected, it
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
375 does the equivalent of a \hgcmdargs{revert}{-r parent} on that file,
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
376 to restore it to the contents it had before that changeset was
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
377 committed.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
378 \item It commits the result as a new changeset. This changeset has
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
379 \texttt{backout} as its parent.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
380 \item If you specify \hgopt{backout}{--merge} on the command line, it
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
381 merges with \texttt{orig}, and commits the result of the merge.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
382 \end{enumerate}
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
383
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
384 An alternative way to implement the \hgcmd{backout} command would be
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
385 to \hgcmd{export} the to-be-backed-out changeset as a diff, then use
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
386 the \cmdopt{patch}{--reverse} option to the \command{patch} command to
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
387 reverse the effect of the change without fiddling with the working
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
388 directory. This sounds much simpler, but it would not work nearly as
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
389 well.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
390
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
391 The reason that \hgcmd{backout} does an update, a commit, a merge, and
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
392 another commit is to give the merge machinery the best chance to do a
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
393 good job when dealing with all the changes \emph{between} the change
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
394 you're backing out and the current tip.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
395
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
396 If you're backing out a changeset that's~100 revisions back in your
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
397 project's history, the chances that the \command{patch} command will
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
398 be able to apply a reverse diff cleanly are not good, because
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
399 intervening changes are likely to have ``broken the context'' that
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
400 \command{patch} uses to determine whether it can apply a patch (if
125
8f8a1ad9627a Fix silly typo.
Bryan O'Sullivan <bos@serpentine.com>
parents: 124
diff changeset
401 this sounds like gibberish, see \ref{sec:mq:patch} for a
124
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
402 discussion of the \command{patch} command). Also, Mercurial's merge
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
403 machinery will handle files and directories being renamed, permission
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
404 changes, and modifications to binary files, none of which
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
405 \command{patch} can deal with.
c9aad709bd3a Document the backout command.
Bryan O'Sullivan <bos@serpentine.com>
parents: 123
diff changeset
406
126
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
407 \section{Changes that should never have been}
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
408 \label{sec:undo:aaaiiieee}
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
409
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
410 Most of the time, the \hgcmd{backout} command is exactly what you need
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
411 if you want to undo the effects of a change. It leaves a permanent
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
412 record of exactly what you did, both when committing the original
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
413 changeset and when you cleaned up after it.
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
414
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
415 On rare occasions, though, you may find that you've committed a change
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
416 that really should not be present in the repository at all. For
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
417 example, it would be very unusual, and usually considered a mistake,
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
418 to commit a software project's object files as well as its source
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
419 files. Object files have almost no intrinsic value, and they're
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
420 \emph{big}, so they increase the size of the repository and the amount
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
421 of time it takes to clone or pull changes.
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
422
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
423 Before I discuss the options that you have if you commit a ``brown
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
424 paper bag'' change (the kind that's so bad that you want to pull a
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
425 brown paper bag over your head), let me first discuss some approaches
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
426 that probably won't work.
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
427
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
428 Since Mercurial treats history as accumulative---every change builds
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
429 on top of all changes that preceded it---you generally can't just make
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
430 disastrous changes disappear. The one exception is when you've just
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
431 committed a change, and it hasn't been pushed or pulled into another
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
432 repository. That's when you can safely use the \hgcmd{rollback}
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
433 command, as I detailed in section~\ref{sec:undo:rollback}.
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
434
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
435 After you've pushed a bad change to another repository, you
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
436 \emph{could} still use \hgcmd{rollback} to make your local copy of the
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
437 change disappear, but it won't have the consequences you want. The
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
438 change will still be present in the remote repository, so it will
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
439 reappear in your local repository the next time you pull.
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
440
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
441 If a situation like this arises, and you know which repositories your
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
442 bad change has propagated into, you can \emph{try} to get rid of the
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
443 changeefrom \emph{every} one of those repositories. This is, of
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
444 course, not a satisfactory solution: if you miss even a single
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
445 repository while you're expunging, the change is still ``in the
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
446 wild'', and could propagate further.
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
447
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
448 If you've committed one or more changes \emph{after} the change that
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
449 you'd like to see disappear, your options are further reduced.
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
450 Mercurial doesn't provide a way to ``punch a hole'' in history,
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
451 leaving changesets intact.
fa3c43dd3a1e More undo-related verbiage.
Bryan O'Sullivan <bos@serpentine.com>
parents: 125
diff changeset
452
129
73efa1a01a6c Note to self.
Bryan O'Sullivan <bos@serpentine.com>
parents: 126
diff changeset
453 XXX This needs filling out. The \texttt{hg-replay} script in the
73efa1a01a6c Note to self.
Bryan O'Sullivan <bos@serpentine.com>
parents: 126
diff changeset
454 \texttt{examples} directory works, but doesn't handle merge
73efa1a01a6c Note to self.
Bryan O'Sullivan <bos@serpentine.com>
parents: 126
diff changeset
455 changesets. Kind of an important omission.
73efa1a01a6c Note to self.
Bryan O'Sullivan <bos@serpentine.com>
parents: 126
diff changeset
456
130
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
457 \section{Finding the source of a bug}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
458
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
459 While it's all very well to be able to back out a changeset that
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
460 introduced a bug, this requires that you know which changeset to back
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
461 out. Mercurial provides an invaluable extension, called
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
462 \hgext{bisect}, that helps you to automate this process and accomplish
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
463 it very efficiently.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
464
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
465 The idea behind the \hgext{bisect} extension is that a changeset has
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
466 introduced some change of behaviour that you can identify with a
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
467 simple binary test. You don't know which piece of code introduced the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
468 change, but you know how to test for the presence of the bug. The
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
469 \hgext{bisect} extension uses your test to direct its search for the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
470 changeset that introduced the code that caused the bug.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
471
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
472 Here are a few scenarios to help you understand how you might apply this
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
473 extension.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
474 \begin{itemize}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
475 \item The most recent version of your software has a bug that you
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
476 remember wasn't present a few weeks ago, but you don't know when it
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
477 was introduced. Here, your binary test checks for the presence of
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
478 that bug.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
479 \item You fixed a bug in a rush, and now it's time to close the entry
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
480 in your team's bug database. The bug database requires a changeset
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
481 ID when you close an entry, but you don't remember which changeset
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
482 you fixed the bug in. Once again, your binary test checks for the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
483 presence of the bug.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
484 \item Your software works correctly, but runs~15\% slower than the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
485 last time you measured it. You want to know which changeset
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
486 introduced the performance regression. In this case, your binary
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
487 test measures the performance of your software, to see whether it's
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
488 ``fast'' or ``slow''.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
489 \item The sizes of the components of your project that you ship
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
490 exploded recently, and you suspect that something changed in the way
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
491 you build your project.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
492 \end{itemize}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
493
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
494 From these examples, it should be clear that the \hgext{bisect}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
495 extension is not useful only for finding the sources of bugs. You can
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
496 use it to find any ``emergent property'' of a repository (anything
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
497 that you can't find from a simple text search of the files in the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
498 tree) for which you can write a binary test.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
499
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
500 We'll introduce a little bit of terminology here, just to make it
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
501 clear which parts of the search process are your responsibility, and
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
502 which are Mercurial's. A \emph{test} is something that \emph{you} run
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
503 when \hgext{bisect} chooses a changeset. A \emph{probe} is what
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
504 \hgext{bisect} runs to tell whether a revision is good. Finally,
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
505 we'll use the word ``bisect'', as both a noun and a verb, to stand in
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
506 for the phrase ``search using the \hgext{bisect} extension''.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
507
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
508 One simple way to automate the searching process would be simply to
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
509 probe every changeset. However, this scales poorly. If it took ten
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
510 minutes to test a single changeset, and you had 10,000 changesets in
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
511 your repository, the exhaustive approach would take on average~35
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
512 \emph{days} to find the changeset that introduced a bug. Even if you
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
513 knew that the bug was introduced by one of the last 500 changesets,
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
514 and limited your search to those, you'd still be looking at over 40
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
515 hours to find the changeset that introduced your bug.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
516
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
517 What the \emph{bisect} extension does is use its knowledge of the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
518 ``shape'' of your project's revision history to perform a search in
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
519 time proportional to the \emph{logarithm} of the number of changesets
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
520 to check (the kind of search it performs is called a dichotomic
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
521 search). With this approach, searching through 10,000 changesets will
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
522 take less than two hours, even at ten minutes per test. Limit your
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
523 search to the last 500 changesets, and it will take less than an hour.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
524
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
525 The \hgext{bisect} extension is aware of the ``branchy'' nature of a
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
526 Mercurial project's revision history, so it has no problems dealing
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
527 with branches, merges, or multiple heads in a repoository. It can
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
528 prune entire branches of history with a single probe, which is how it
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
529 operates so efficiently.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
530
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
531 \subsection{Using the \hgext{bisect} extension}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
532
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
533 Here's an example of \hgext{bisect} in action. To keep the core of
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
534 Mercurial simple, \hgext{bisect} is packaged as an extension; this
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
535 means that it won't be present unless you explicitly enable it. To do
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
536 this, edit your \hgrc\ and add the following section header (if it's
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
537 not already present):
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
538 \begin{codesample2}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
539 [extensions]
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
540 \end{codesample2}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
541 Then add a line to this section to enable the extension:
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
542 \begin{codesample2}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
543 hbisect =
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
544 \end{codesample2}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
545 \begin{note}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
546 That's right, there's a ``\texttt{h}'' at the front of the name of
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
547 the \hgext{bisect} extension. The reason is that Mercurial is
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
548 written in Python, and uses a standard Python package called
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
549 \texttt{bisect}. If you omit the ``\texttt{h}'' from the name
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
550 ``\texttt{hbisect}'', Mercurial will erroneously find the standard
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
551 Python \texttt{bisect} package, and try to use it as a Mercurial
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
552 extension. This won't work, and Mercurial will crash repeatedly
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
553 until you fix the spelling in your \hgrc. Ugh.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
554 \end{note}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
555
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
556 Now let's create a repository, so that we can try out the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
557 \hgext{bisect} extension in isolation.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
558 \interaction{bisect.init}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
559 We'll simulate a project that has a bug in it in a simple-minded way:
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
560 create trivial changes in a loop, and nominate one specific change
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
561 that will have the ``bug''. This loop creates 50 changesets, each
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
562 adding a single file to the repository. We'll represent our ``bug''
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
563 with a file that contains the text ``i have a gub''.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
564 \interaction{bisect.commits}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
565
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
566 The next thing that we'd like to do is figure out how to use the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
567 \hgext{bisect} extension. We can use Mercurial's normal built-in help
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
568 mechanism for this.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
569 \interaction{bisect.help}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
570
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
571 The \hgext{bisect} extension works in steps. Each step proceeds as follows.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
572 \begin{enumerate}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
573 \item You run your binary test.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
574 \begin{itemize}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
575 \item If the test succeeded, you tell \hgext{bisect} by running the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
576 \hgcmdargs{bisect}{good} command.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
577 \item If it failed, use the \hgcmdargs{bisect}{bad} command to let
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
578 the \hgext{bisect} extension know.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
579 \end{itemize}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
580 \item The extension uses your information to decide which changeset to
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
581 test next.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
582 \item It updates the working directory to that changeset, and the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
583 process begins again.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
584 \end{enumerate}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
585 The process ends when \hgext{bisect} identifies a unique changeset
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
586 that marks the point where your test transitioned from ``succeeding''
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
587 to ``failing''.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
588
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
589 To start the search, we must run the \hgcmdargs{bisect}{init} command.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
590 \interaction{bisect.search.init}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
591
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
592 In our case, the binary test we use is simple: we check to see if any
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
593 file in the repository contains the string ``i have a gub''. If it
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
594 does, this changeset contains the change that ``caused the bug''. By
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
595 convention, a changeset that has the property we're searching for is
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
596 ``bad'', while one that doesn't is ``good''.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
597
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
598 Most of the time, the revision to which the working directory is
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
599 synced (usually the tip) already exhibits the problem introduced by
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
600 the buggy change, so we'll mark it as ``bad''.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
601 \interaction{bisect.search.bad-init}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
602
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
603 Our next task is to nominate a changeset that we know \emph{doesn't}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
604 have the bug; the \hgext{bisect} extension will ``bracket'' its search
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
605 between the first pair of good and bad changesets. In our case, we
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
606 know that revision~10 didn't have the bug. (I'll have more words
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
607 about choosing the first ``good'' changeset later.)
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
608 \interaction{bisect.search.good-init}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
609
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
610 Notice that this command printed some output.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
611 \begin{itemize}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
612 \item It told us how many changesets it must consider before it can
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
613 identify the one that introduced the bug, and how many tests that
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
614 will require.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
615 \item It updated the working directory to the next changeset to test,
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
616 and told us which changeset it's testing.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
617 \end{itemize}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
618
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
619 We now run our test in the working directory. We use the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
620 \command{grep} command to see if our ``bad'' file is present in the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
621 working directory. If it is, this revision is bad; if not, this
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
622 revision is good.
131
153efeaa8f57 Fix stupid build bugs.
Bryan O'Sullivan <bos@serpentine.com>
parents: 130
diff changeset
623 \interaction{bisect.search.step1}
130
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
624
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
625 This test looks like a perfect candidate for automation, so let's turn
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
626 it into a shell function.
131
153efeaa8f57 Fix stupid build bugs.
Bryan O'Sullivan <bos@serpentine.com>
parents: 130
diff changeset
627 \interaction{bisect.search.mytest}
130
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
628 We can now run an entire test step with a single command,
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
629 \texttt{mytest}.
131
153efeaa8f57 Fix stupid build bugs.
Bryan O'Sullivan <bos@serpentine.com>
parents: 130
diff changeset
630 \interaction{bisect.search.step2}
130
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
631 A few more invocations of our canned test step command, and we're
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
632 done.
131
153efeaa8f57 Fix stupid build bugs.
Bryan O'Sullivan <bos@serpentine.com>
parents: 130
diff changeset
633 \interaction{bisect.search.rest}
130
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
634
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
635 Even though we had~40 changesets to search through, the \hgext{bisect}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
636 extension let us find the changeset that introduced our ``bug'' with
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
637 only five tests. Because the number of tests that the \hgext{bisect}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
638 extension grows logarithmically with the number of changesets to
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
639 search, the advantage that it has over the ``brute force'' search
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
640 approach increases with every changeset you add.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
641
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
642 \subsection{Cleaning up after your search}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
643
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
644 When you're finished using the \hgext{bisect} extension in a
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
645 repository, you can use the \hgcmdargs{bisect}{reset} command to drop
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
646 the information it was using to drive your search. The extension
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
647 doesn't use much space, so it doesn't matter if you forget to run this
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
648 command. However, \hgext{bisect} won't let you start a new search in
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
649 that repository until you do a \hgcmdargs{bisect}{reset}.
131
153efeaa8f57 Fix stupid build bugs.
Bryan O'Sullivan <bos@serpentine.com>
parents: 130
diff changeset
650 \interaction{bisect.search.reset}
130
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
651
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
652 \section{Tips for finding bugs effectively}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
653
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
654 \subsection{Give consistent input}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
655
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
656 The \hgext{bisect} extension requires that you correctly report the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
657 result of every test you perform. If you tell it that a test failed
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
658 when it really succeeded, it \emph{might} be able to detect the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
659 inconsistency. If it can identify an inconsistency in your reports,
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
660 it will tell you that a particular changeset is both good and bad.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
661 However, it can't do this perfectly; it's about as likely to report
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
662 the wrong changeset as the source of the bug.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
663
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
664 \subsection{Automate as much as possible}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
665
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
666 When I started using the \hgext{bisect} extension, I tried a few times
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
667 to run my tests by hand, on the command line. This is an approach
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
668 that I, at least, am not suited to. After a few tries, I found that I
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
669 was making enough mistakes that I was having to restart my searches
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
670 several times before finally getting correct results.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
671
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
672 My initial problems with driving the \hgext{bisect} extension by hand
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
673 occurred even with simple searches on small repositories; if the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
674 problem you're looking for is more subtle, or the number of tests that
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
675 \hgext{bisect} must perform increases, the likelihood of operator
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
676 error ruining the search is much higher. Once I started automating my
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
677 tests, I had much better results.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
678
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
679 The key to automated testing is twofold:
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
680 \begin{itemize}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
681 \item always test for the same symptom, and
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
682 \item always feed consistent input to the \hgcmd{bisect} command.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
683 \end{itemize}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
684 In my tutorial example above, the \command{grep} command tests for the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
685 symptom, and the \texttt{if} statement takes the result of this check
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
686 and ensures that we always feed the same input to the \hgcmd{bisect}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
687 command. The \texttt{mytest} function marries these together in a
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
688 reproducible way, so that every test is uniform and consistent.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
689
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
690 \subsection{Check your results}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
691
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
692 Because the output of a \hgext{bisect} search is only as good as the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
693 input you give it, don't take the changeset it reports as the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
694 absolute truth. A simple way to cross-check its report is to manually
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
695 run your test at each of the following changesets:
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
696 \begin{itemize}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
697 \item The changeset that it reports as the first bad revision. Your
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
698 test should still report this as bad.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
699 \item The parent of that changeset (either parent, if it's a merge).
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
700 Your test should report this changeset as good.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
701 \item A child of that changeset. Your test should report this
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
702 changeset as bad.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
703 \end{itemize}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
704
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
705 \subsection{Beware interference between bugs}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
706
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
707 It's possible that your search for one bug could be disrupted by the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
708 presence of another. For example, let's say your software crashes at
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
709 revision 100, and worked correctly at revision 50. Unknown to you,
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
710 someone else introduced a different crashing bug at revision 60, and
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
711 fixed it at revision 80. This could distort your results in one of
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
712 several ways.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
713
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
714 It is possible that this other bug completely ``masks'' yours, which
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
715 is to say that it occurs before your bug has a chance to manifest
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
716 itself. If you can't avoid that other bug (for example, it prevents
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
717 your project from building), and so can't tell whether your bug is
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
718 present in a particular changeset, the \hgext{bisect} extension cannot
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
719 help you directly. Instead, you'll need to manually avoid the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
720 changesets where that bug is present, and do separate searches
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
721 ``around'' it.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
722
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
723 A different problem could arise if your test for a bug's presence is
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
724 not specific enough. If you checks for ``my program crashes'', then
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
725 both your crashing bug and an unrelated crashing bug that masks it
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
726 will look like the same thing, and mislead \hgext{bisect}.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
727
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
728 \subsection{Bracket your search lazily}
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
729
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
730 Choosing the first ``good'' and ``bad'' changesets that will mark the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
731 end points of your search is often easy, but it bears a little
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
732 discussion neverthheless. From the perspective of \hgext{bisect}, the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
733 ``newest'' changeset is conventionally ``bad'', and the older
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
734 changeset is ``good''.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
735
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
736 If you're having trouble remembering when a suitable ``good'' change
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
737 was, so that you can tell \hgext{bisect}, you could do worse than
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
738 testing changesets at random. Just remember to eliminate contenders
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
739 that can't possibly exhibit the bug (perhaps because the feature with
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
740 the bug isn't present yet) and those where another problem masks the
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
741 bug (as I discussed above).
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
742
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
743 Even if you end up ``early'' by thousands of changesets or months of
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
744 history, you will only add a handful of tests to the total number that
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
745 \hgext{bisect} must perform, thanks to its logarithmic behaviour.
26b7a4e943aa Describe the bisect extension.
Bryan O'Sullivan <bos@serpentine.com>
parents: 129
diff changeset
746
121
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
747 %%% Local Variables:
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
748 %%% mode: latex
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
749 %%% TeX-master: "00book"
9094c9fda8ec Start chapter on error recovery.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
750 %%% End: