hgbook

diff en/undo.tex @ 296:e0b56f008b09

Fix sample output for 'backout' test.
author Guido Ostkamp <hg@ostkamp.fastmail.fm>
date Wed Aug 20 21:51:54 2008 +0200 (2008-08-20)
parents d145739b7865
children a168daed199b
line diff
     1.1 --- a/en/undo.tex	Fri Aug 31 19:44:35 2007 +0200
     1.2 +++ b/en/undo.tex	Wed Aug 20 21:51:54 2008 +0200
     1.3 @@ -482,19 +482,19 @@
     1.4  
     1.5  While it's all very well to be able to back out a changeset that
     1.6  introduced a bug, this requires that you know which changeset to back
     1.7 -out.  Mercurial provides an invaluable extension, called
     1.8 -\hgext{bisect}, that helps you to automate this process and accomplish
     1.9 +out.  Mercurial provides an invaluable command, called
    1.10 +\hgcmd{bisect}, that helps you to automate this process and accomplish
    1.11  it very efficiently.
    1.12  
    1.13 -The idea behind the \hgext{bisect} extension is that a changeset has
    1.14 +The idea behind the \hgcmd{bisect} command is that a changeset has
    1.15  introduced some change of behaviour that you can identify with a
    1.16  simple binary test.  You don't know which piece of code introduced the
    1.17  change, but you know how to test for the presence of the bug.  The
    1.18 -\hgext{bisect} extension uses your test to direct its search for the
    1.19 +\hgcmd{bisect} command uses your test to direct its search for the
    1.20  changeset that introduced the code that caused the bug.
    1.21  
    1.22 -Here are a few scenarios to help you understand how you might apply this
    1.23 -extension.
    1.24 +Here are a few scenarios to help you understand how you might apply
    1.25 +this command.
    1.26  \begin{itemize}
    1.27  \item The most recent version of your software has a bug that you
    1.28    remember wasn't present a few weeks ago, but you don't know when it
    1.29 @@ -515,8 +515,8 @@
    1.30    you build your project.
    1.31  \end{itemize}
    1.32  
    1.33 -From these examples, it should be clear that the \hgext{bisect}
    1.34 -extension is not useful only for finding the sources of bugs.  You can
    1.35 +From these examples, it should be clear that the \hgcmd{bisect}
    1.36 +command is not useful only for finding the sources of bugs.  You can
    1.37  use it to find any ``emergent property'' of a repository (anything
    1.38  that you can't find from a simple text search of the files in the
    1.39  tree) for which you can write a binary test.
    1.40 @@ -524,10 +524,10 @@
    1.41  We'll introduce a little bit of terminology here, just to make it
    1.42  clear which parts of the search process are your responsibility, and
    1.43  which are Mercurial's.  A \emph{test} is something that \emph{you} run
    1.44 -when \hgext{bisect} chooses a changeset.  A \emph{probe} is what
    1.45 -\hgext{bisect} runs to tell whether a revision is good.  Finally,
    1.46 +when \hgcmd{bisect} chooses a changeset.  A \emph{probe} is what
    1.47 +\hgcmd{bisect} runs to tell whether a revision is good.  Finally,
    1.48  we'll use the word ``bisect'', as both a noun and a verb, to stand in
    1.49 -for the phrase ``search using the \hgext{bisect} extension''.
    1.50 +for the phrase ``search using the \hgcmd{bisect} command.
    1.51  
    1.52  One simple way to automate the searching process would be simply to
    1.53  probe every changeset.  However, this scales poorly.  If it took ten
    1.54 @@ -538,47 +538,33 @@
    1.55  and limited your search to those, you'd still be looking at over 40
    1.56  hours to find the changeset that introduced your bug.
    1.57  
    1.58 -What the \emph{bisect} extension does is use its knowledge of the
    1.59 +What the \hgcmd{bisect} command does is use its knowledge of the
    1.60  ``shape'' of your project's revision history to perform a search in
    1.61  time proportional to the \emph{logarithm} of the number of changesets
    1.62  to check (the kind of search it performs is called a dichotomic
    1.63  search).  With this approach, searching through 10,000 changesets will
    1.64 -take less than two hours, even at ten minutes per test.  Limit your
    1.65 -search to the last 500 changesets, and it will take less than an hour.
    1.66 -
    1.67 -The \hgext{bisect} extension is aware of the ``branchy'' nature of a
    1.68 +take less than three hours, even at ten minutes per test (the search
    1.69 +will require about 14 tests).  Limit your search to the last hundred
    1.70 +changesets, and it will take only about an hour (roughly seven tests).
    1.71 +
    1.72 +The \hgcmd{bisect} command is aware of the ``branchy'' nature of a
    1.73  Mercurial project's revision history, so it has no problems dealing
    1.74  with branches, merges, or multiple heads in a repoository.  It can
    1.75  prune entire branches of history with a single probe, which is how it
    1.76  operates so efficiently.
    1.77  
    1.78 -\subsection{Using the \hgext{bisect} extension}
    1.79 -
    1.80 -Here's an example of \hgext{bisect} in action.  To keep the core of
    1.81 -Mercurial simple, \hgext{bisect} is packaged as an extension; this
    1.82 -means that it won't be present unless you explicitly enable it.  To do
    1.83 -this, edit your \hgrc\ and add the following section header (if it's
    1.84 -not already present):
    1.85 -\begin{codesample2}
    1.86 -  [extensions]
    1.87 -\end{codesample2}
    1.88 -Then add a line to this section to enable the extension:
    1.89 -\begin{codesample2}
    1.90 -  hbisect =
    1.91 -\end{codesample2}
    1.92 +\subsection{Using the \hgcmd{bisect} command}
    1.93 +
    1.94 +Here's an example of \hgcmd{bisect} in action.
    1.95 +
    1.96  \begin{note}
    1.97 -  That's right, there's a ``\texttt{h}'' at the front of the name of
    1.98 -  the \hgext{bisect} extension.  The reason is that Mercurial is
    1.99 -  written in Python, and uses a standard Python package called
   1.100 -  \texttt{bisect}.  If you omit the ``\texttt{h}'' from the name
   1.101 -  ``\texttt{hbisect}'', Mercurial will erroneously find the standard
   1.102 -  Python \texttt{bisect} package, and try to use it as a Mercurial
   1.103 -  extension.  This won't work, and Mercurial will crash repeatedly
   1.104 -  until you fix the spelling in your \hgrc.  Ugh.
   1.105 +  In versions 0.9.5 and earlier of Mercurial, \hgcmd{bisect} was not a
   1.106 +  core command: it was distributed with Mercurial as an extension.
   1.107 +  This section describes the built-in command, not the old extension.
   1.108  \end{note}
   1.109  
   1.110  Now let's create a repository, so that we can try out the
   1.111 -\hgext{bisect} extension in isolation.
   1.112 +\hgcmd{bisect} command in isolation.
   1.113  \interaction{bisect.init}
   1.114  We'll simulate a project that has a bug in it in a simple-minded way:
   1.115  create trivial changes in a loop, and nominate one specific change
   1.116 @@ -588,29 +574,28 @@
   1.117  \interaction{bisect.commits}
   1.118  
   1.119  The next thing that we'd like to do is figure out how to use the
   1.120 -\hgext{bisect} extension.  We can use Mercurial's normal built-in help
   1.121 +\hgcmd{bisect} command.  We can use Mercurial's normal built-in help
   1.122  mechanism for this.
   1.123  \interaction{bisect.help}
   1.124  
   1.125 -The \hgext{bisect} extension works in steps.  Each step proceeds as follows.
   1.126 +The \hgcmd{bisect} command works in steps.  Each step proceeds as follows.
   1.127  \begin{enumerate}
   1.128  \item You run your binary test.
   1.129    \begin{itemize}
   1.130 -  \item If the test succeeded, you tell \hgext{bisect} by running the
   1.131 +  \item If the test succeeded, you tell \hgcmd{bisect} by running the
   1.132      \hgcmdargs{bisect}{good} command.
   1.133 -  \item If it failed, use the \hgcmdargs{bisect}{bad} command to let
   1.134 -    the \hgext{bisect} extension know.
   1.135 +  \item If it failed, run the \hgcmdargs{bisect}{--bad} command.
   1.136    \end{itemize}
   1.137 -\item The extension uses your information to decide which changeset to
   1.138 +\item The command uses your information to decide which changeset to
   1.139    test next.
   1.140  \item It updates the working directory to that changeset, and the
   1.141    process begins again.
   1.142  \end{enumerate}
   1.143 -The process ends when \hgext{bisect} identifies a unique changeset
   1.144 +The process ends when \hgcmd{bisect} identifies a unique changeset
   1.145  that marks the point where your test transitioned from ``succeeding''
   1.146  to ``failing''.
   1.147  
   1.148 -To start the search, we must run the \hgcmdargs{bisect}{init} command.
   1.149 +To start the search, we must run the \hgcmdargs{bisect}{--reset} command.
   1.150  \interaction{bisect.search.init}
   1.151  
   1.152  In our case, the binary test we use is simple: we check to see if any
   1.153 @@ -625,7 +610,7 @@
   1.154  \interaction{bisect.search.bad-init}
   1.155  
   1.156  Our next task is to nominate a changeset that we know \emph{doesn't}
   1.157 -have the bug; the \hgext{bisect} extension will ``bracket'' its search
   1.158 +have the bug; the \hgcmd{bisect} command will ``bracket'' its search
   1.159  between the first pair of good and bad changesets.  In our case, we
   1.160  know that revision~10 didn't have the bug.  (I'll have more words
   1.161  about choosing the first ``good'' changeset later.)
   1.162 @@ -656,20 +641,20 @@
   1.163  done.
   1.164  \interaction{bisect.search.rest}
   1.165  
   1.166 -Even though we had~40 changesets to search through, the \hgext{bisect}
   1.167 -extension let us find the changeset that introduced our ``bug'' with
   1.168 -only five tests.  Because the number of tests that the \hgext{bisect}
   1.169 -extension grows logarithmically with the number of changesets to
   1.170 +Even though we had~40 changesets to search through, the \hgcmd{bisect}
   1.171 +command let us find the changeset that introduced our ``bug'' with
   1.172 +only five tests.  Because the number of tests that the \hgcmd{bisect}
   1.173 +command grows logarithmically with the number of changesets to
   1.174  search, the advantage that it has over the ``brute force'' search
   1.175  approach increases with every changeset you add.
   1.176  
   1.177  \subsection{Cleaning up after your search}
   1.178  
   1.179 -When you're finished using the \hgext{bisect} extension in a
   1.180 +When you're finished using the \hgcmd{bisect} command in a
   1.181  repository, you can use the \hgcmdargs{bisect}{reset} command to drop
   1.182 -the information it was using to drive your search.  The extension
   1.183 +the information it was using to drive your search.  The command
   1.184  doesn't use much space, so it doesn't matter if you forget to run this
   1.185 -command.  However, \hgext{bisect} won't let you start a new search in
   1.186 +command.  However, \hgcmd{bisect} won't let you start a new search in
   1.187  that repository until you do a \hgcmdargs{bisect}{reset}.
   1.188  \interaction{bisect.search.reset}
   1.189  
   1.190 @@ -677,7 +662,7 @@
   1.191  
   1.192  \subsection{Give consistent input}
   1.193  
   1.194 -The \hgext{bisect} extension requires that you correctly report the
   1.195 +The \hgcmd{bisect} command requires that you correctly report the
   1.196  result of every test you perform.  If you tell it that a test failed
   1.197  when it really succeeded, it \emph{might} be able to detect the
   1.198  inconsistency.  If it can identify an inconsistency in your reports,
   1.199 @@ -687,16 +672,16 @@
   1.200  
   1.201  \subsection{Automate as much as possible}
   1.202  
   1.203 -When I started using the \hgext{bisect} extension, I tried a few times
   1.204 +When I started using the \hgcmd{bisect} command, I tried a few times
   1.205  to run my tests by hand, on the command line.  This is an approach
   1.206  that I, at least, am not suited to.  After a few tries, I found that I
   1.207  was making enough mistakes that I was having to restart my searches
   1.208 -several times before finally getting correct results.  
   1.209 -
   1.210 -My initial problems with driving the \hgext{bisect} extension by hand
   1.211 +several times before finally getting correct results.
   1.212 +
   1.213 +My initial problems with driving the \hgcmd{bisect} command by hand
   1.214  occurred even with simple searches on small repositories; if the
   1.215  problem you're looking for is more subtle, or the number of tests that
   1.216 -\hgext{bisect} must perform increases, the likelihood of operator
   1.217 +\hgcmd{bisect} must perform increases, the likelihood of operator
   1.218  error ruining the search is much higher.  Once I started automating my
   1.219  tests, I had much better results.
   1.220  
   1.221 @@ -713,7 +698,7 @@
   1.222  
   1.223  \subsection{Check your results}
   1.224  
   1.225 -Because the output of a \hgext{bisect} search is only as good as the
   1.226 +Because the output of a \hgcmd{bisect} search is only as good as the
   1.227  input you give it, don't take the changeset it reports as the
   1.228  absolute truth.  A simple way to cross-check its report is to manually
   1.229  run your test at each of the following changesets:
   1.230 @@ -739,26 +724,30 @@
   1.231  is to say that it occurs before your bug has a chance to manifest
   1.232  itself.  If you can't avoid that other bug (for example, it prevents
   1.233  your project from building), and so can't tell whether your bug is
   1.234 -present in a particular changeset, the \hgext{bisect} extension cannot
   1.235 -help you directly.  Instead, you'll need to manually avoid the
   1.236 -changesets where that bug is present, and do separate searches
   1.237 -``around'' it.
   1.238 +present in a particular changeset, the \hgcmd{bisect} command cannot
   1.239 +help you directly.  Instead, you can mark a changeset as untested by
   1.240 +running \hgcmdargs{bisect}{--skip}.
   1.241  
   1.242  A different problem could arise if your test for a bug's presence is
   1.243  not specific enough.  If you check for ``my program crashes'', then
   1.244  both your crashing bug and an unrelated crashing bug that masks it
   1.245 -will look like the same thing, and mislead \hgext{bisect}.
   1.246 +will look like the same thing, and mislead \hgcmd{bisect}.
   1.247 +
   1.248 +Another useful situation in which to use \hgcmdargs{bisect}{--skip} is
   1.249 +if you can't test a revision because your project was in a broken and
   1.250 +hence untestable state at that revision, perhaps because someone
   1.251 +checked in a change that prevented the project from building.
   1.252  
   1.253  \subsection{Bracket your search lazily}
   1.254  
   1.255  Choosing the first ``good'' and ``bad'' changesets that will mark the
   1.256  end points of your search is often easy, but it bears a little
   1.257 -discussion nevertheless.  From the perspective of \hgext{bisect}, the
   1.258 +discussion nevertheless.  From the perspective of \hgcmd{bisect}, the
   1.259  ``newest'' changeset is conventionally ``bad'', and the older
   1.260  changeset is ``good''.
   1.261  
   1.262  If you're having trouble remembering when a suitable ``good'' change
   1.263 -was, so that you can tell \hgext{bisect}, you could do worse than
   1.264 +was, so that you can tell \hgcmd{bisect}, you could do worse than
   1.265  testing changesets at random.  Just remember to eliminate contenders
   1.266  that can't possibly exhibit the bug (perhaps because the feature with
   1.267  the bug isn't present yet) and those where another problem masks the
   1.268 @@ -766,7 +755,7 @@
   1.269  
   1.270  Even if you end up ``early'' by thousands of changesets or months of
   1.271  history, you will only add a handful of tests to the total number that
   1.272 -\hgext{bisect} must perform, thanks to its logarithmic behaviour.
   1.273 +\hgcmd{bisect} must perform, thanks to its logarithmic behaviour.
   1.274  
   1.275  %%% Local Variables: 
   1.276  %%% mode: latex