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