annotate es/undo.tex @ 473:c2ff82128ac5

Started translating undo.tex , added mistake and rollback
author Igor TAmara <igor@tamarapatino.org>
date Mon, 27 Oct 2008 13:32:16 -0500
parents 2fb78d342e07
children d5f1049a79dd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
473
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
1 \chapter{Encontrar y arreglar sus equivocaciones}
442
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
2 \label{chap:undo}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
3
473
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
4 Errar es humano, pero tratar adecuadamente las consecuencias requiere
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
5 un sistema de control de revisiones de primera categoría. En este
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
6 capítulo, discutiremos algunas técnicas que puede usar cuando
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
7 encuentra que hay un problema enraizado en su proyecto. Mercurial
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
8 tiene unas características poderosas que le ayudarán a isolar las
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
9 fuentes de los problemas, y a dar cuenta de ellas apropiadamente.
442
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
10
473
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
11 \section{Borrar la historia local}
442
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
12
473
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
13 \subsection{La consignación accidental}
442
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
14
473
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
15 Tengo el problema ocasional, pero persistente de teclear más rápido de
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
16 lo que pienso, que aveces resulta en consignar un conjunto de cambios
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
17 incompleto o simplemente malo. En mi caso, el conjunto de cambios
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
18 incompleto consiste en que creé un nuevo archivo fuente, pero olvidé
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
19 hacerle \hgcmd{add}. Un conjunto de cambios``simplemente malo'' no es
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
20 tan común, pero sí resulta muy molesto.
442
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
21
473
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
22 \subsection{Retroceder una transacción}
442
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
23 \label{sec:undo:rollback}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
24
473
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
25 En la sección~\ref{sec:concepts:txn}, mencioné que Mercurial trata
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
26 modificación a un repositorio como una \emph{transacción}. Cada vez
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
27 que consigna un conjunto de cambios o lo jala de otro repositorio,
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
28 Mercurial recuerda lo que hizo. Puede deshacer, o \emph{retroceder},
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
29 exactamente una de tales acciones usando la orden \hgcmd{rollback}.
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
30 (Ver en la sección~\ref{sec:undo:rollback-after-push} una anotación
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
31 importante acerca del uso de esta orden.)
442
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
32
473
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
33 A continuación una equivocación que me sucede frecuentemente:
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
34 consignar un cambio en el cual he creado un nuevo fichero, pero he
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
35 olvidado hacerle \hgcmd{add}.
442
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
36 \interaction{rollback.commit}
473
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
37 La salida de \hgcmd{status} después de la consignación confirma
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
38 inmediatamente este error.
442
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
39 \interaction{rollback.status}
473
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
40 La consignación capturó los cambios en el archivo \filename{a}, pero
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
41 no el nuevo fichero \filename{b}. Si yo publicara este conjunto de
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
42 cambios a un repositorio compartido con un colega, es bastante
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
43 probable que algo en \filename{a} se refiriera a \filename{b}, el cual
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
44 podría no estar presente cuando jalen mis cambios del repositorio. Me
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
45 convertiría el sujeto de cierta indignación.
442
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
46
473
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
47 Como sea, la suerte me acompaña---Encontré mi error antes de publicar
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
48 el conjunto de cambios. Uso la orden \hgcmd{rollback}, y Mercurial
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
49 hace desaparecer el último conjunto de cambios.
442
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
50 \interaction{rollback.rollback}
473
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
51 El conjunto de cambios ya no está en la historia del repositorio, y el
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
52 directorio de trabajo cree que el fichero \filename{a} ha sido
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
53 modificado. La consignación y el retroceso dejaron el directorio de
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
54 trabajo exactamente como estaban antes de la consignación; el conjunto
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
55 de cambios ha sido eliminado totlamente. Ahora puedo hacer \hgcmd{add}
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
56 al fichero \filename{b}, y hacer de nuevo la consignación.
442
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
57 \interaction{rollback.add}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
58
473
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
59 \subsection{Erroneamente jalado}
442
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
60
473
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
61 Mantener ramas de desarrollo separadas de un proyecto en distintos
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
62 repositorios es una práctica común con Mercurial. Su equipo de
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
63 desarrollo puede tener un repositorio compartido para la versión ``0.9''
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
64 y otra con cambios distintos para la versión ``1.0''.
442
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
65
473
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
66 Con este escenario, puede imaginar las consecuencias si tuviera un
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
67 repositorio local ``0.9'', y jalara accidentalmente los cambios del
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
68 repositorio compartido de la versión ``1.0'' en este. En el peor de
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
69 los casos, por falta de atención, es posible que publique tales
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
70 cambios en el árbol compartido ``0.9'', confundiendo a todo su equipo
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
71 de trabajo(pero no se preocupe, volveremos a este terrorífico
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
72 escenario posteriormente). En todo caso, es muy probable que usted se
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
73 de cuenta inmediatamente, dado que Mercurial mostrará el URL de donde
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
74 está jalando, o que vea jalando una sospechosa gran cantidad de
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
75 cambios en el repositorio.
442
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
76
473
c2ff82128ac5 Started translating undo.tex , added mistake and rollback
Igor TAmara <igor@tamarapatino.org>
parents: 442
diff changeset
77 La orden \hgcmd{rollback} command will work nicely to expunge all of the
442
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
78 changesets that you just pulled. Mercurial groups all changes from
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
79 one \hgcmd{pull} into a single transaction, so one \hgcmd{rollback} is
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
80 all you need to undo this mistake.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
81
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
82 \subsection{Rolling back is useless once you've pushed}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
83 \label{sec:undo:rollback-after-push}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
84
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
85 The value of the \hgcmd{rollback} command drops to zero once you've
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
86 pushed your changes to another repository. Rolling back a change
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
87 makes it disappear entirely, but \emph{only} in the repository in
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
88 which you perform the \hgcmd{rollback}. Because a rollback eliminates
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
89 history, there's no way for the disappearance of a change to propagate
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
90 between repositories.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
91
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
92 If you've pushed a change to another repository---particularly if it's
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
93 a shared repository---it has essentially ``escaped into the wild,''
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
94 and you'll have to recover from your mistake in a different way. What
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
95 will happen if you push a changeset somewhere, then roll it back, then
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
96 pull from the repository you pushed to, is that the changeset will
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
97 reappear in your repository.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
98
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
99 (If you absolutely know for sure that the change you want to roll back
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
100 is the most recent change in the repository that you pushed to,
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
101 \emph{and} you know that nobody else could have pulled it from that
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
102 repository, you can roll back the changeset there, too, but you really
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
103 should really not rely on this working reliably. If you do this,
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
104 sooner or later a change really will make it into a repository that
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
105 you don't directly control (or have forgotten about), and come back to
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
106 bite you.)
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
107
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
108 \subsection{You can only roll back once}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
109
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
110 Mercurial stores exactly one transaction in its transaction log; that
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
111 transaction is the most recent one that occurred in the repository.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
112 This means that you can only roll back one transaction. If you expect
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
113 to be able to roll back one transaction, then its predecessor, this is
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
114 not the behaviour you will get.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
115 \interaction{rollback.twice}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
116 Once you've rolled back one transaction in a repository, you can't
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
117 roll back again in that repository until you perform another commit or
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
118 pull.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
119
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
120 \section{Reverting the mistaken change}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
121
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
122 If you make a modification to a file, and decide that you really
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
123 didn't want to change the file at all, and you haven't yet committed
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
124 your changes, the \hgcmd{revert} command is the one you'll need. It
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
125 looks at the changeset that's the parent of the working directory, and
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
126 restores the contents of the file to their state as of that changeset.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
127 (That's a long-winded way of saying that, in the normal case, it
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
128 undoes your modifications.)
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
129
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
130 Let's illustrate how the \hgcmd{revert} command works with yet another
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
131 small example. We'll begin by modifying a file that Mercurial is
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
132 already tracking.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
133 \interaction{daily.revert.modify}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
134 If we don't want that change, we can simply \hgcmd{revert} the file.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
135 \interaction{daily.revert.unmodify}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
136 The \hgcmd{revert} command provides us with an extra degree of safety
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
137 by saving our modified file with a \filename{.orig} extension.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
138 \interaction{daily.revert.status}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
139
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
140 Here is a summary of the cases that the \hgcmd{revert} command can
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
141 deal with. We will describe each of these in more detail in the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
142 section that follows.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
143 \begin{itemize}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
144 \item If you modify a file, it will restore the file to its unmodified
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
145 state.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
146 \item If you \hgcmd{add} a file, it will undo the ``added'' state of
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
147 the file, but leave the file itself untouched.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
148 \item If you delete a file without telling Mercurial, it will restore
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
149 the file to its unmodified contents.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
150 \item If you use the \hgcmd{remove} command to remove a file, it will
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
151 undo the ``removed'' state of the file, and restore the file to its
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
152 unmodified contents.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
153 \end{itemize}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
154
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
155 \subsection{File management errors}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
156 \label{sec:undo:mgmt}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
157
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
158 The \hgcmd{revert} command is useful for more than just modified
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
159 files. It lets you reverse the results of all of Mercurial's file
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
160 management commands---\hgcmd{add}, \hgcmd{remove}, and so on.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
161
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
162 If you \hgcmd{add} a file, then decide that in fact you don't want
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
163 Mercurial to track it, use \hgcmd{revert} to undo the add. Don't
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
164 worry; Mercurial will not modify the file in any way. It will just
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
165 ``unmark'' the file.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
166 \interaction{daily.revert.add}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
167
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
168 Similarly, if you ask Mercurial to \hgcmd{remove} a file, you can use
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
169 \hgcmd{revert} to restore it to the contents it had as of the parent
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
170 of the working directory.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
171 \interaction{daily.revert.remove}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
172 This works just as well for a file that you deleted by hand, without
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
173 telling Mercurial (recall that in Mercurial terminology, this kind of
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
174 file is called ``missing'').
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
175 \interaction{daily.revert.missing}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
176
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
177 If you revert a \hgcmd{copy}, the copied-to file remains in your
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
178 working directory afterwards, untracked. Since a copy doesn't affect
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
179 the copied-from file in any way, Mercurial doesn't do anything with
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
180 the copied-from file.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
181 \interaction{daily.revert.copy}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
182
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
183 \subsubsection{A slightly special case: reverting a rename}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
184
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
185 If you \hgcmd{rename} a file, there is one small detail that
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
186 you should remember. When you \hgcmd{revert} a rename, it's not
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
187 enough to provide the name of the renamed-to file, as you can see
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
188 here.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
189 \interaction{daily.revert.rename}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
190 As you can see from the output of \hgcmd{status}, the renamed-to file
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
191 is no longer identified as added, but the renamed-\emph{from} file is
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
192 still removed! This is counter-intuitive (at least to me), but at
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
193 least it's easy to deal with.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
194 \interaction{daily.revert.rename-orig}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
195 So remember, to revert a \hgcmd{rename}, you must provide \emph{both}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
196 the source and destination names.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
197
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
198 % TODO: the output doesn't look like it will be removed!
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
199
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
200 (By the way, if you rename a file, then modify the renamed-to file,
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
201 then revert both components of the rename, when Mercurial restores the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
202 file that was removed as part of the rename, it will be unmodified.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
203 If you need the modifications in the renamed-to file to show up in the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
204 renamed-from file, don't forget to copy them over.)
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
205
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
206 These fiddly aspects of reverting a rename arguably constitute a small
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
207 bug in Mercurial.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
208
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
209 \section{Dealing with committed changes}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
210
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
211 Consider a case where you have committed a change $a$, and another
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
212 change $b$ on top of it; you then realise that change $a$ was
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
213 incorrect. Mercurial lets you ``back out'' an entire changeset
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
214 automatically, and building blocks that let you reverse part of a
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
215 changeset by hand.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
216
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
217 Before you read this section, here's something to keep in mind: the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
218 \hgcmd{backout} command undoes changes by \emph{adding} history, not
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
219 by modifying or erasing it. It's the right tool to use if you're
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
220 fixing bugs, but not if you're trying to undo some change that has
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
221 catastrophic consequences. To deal with those, see
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
222 section~\ref{sec:undo:aaaiiieee}.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
223
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
224 \subsection{Backing out a changeset}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
225
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
226 The \hgcmd{backout} command lets you ``undo'' the effects of an entire
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
227 changeset in an automated fashion. Because Mercurial's history is
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
228 immutable, this command \emph{does not} get rid of the changeset you
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
229 want to undo. Instead, it creates a new changeset that
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
230 \emph{reverses} the effect of the to-be-undone changeset.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
231
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
232 The operation of the \hgcmd{backout} command is a little intricate, so
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
233 let's illustrate it with some examples. First, we'll create a
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
234 repository with some simple changes.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
235 \interaction{backout.init}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
236
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
237 The \hgcmd{backout} command takes a single changeset ID as its
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
238 argument; this is the changeset to back out. Normally,
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
239 \hgcmd{backout} will drop you into a text editor to write a commit
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
240 message, so you can record why you're backing the change out. In this
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
241 example, we provide a commit message on the command line using the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
242 \hgopt{backout}{-m} option.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
243
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
244 \subsection{Backing out the tip changeset}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
245
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
246 We're going to start by backing out the last changeset we committed.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
247 \interaction{backout.simple}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
248 You can see that the second line from \filename{myfile} is no longer
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
249 present. Taking a look at the output of \hgcmd{log} gives us an idea
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
250 of what the \hgcmd{backout} command has done.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
251 \interaction{backout.simple.log}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
252 Notice that the new changeset that \hgcmd{backout} has created is a
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
253 child of the changeset we backed out. It's easier to see this in
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
254 figure~\ref{fig:undo:backout}, which presents a graphical view of the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
255 change history. As you can see, the history is nice and linear.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
256
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
257 \begin{figure}[htb]
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
258 \centering
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
259 \grafix{undo-simple}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
260 \caption{Backing out a change using the \hgcmd{backout} command}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
261 \label{fig:undo:backout}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
262 \end{figure}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
263
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
264 \subsection{Backing out a non-tip change}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
265
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
266 If you want to back out a change other than the last one you
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
267 committed, pass the \hgopt{backout}{--merge} option to the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
268 \hgcmd{backout} command.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
269 \interaction{backout.non-tip.clone}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
270 This makes backing out any changeset a ``one-shot'' operation that's
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
271 usually simple and fast.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
272 \interaction{backout.non-tip.backout}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
273
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
274 If you take a look at the contents of \filename{myfile} after the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
275 backout finishes, you'll see that the first and third changes are
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
276 present, but not the second.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
277 \interaction{backout.non-tip.cat}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
278
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
279 As the graphical history in figure~\ref{fig:undo:backout-non-tip}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
280 illustrates, Mercurial actually commits \emph{two} changes in this
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
281 kind of situation (the box-shaped nodes are the ones that Mercurial
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
282 commits automatically). Before Mercurial begins the backout process,
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
283 it first remembers what the current parent of the working directory
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
284 is. It then backs out the target changeset, and commits that as a
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
285 changeset. Finally, it merges back to the previous parent of the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
286 working directory, and commits the result of the merge.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
287
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
288 % TODO: to me it looks like mercurial doesn't commit the second merge automatically!
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
289
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
290 \begin{figure}[htb]
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
291 \centering
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
292 \grafix{undo-non-tip}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
293 \caption{Automated backout of a non-tip change using the \hgcmd{backout} command}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
294 \label{fig:undo:backout-non-tip}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
295 \end{figure}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
296
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
297 The result is that you end up ``back where you were'', only with some
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
298 extra history that undoes the effect of the changeset you wanted to
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
299 back out.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
300
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
301 \subsubsection{Always use the \hgopt{backout}{--merge} option}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
302
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
303 In fact, since the \hgopt{backout}{--merge} option will do the ``right
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
304 thing'' whether or not the changeset you're backing out is the tip
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
305 (i.e.~it won't try to merge if it's backing out the tip, since there's
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
306 no need), you should \emph{always} use this option when you run the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
307 \hgcmd{backout} command.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
308
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
309 \subsection{Gaining more control of the backout process}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
310
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
311 While I've recommended that you always use the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
312 \hgopt{backout}{--merge} option when backing out a change, the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
313 \hgcmd{backout} command lets you decide how to merge a backout
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
314 changeset. Taking control of the backout process by hand is something
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
315 you will rarely need to do, but it can be useful to understand what
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
316 the \hgcmd{backout} command is doing for you automatically. To
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
317 illustrate this, let's clone our first repository, but omit the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
318 backout change that it contains.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
319
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
320 \interaction{backout.manual.clone}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
321 As with our earlier example, We'll commit a third changeset, then back
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
322 out its parent, and see what happens.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
323 \interaction{backout.manual.backout}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
324 Our new changeset is again a descendant of the changeset we backout
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
325 out; it's thus a new head, \emph{not} a descendant of the changeset
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
326 that was the tip. The \hgcmd{backout} command was quite explicit in
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
327 telling us this.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
328 \interaction{backout.manual.log}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
329
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
330 Again, it's easier to see what has happened by looking at a graph of
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
331 the revision history, in figure~\ref{fig:undo:backout-manual}. This
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
332 makes it clear that when we use \hgcmd{backout} to back out a change
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
333 other than the tip, Mercurial adds a new head to the repository (the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
334 change it committed is box-shaped).
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
335
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
336 \begin{figure}[htb]
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
337 \centering
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
338 \grafix{undo-manual}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
339 \caption{Backing out a change using the \hgcmd{backout} command}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
340 \label{fig:undo:backout-manual}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
341 \end{figure}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
342
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
343 After the \hgcmd{backout} command has completed, it leaves the new
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
344 ``backout'' changeset as the parent of the working directory.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
345 \interaction{backout.manual.parents}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
346 Now we have two isolated sets of changes.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
347 \interaction{backout.manual.heads}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
348
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
349 Let's think about what we expect to see as the contents of
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
350 \filename{myfile} now. The first change should be present, because
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
351 we've never backed it out. The second change should be missing, as
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
352 that's the change we backed out. Since the history graph shows the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
353 third change as a separate head, we \emph{don't} expect to see the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
354 third change present in \filename{myfile}.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
355 \interaction{backout.manual.cat}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
356 To get the third change back into the file, we just do a normal merge
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
357 of our two heads.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
358 \interaction{backout.manual.merge}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
359 Afterwards, the graphical history of our repository looks like
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
360 figure~\ref{fig:undo:backout-manual-merge}.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
361
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
362 \begin{figure}[htb]
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
363 \centering
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
364 \grafix{undo-manual-merge}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
365 \caption{Manually merging a backout change}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
366 \label{fig:undo:backout-manual-merge}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
367 \end{figure}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
368
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
369 \subsection{Why \hgcmd{backout} works as it does}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
370
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
371 Here's a brief description of how the \hgcmd{backout} command works.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
372 \begin{enumerate}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
373 \item It ensures that the working directory is ``clean'', i.e.~that
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
374 the output of \hgcmd{status} would be empty.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
375 \item It remembers the current parent of the working directory. Let's
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
376 call this changeset \texttt{orig}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
377 \item It does the equivalent of a \hgcmd{update} to sync the working
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
378 directory to the changeset you want to back out. Let's call this
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
379 changeset \texttt{backout}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
380 \item It finds the parent of that changeset. Let's call that
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
381 changeset \texttt{parent}.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
382 \item For each file that the \texttt{backout} changeset affected, it
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
383 does the equivalent of a \hgcmdargs{revert}{-r parent} on that file,
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
384 to restore it to the contents it had before that changeset was
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
385 committed.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
386 \item It commits the result as a new changeset. This changeset has
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
387 \texttt{backout} as its parent.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
388 \item If you specify \hgopt{backout}{--merge} on the command line, it
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
389 merges with \texttt{orig}, and commits the result of the merge.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
390 \end{enumerate}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
391
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
392 An alternative way to implement the \hgcmd{backout} command would be
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
393 to \hgcmd{export} the to-be-backed-out changeset as a diff, then use
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
394 the \cmdopt{patch}{--reverse} option to the \command{patch} command to
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
395 reverse the effect of the change without fiddling with the working
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
396 directory. This sounds much simpler, but it would not work nearly as
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
397 well.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
398
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
399 The reason that \hgcmd{backout} does an update, a commit, a merge, and
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
400 another commit is to give the merge machinery the best chance to do a
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
401 good job when dealing with all the changes \emph{between} the change
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
402 you're backing out and the current tip.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
403
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
404 If you're backing out a changeset that's~100 revisions back in your
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
405 project's history, the chances that the \command{patch} command will
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
406 be able to apply a reverse diff cleanly are not good, because
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
407 intervening changes are likely to have ``broken the context'' that
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
408 \command{patch} uses to determine whether it can apply a patch (if
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
409 this sounds like gibberish, see \ref{sec:mq:patch} for a
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
410 discussion of the \command{patch} command). Also, Mercurial's merge
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
411 machinery will handle files and directories being renamed, permission
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
412 changes, and modifications to binary files, none of which
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
413 \command{patch} can deal with.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
414
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
415 \section{Changes that should never have been}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
416 \label{sec:undo:aaaiiieee}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
417
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
418 Most of the time, the \hgcmd{backout} command is exactly what you need
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
419 if you want to undo the effects of a change. It leaves a permanent
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
420 record of exactly what you did, both when committing the original
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
421 changeset and when you cleaned up after it.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
422
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
423 On rare occasions, though, you may find that you've committed a change
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
424 that really should not be present in the repository at all. For
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
425 example, it would be very unusual, and usually considered a mistake,
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
426 to commit a software project's object files as well as its source
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
427 files. Object files have almost no intrinsic value, and they're
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
428 \emph{big}, so they increase the size of the repository and the amount
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
429 of time it takes to clone or pull changes.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
430
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
431 Before I discuss the options that you have if you commit a ``brown
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
432 paper bag'' change (the kind that's so bad that you want to pull a
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
433 brown paper bag over your head), let me first discuss some approaches
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
434 that probably won't work.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
435
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
436 Since Mercurial treats history as accumulative---every change builds
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
437 on top of all changes that preceded it---you generally can't just make
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
438 disastrous changes disappear. The one exception is when you've just
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
439 committed a change, and it hasn't been pushed or pulled into another
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
440 repository. That's when you can safely use the \hgcmd{rollback}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
441 command, as I detailed in section~\ref{sec:undo:rollback}.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
442
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
443 After you've pushed a bad change to another repository, you
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
444 \emph{could} still use \hgcmd{rollback} to make your local copy of the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
445 change disappear, but it won't have the consequences you want. The
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
446 change will still be present in the remote repository, so it will
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
447 reappear in your local repository the next time you pull.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
448
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
449 If a situation like this arises, and you know which repositories your
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
450 bad change has propagated into, you can \emph{try} to get rid of the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
451 changeefrom \emph{every} one of those repositories. This is, of
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
452 course, not a satisfactory solution: if you miss even a single
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
453 repository while you're expunging, the change is still ``in the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
454 wild'', and could propagate further.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
455
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
456 If you've committed one or more changes \emph{after} the change that
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
457 you'd like to see disappear, your options are further reduced.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
458 Mercurial doesn't provide a way to ``punch a hole'' in history,
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
459 leaving changesets intact.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
460
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
461 XXX This needs filling out. The \texttt{hg-replay} script in the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
462 \texttt{examples} directory works, but doesn't handle merge
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
463 changesets. Kind of an important omission.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
464
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
465 \subsection{Protect yourself from ``escaped'' changes}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
466
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
467 If you've committed some changes to your local repository and they've
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
468 been pushed or pulled somewhere else, this isn't necessarily a
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
469 disaster. You can protect yourself ahead of time against some classes
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
470 of bad changeset. This is particularly easy if your team usually
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
471 pulls changes from a central repository.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
472
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
473 By configuring some hooks on that repository to validate incoming
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
474 changesets (see chapter~\ref{chap:hook}), you can automatically
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
475 prevent some kinds of bad changeset from being pushed to the central
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
476 repository at all. With such a configuration in place, some kinds of
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
477 bad changeset will naturally tend to ``die out'' because they can't
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
478 propagate into the central repository. Better yet, this happens
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
479 without any need for explicit intervention.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
480
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
481 For instance, an incoming change hook that verifies that a changeset
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
482 will actually compile can prevent people from inadvertantly ``breaking
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
483 the build''.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
484
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
485 \section{Finding the source of a bug}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
486 \label{sec:undo:bisect}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
487
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
488 While it's all very well to be able to back out a changeset that
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
489 introduced a bug, this requires that you know which changeset to back
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
490 out. Mercurial provides an invaluable command, called
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
491 \hgcmd{bisect}, that helps you to automate this process and accomplish
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
492 it very efficiently.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
493
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
494 The idea behind the \hgcmd{bisect} command is that a changeset has
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
495 introduced some change of behaviour that you can identify with a
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
496 simple binary test. You don't know which piece of code introduced the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
497 change, but you know how to test for the presence of the bug. The
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
498 \hgcmd{bisect} command uses your test to direct its search for the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
499 changeset that introduced the code that caused the bug.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
500
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
501 Here are a few scenarios to help you understand how you might apply
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
502 this command.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
503 \begin{itemize}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
504 \item The most recent version of your software has a bug that you
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
505 remember wasn't present a few weeks ago, but you don't know when it
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
506 was introduced. Here, your binary test checks for the presence of
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
507 that bug.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
508 \item You fixed a bug in a rush, and now it's time to close the entry
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
509 in your team's bug database. The bug database requires a changeset
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
510 ID when you close an entry, but you don't remember which changeset
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
511 you fixed the bug in. Once again, your binary test checks for the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
512 presence of the bug.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
513 \item Your software works correctly, but runs~15\% slower than the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
514 last time you measured it. You want to know which changeset
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
515 introduced the performance regression. In this case, your binary
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
516 test measures the performance of your software, to see whether it's
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
517 ``fast'' or ``slow''.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
518 \item The sizes of the components of your project that you ship
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
519 exploded recently, and you suspect that something changed in the way
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
520 you build your project.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
521 \end{itemize}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
522
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
523 From these examples, it should be clear that the \hgcmd{bisect}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
524 command is not useful only for finding the sources of bugs. You can
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
525 use it to find any ``emergent property'' of a repository (anything
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
526 that you can't find from a simple text search of the files in the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
527 tree) for which you can write a binary test.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
528
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
529 We'll introduce a little bit of terminology here, just to make it
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
530 clear which parts of the search process are your responsibility, and
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
531 which are Mercurial's. A \emph{test} is something that \emph{you} run
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
532 when \hgcmd{bisect} chooses a changeset. A \emph{probe} is what
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
533 \hgcmd{bisect} runs to tell whether a revision is good. Finally,
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
534 we'll use the word ``bisect'', as both a noun and a verb, to stand in
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
535 for the phrase ``search using the \hgcmd{bisect} command.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
536
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
537 One simple way to automate the searching process would be simply to
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
538 probe every changeset. However, this scales poorly. If it took ten
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
539 minutes to test a single changeset, and you had 10,000 changesets in
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
540 your repository, the exhaustive approach would take on average~35
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
541 \emph{days} to find the changeset that introduced a bug. Even if you
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
542 knew that the bug was introduced by one of the last 500 changesets,
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
543 and limited your search to those, you'd still be looking at over 40
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
544 hours to find the changeset that introduced your bug.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
545
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
546 What the \hgcmd{bisect} command does is use its knowledge of the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
547 ``shape'' of your project's revision history to perform a search in
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
548 time proportional to the \emph{logarithm} of the number of changesets
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
549 to check (the kind of search it performs is called a dichotomic
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
550 search). With this approach, searching through 10,000 changesets will
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
551 take less than three hours, even at ten minutes per test (the search
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
552 will require about 14 tests). Limit your search to the last hundred
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
553 changesets, and it will take only about an hour (roughly seven tests).
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
554
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
555 The \hgcmd{bisect} command is aware of the ``branchy'' nature of a
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
556 Mercurial project's revision history, so it has no problems dealing
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
557 with branches, merges, or multiple heads in a repoository. It can
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
558 prune entire branches of history with a single probe, which is how it
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
559 operates so efficiently.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
560
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
561 \subsection{Using the \hgcmd{bisect} command}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
562
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
563 Here's an example of \hgcmd{bisect} in action.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
564
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
565 \begin{note}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
566 In versions 0.9.5 and earlier of Mercurial, \hgcmd{bisect} was not a
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
567 core command: it was distributed with Mercurial as an extension.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
568 This section describes the built-in command, not the old extension.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
569 \end{note}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
570
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
571 Now let's create a repository, so that we can try out the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
572 \hgcmd{bisect} command in isolation.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
573 \interaction{bisect.init}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
574 We'll simulate a project that has a bug in it in a simple-minded way:
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
575 create trivial changes in a loop, and nominate one specific change
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
576 that will have the ``bug''. This loop creates 35 changesets, each
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
577 adding a single file to the repository. We'll represent our ``bug''
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
578 with a file that contains the text ``i have a gub''.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
579 \interaction{bisect.commits}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
580
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
581 The next thing that we'd like to do is figure out how to use the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
582 \hgcmd{bisect} command. We can use Mercurial's normal built-in help
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
583 mechanism for this.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
584 \interaction{bisect.help}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
585
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
586 The \hgcmd{bisect} command works in steps. Each step proceeds as follows.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
587 \begin{enumerate}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
588 \item You run your binary test.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
589 \begin{itemize}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
590 \item If the test succeeded, you tell \hgcmd{bisect} by running the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
591 \hgcmdargs{bisect}{good} command.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
592 \item If it failed, run the \hgcmdargs{bisect}{--bad} command.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
593 \end{itemize}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
594 \item The command uses your information to decide which changeset to
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
595 test next.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
596 \item It updates the working directory to that changeset, and the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
597 process begins again.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
598 \end{enumerate}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
599 The process ends when \hgcmd{bisect} identifies a unique changeset
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
600 that marks the point where your test transitioned from ``succeeding''
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
601 to ``failing''.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
602
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
603 To start the search, we must run the \hgcmdargs{bisect}{--reset} command.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
604 \interaction{bisect.search.init}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
605
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
606 In our case, the binary test we use is simple: we check to see if any
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
607 file in the repository contains the string ``i have a gub''. If it
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
608 does, this changeset contains the change that ``caused the bug''. By
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
609 convention, a changeset that has the property we're searching for is
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
610 ``bad'', while one that doesn't is ``good''.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
611
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
612 Most of the time, the revision to which the working directory is
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
613 synced (usually the tip) already exhibits the problem introduced by
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
614 the buggy change, so we'll mark it as ``bad''.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
615 \interaction{bisect.search.bad-init}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
616
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
617 Our next task is to nominate a changeset that we know \emph{doesn't}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
618 have the bug; the \hgcmd{bisect} command will ``bracket'' its search
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
619 between the first pair of good and bad changesets. In our case, we
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
620 know that revision~10 didn't have the bug. (I'll have more words
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
621 about choosing the first ``good'' changeset later.)
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
622 \interaction{bisect.search.good-init}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
623
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
624 Notice that this command printed some output.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
625 \begin{itemize}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
626 \item It told us how many changesets it must consider before it can
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
627 identify the one that introduced the bug, and how many tests that
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
628 will require.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
629 \item It updated the working directory to the next changeset to test,
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
630 and told us which changeset it's testing.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
631 \end{itemize}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
632
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
633 We now run our test in the working directory. We use the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
634 \command{grep} command to see if our ``bad'' file is present in the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
635 working directory. If it is, this revision is bad; if not, this
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
636 revision is good.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
637 \interaction{bisect.search.step1}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
638
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
639 This test looks like a perfect candidate for automation, so let's turn
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
640 it into a shell function.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
641 \interaction{bisect.search.mytest}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
642 We can now run an entire test step with a single command,
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
643 \texttt{mytest}.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
644 \interaction{bisect.search.step2}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
645 A few more invocations of our canned test step command, and we're
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
646 done.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
647 \interaction{bisect.search.rest}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
648
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
649 Even though we had~40 changesets to search through, the \hgcmd{bisect}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
650 command let us find the changeset that introduced our ``bug'' with
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
651 only five tests. Because the number of tests that the \hgcmd{bisect}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
652 command performs grows logarithmically with the number of changesets to
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
653 search, the advantage that it has over the ``brute force'' search
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
654 approach increases with every changeset you add.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
655
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
656 \subsection{Cleaning up after your search}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
657
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
658 When you're finished using the \hgcmd{bisect} command in a
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
659 repository, you can use the \hgcmdargs{bisect}{reset} command to drop
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
660 the information it was using to drive your search. The command
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
661 doesn't use much space, so it doesn't matter if you forget to run this
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
662 command. However, \hgcmd{bisect} won't let you start a new search in
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
663 that repository until you do a \hgcmdargs{bisect}{reset}.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
664 \interaction{bisect.search.reset}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
665
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
666 \section{Tips for finding bugs effectively}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
667
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
668 \subsection{Give consistent input}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
669
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
670 The \hgcmd{bisect} command requires that you correctly report the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
671 result of every test you perform. If you tell it that a test failed
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
672 when it really succeeded, it \emph{might} be able to detect the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
673 inconsistency. If it can identify an inconsistency in your reports,
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
674 it will tell you that a particular changeset is both good and bad.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
675 However, it can't do this perfectly; it's about as likely to report
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
676 the wrong changeset as the source of the bug.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
677
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
678 \subsection{Automate as much as possible}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
679
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
680 When I started using the \hgcmd{bisect} command, I tried a few times
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
681 to run my tests by hand, on the command line. This is an approach
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
682 that I, at least, am not suited to. After a few tries, I found that I
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
683 was making enough mistakes that I was having to restart my searches
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
684 several times before finally getting correct results.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
685
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
686 My initial problems with driving the \hgcmd{bisect} command by hand
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
687 occurred even with simple searches on small repositories; if the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
688 problem you're looking for is more subtle, or the number of tests that
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
689 \hgcmd{bisect} must perform increases, the likelihood of operator
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
690 error ruining the search is much higher. Once I started automating my
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
691 tests, I had much better results.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
692
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
693 The key to automated testing is twofold:
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
694 \begin{itemize}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
695 \item always test for the same symptom, and
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
696 \item always feed consistent input to the \hgcmd{bisect} command.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
697 \end{itemize}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
698 In my tutorial example above, the \command{grep} command tests for the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
699 symptom, and the \texttt{if} statement takes the result of this check
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
700 and ensures that we always feed the same input to the \hgcmd{bisect}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
701 command. The \texttt{mytest} function marries these together in a
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
702 reproducible way, so that every test is uniform and consistent.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
703
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
704 \subsection{Check your results}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
705
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
706 Because the output of a \hgcmd{bisect} search is only as good as the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
707 input you give it, don't take the changeset it reports as the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
708 absolute truth. A simple way to cross-check its report is to manually
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
709 run your test at each of the following changesets:
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
710 \begin{itemize}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
711 \item The changeset that it reports as the first bad revision. Your
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
712 test should still report this as bad.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
713 \item The parent of that changeset (either parent, if it's a merge).
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
714 Your test should report this changeset as good.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
715 \item A child of that changeset. Your test should report this
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
716 changeset as bad.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
717 \end{itemize}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
718
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
719 \subsection{Beware interference between bugs}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
720
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
721 It's possible that your search for one bug could be disrupted by the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
722 presence of another. For example, let's say your software crashes at
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
723 revision 100, and worked correctly at revision 50. Unknown to you,
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
724 someone else introduced a different crashing bug at revision 60, and
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
725 fixed it at revision 80. This could distort your results in one of
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
726 several ways.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
727
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
728 It is possible that this other bug completely ``masks'' yours, which
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
729 is to say that it occurs before your bug has a chance to manifest
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
730 itself. If you can't avoid that other bug (for example, it prevents
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
731 your project from building), and so can't tell whether your bug is
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
732 present in a particular changeset, the \hgcmd{bisect} command cannot
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
733 help you directly. Instead, you can mark a changeset as untested by
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
734 running \hgcmdargs{bisect}{--skip}.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
735
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
736 A different problem could arise if your test for a bug's presence is
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
737 not specific enough. If you check for ``my program crashes'', then
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
738 both your crashing bug and an unrelated crashing bug that masks it
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
739 will look like the same thing, and mislead \hgcmd{bisect}.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
740
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
741 Another useful situation in which to use \hgcmdargs{bisect}{--skip} is
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
742 if you can't test a revision because your project was in a broken and
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
743 hence untestable state at that revision, perhaps because someone
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
744 checked in a change that prevented the project from building.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
745
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
746 \subsection{Bracket your search lazily}
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
747
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
748 Choosing the first ``good'' and ``bad'' changesets that will mark the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
749 end points of your search is often easy, but it bears a little
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
750 discussion nevertheless. From the perspective of \hgcmd{bisect}, the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
751 ``newest'' changeset is conventionally ``bad'', and the older
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
752 changeset is ``good''.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
753
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
754 If you're having trouble remembering when a suitable ``good'' change
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
755 was, so that you can tell \hgcmd{bisect}, you could do worse than
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
756 testing changesets at random. Just remember to eliminate contenders
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
757 that can't possibly exhibit the bug (perhaps because the feature with
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
758 the bug isn't present yet) and those where another problem masks the
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
759 bug (as I discussed above).
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
760
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
761 Even if you end up ``early'' by thousands of changesets or months of
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
762 history, you will only add a handful of tests to the total number that
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
763 \hgcmd{bisect} must perform, thanks to its logarithmic behaviour.
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
764
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
765 %%% Local Variables:
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
766 %%% mode: latex
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
767 %%% TeX-master: "00book"
2fb78d342e07 changed es/Leame.1st
jerojasro@localhost
parents: 432
diff changeset
768 %%% End: