hgbook

diff fr/tour-basic.tex @ 923:0d08ac613527

Beginning translation work on 'intro.text'
author Romain PELISSE <romain.pelisse@atosorigin.com>
date Fri Feb 06 15:31:26 2009 +0100 (2009-02-06)
parents 1d277d6aa187
children 9968b0ed4a38
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/fr/tour-basic.tex	Fri Feb 06 15:31:26 2009 +0100
     1.3 @@ -0,0 +1,624 @@
     1.4 +\chapter{A tour of Mercurial: the basics}
     1.5 +\label{chap:tour-basic}
     1.6 +
     1.7 +\section{Installing Mercurial on your system}
     1.8 +\label{sec:tour:install}
     1.9 +
    1.10 +Prebuilt binary packages of Mercurial are available for every popular
    1.11 +operating system.  These make it easy to start using Mercurial on your
    1.12 +computer immediately.
    1.13 +
    1.14 +\subsection{Linux}
    1.15 +
    1.16 +Because each Linux distribution has its own packaging tools, policies,
    1.17 +and rate of development, it's difficult to give a comprehensive set of
    1.18 +instructions on how to install Mercurial binaries.  The version of
    1.19 +Mercurial that you will end up with can vary depending on how active
    1.20 +the person is who maintains the package for your distribution.
    1.21 +
    1.22 +To keep things simple, I will focus on installing Mercurial from the
    1.23 +command line under the most popular Linux distributions.  Most of
    1.24 +these distributions provide graphical package managers that will let
    1.25 +you install Mercurial with a single click; the package name to look
    1.26 +for is \texttt{mercurial}.
    1.27 +
    1.28 +\begin{itemize}
    1.29 +\item[Debian]
    1.30 +  \begin{codesample4}
    1.31 +    apt-get install mercurial
    1.32 +  \end{codesample4}
    1.33 +
    1.34 +\item[Fedora Core]
    1.35 +  \begin{codesample4}
    1.36 +    yum install mercurial
    1.37 +  \end{codesample4}
    1.38 +
    1.39 +\item[Gentoo]
    1.40 +  \begin{codesample4}
    1.41 +    emerge mercurial
    1.42 +  \end{codesample4}
    1.43 +
    1.44 +\item[OpenSUSE]
    1.45 +  \begin{codesample4}
    1.46 +    yum install mercurial
    1.47 +  \end{codesample4}
    1.48 +
    1.49 +\item[Ubuntu] Ubuntu's Mercurial package is based on Debian's.  To
    1.50 +  install it, run the following command.
    1.51 +  \begin{codesample4}
    1.52 +    apt-get install mercurial
    1.53 +  \end{codesample4}
    1.54 +  The Ubuntu package for Mercurial tends to lag behind the Debian
    1.55 +  version by a considerable time margin (at the time of writing, seven
    1.56 +  months), which in some cases will mean that on Ubuntu, you may run
    1.57 +  into problems that have since been fixed in the Debian package.
    1.58 +\end{itemize}
    1.59 +
    1.60 +\subsection{Solaris}
    1.61 +
    1.62 +SunFreeWare, at \url{http://www.sunfreeware.com}, is a good source for a
    1.63 +large number of pre-built Solaris packages for 32 and 64 bit Intel and
    1.64 +Sparc architectures, including current versions of Mercurial.
    1.65 +
    1.66 +\subsection{Mac OS X}
    1.67 +
    1.68 +Lee Cantey publishes an installer of Mercurial for Mac OS~X at
    1.69 +\url{http://mercurial.berkwood.com}.  This package works on both
    1.70 +Intel-~and Power-based Macs.  Before you can use it, you must install
    1.71 +a compatible version of Universal MacPython~\cite{web:macpython}.  This
    1.72 +is easy to do; simply follow the instructions on Lee's site.
    1.73 +
    1.74 +It's also possible to install Mercurial using Fink or MacPorts,
    1.75 +two popular free package managers for Mac OS X.  If you have Fink,
    1.76 +use \command{sudo apt-get install mercurial-py25}.  If MacPorts,
    1.77 +\command{sudo port install mercurial}.
    1.78 +
    1.79 +\subsection{Windows}
    1.80 +
    1.81 +Lee Cantey publishes an installer of Mercurial for Windows at
    1.82 +\url{http://mercurial.berkwood.com}.  This package has no external
    1.83 +dependencies; it ``just works''.
    1.84 +
    1.85 +\begin{note}
    1.86 +  The Windows version of Mercurial does not automatically convert line
    1.87 +  endings between Windows and Unix styles.  If you want to share work
    1.88 +  with Unix users, you must do a little additional configuration
    1.89 +  work. XXX Flesh this out.
    1.90 +\end{note}
    1.91 +
    1.92 +\section{Getting started}
    1.93 +
    1.94 +To begin, we'll use the \hgcmd{version} command to find out whether
    1.95 +Mercurial is actually installed properly.  The actual version
    1.96 +information that it prints isn't so important; it's whether it prints
    1.97 +anything at all that we care about.
    1.98 +\interaction{tour.version}
    1.99 +
   1.100 +\subsection{Built-in help}
   1.101 +
   1.102 +Mercurial provides a built-in help system.  This is invaluable for those
   1.103 +times when you find yourself stuck trying to remember how to run a
   1.104 +command.  If you are completely stuck, simply run \hgcmd{help}; it
   1.105 +will print a brief list of commands, along with a description of what
   1.106 +each does.  If you ask for help on a specific command (as below), it
   1.107 +prints more detailed information.
   1.108 +\interaction{tour.help}
   1.109 +For a more impressive level of detail (which you won't usually need)
   1.110 +run \hgcmdargs{help}{\hggopt{-v}}.  The \hggopt{-v} option is short
   1.111 +for \hggopt{--verbose}, and tells Mercurial to print more information
   1.112 +than it usually would.
   1.113 +
   1.114 +\section{Working with a repository}
   1.115 +
   1.116 +In Mercurial, everything happens inside a \emph{repository}.  The
   1.117 +repository for a project contains all of the files that ``belong to''
   1.118 +that project, along with a historical record of the project's files.
   1.119 +
   1.120 +There's nothing particularly magical about a repository; it is simply
   1.121 +a directory tree in your filesystem that Mercurial treats as special.
   1.122 +You can rename or delete a repository any time you like, using either the
   1.123 +command line or your file browser.
   1.124 +
   1.125 +\subsection{Making a local copy of a repository}
   1.126 +
   1.127 +\emph{Copying} a repository is just a little bit special.  While you
   1.128 +could use a normal file copying command to make a copy of a
   1.129 +repository, it's best to use a built-in command that Mercurial
   1.130 +provides.  This command is called \hgcmd{clone}, because it creates an
   1.131 +identical copy of an existing repository.
   1.132 +\interaction{tour.clone}
   1.133 +If our clone succeeded, we should now have a local directory called
   1.134 +\dirname{hello}.  This directory will contain some files.
   1.135 +\interaction{tour.ls}
   1.136 +These files have the same contents and history in our repository as
   1.137 +they do in the repository we cloned.
   1.138 +
   1.139 +Every Mercurial repository is complete, self-contained, and
   1.140 +independent.  It contains its own private copy of a project's files
   1.141 +and history.  A cloned repository remembers the location of the
   1.142 +repository it was cloned from, but it does not communicate with that
   1.143 +repository, or any other, unless you tell it to.
   1.144 +
   1.145 +What this means for now is that we're free to experiment with our
   1.146 +repository, safe in the knowledge that it's a private ``sandbox'' that
   1.147 +won't affect anyone else.
   1.148 +
   1.149 +\subsection{What's in a repository?}
   1.150 +
   1.151 +When we take a more detailed look inside a repository, we can see that
   1.152 +it contains a directory named \dirname{.hg}.  This is where Mercurial
   1.153 +keeps all of its metadata for the repository.
   1.154 +\interaction{tour.ls-a}
   1.155 +
   1.156 +The contents of the \dirname{.hg} directory and its subdirectories are
   1.157 +private to Mercurial.  Every other file and directory in the
   1.158 +repository is yours to do with as you please.
   1.159 +
   1.160 +To introduce a little terminology, the \dirname{.hg} directory is the
   1.161 +``real'' repository, and all of the files and directories that coexist
   1.162 +with it are said to live in the \emph{working directory}.  An easy way
   1.163 +to remember the distinction is that the \emph{repository} contains the
   1.164 +\emph{history} of your project, while the \emph{working directory}
   1.165 +contains a \emph{snapshot} of your project at a particular point in
   1.166 +history.
   1.167 +
   1.168 +\section{A tour through history}
   1.169 +
   1.170 +One of the first things we might want to do with a new, unfamiliar
   1.171 +repository is understand its history.  The \hgcmd{log} command gives
   1.172 +us a view of history.
   1.173 +\interaction{tour.log}
   1.174 +By default, this command prints a brief paragraph of output for each
   1.175 +change to the project that was recorded.  In Mercurial terminology, we
   1.176 +call each of these recorded events a \emph{changeset}, because it can
   1.177 +contain a record of changes to several files.
   1.178 +
   1.179 +The fields in a record of output from \hgcmd{log} are as follows.
   1.180 +\begin{itemize}
   1.181 +\item[\texttt{changeset}] This field has the format of a number,
   1.182 +  followed by a colon, followed by a hexadecimal string.  These are
   1.183 +  \emph{identifiers} for the changeset.  There are two identifiers
   1.184 +  because the number is shorter and easier to type than the hex
   1.185 +  string.
   1.186 +\item[\texttt{user}] The identity of the person who created the
   1.187 +  changeset.  This is a free-form field, but it most often contains a
   1.188 +  person's name and email address.
   1.189 +\item[\texttt{date}] The date and time on which the changeset was
   1.190 +  created, and the timezone in which it was created.  (The date and
   1.191 +  time are local to that timezone; they display what time and date it
   1.192 +  was for the person who created the changeset.)
   1.193 +\item[\texttt{summary}] The first line of the text message that the
   1.194 +  creator of the changeset entered to describe the changeset.
   1.195 +\end{itemize}
   1.196 +The default output printed by \hgcmd{log} is purely a summary; it is
   1.197 +missing a lot of detail.
   1.198 +
   1.199 +Figure~\ref{fig:tour-basic:history} provides a graphical representation of
   1.200 +the history of the \dirname{hello} repository, to make it a little
   1.201 +easier to see which direction history is ``flowing'' in.  We'll be
   1.202 +returning to this figure several times in this chapter and the chapter
   1.203 +that follows.
   1.204 +
   1.205 +\begin{figure}[ht]
   1.206 +  \centering
   1.207 +  \grafix{tour-history}
   1.208 +  \caption{Graphical history of the \dirname{hello} repository}
   1.209 +  \label{fig:tour-basic:history}
   1.210 +\end{figure}
   1.211 +
   1.212 +\subsection{Changesets, revisions, and talking to other 
   1.213 +  people}
   1.214 +
   1.215 +As English is a notoriously sloppy language, and computer science has
   1.216 +a hallowed history of terminological confusion (why use one term when
   1.217 +four will do?), revision control has a variety of words and phrases
   1.218 +that mean the same thing.  If you are talking about Mercurial history
   1.219 +with other people, you will find that the word ``changeset'' is often
   1.220 +compressed to ``change'' or (when written) ``cset'', and sometimes a
   1.221 +changeset is referred to as a ``revision'' or a ``rev''.
   1.222 +
   1.223 +While it doesn't matter what \emph{word} you use to refer to the
   1.224 +concept of ``a~changeset'', the \emph{identifier} that you use to
   1.225 +refer to ``a~\emph{specific} changeset'' is of great importance.
   1.226 +Recall that the \texttt{changeset} field in the output from
   1.227 +\hgcmd{log} identifies a changeset using both a number and a
   1.228 +hexadecimal string.
   1.229 +\begin{itemize}
   1.230 +\item The revision number is \emph{only valid in that repository},
   1.231 +\item while the hex string is the \emph{permanent, unchanging
   1.232 +    identifier} that will always identify that exact changeset in
   1.233 +  \emph{every} copy of the repository.
   1.234 +\end{itemize}
   1.235 +This distinction is important.  If you send someone an email talking
   1.236 +about ``revision~33'', there's a high likelihood that their
   1.237 +revision~33 will \emph{not be the same} as yours.  The reason for this
   1.238 +is that a revision number depends on the order in which changes
   1.239 +arrived in a repository, and there is no guarantee that the same
   1.240 +changes will happen in the same order in different repositories.
   1.241 +Three changes $a,b,c$ can easily appear in one repository as $0,1,2$,
   1.242 +while in another as $1,0,2$.
   1.243 +
   1.244 +Mercurial uses revision numbers purely as a convenient shorthand.  If
   1.245 +you need to discuss a changeset with someone, or make a record of a
   1.246 +changeset for some other reason (for example, in a bug report), use
   1.247 +the hexadecimal identifier.
   1.248 +
   1.249 +\subsection{Viewing specific revisions}
   1.250 +
   1.251 +To narrow the output of \hgcmd{log} down to a single revision, use the
   1.252 +\hgopt{log}{-r} (or \hgopt{log}{--rev}) option.  You can use either a
   1.253 +revision number or a long-form changeset identifier, and you can
   1.254 +provide as many revisions as you want.  \interaction{tour.log-r}
   1.255 +
   1.256 +If you want to see the history of several revisions without having to
   1.257 +list each one, you can use \emph{range notation}; this lets you
   1.258 +express the idea ``I want all revisions between $a$ and $b$,
   1.259 +inclusive''.
   1.260 +\interaction{tour.log.range}
   1.261 +Mercurial also honours the order in which you specify revisions, so
   1.262 +\hgcmdargs{log}{-r 2:4} prints $2,3,4$ while \hgcmdargs{log}{-r 4:2}
   1.263 +prints $4,3,2$.
   1.264 +
   1.265 +\subsection{More detailed information}
   1.266 +
   1.267 +While the summary information printed by \hgcmd{log} is useful if you
   1.268 +already know what you're looking for, you may need to see a complete
   1.269 +description of the change, or a list of the files changed, if you're
   1.270 +trying to decide whether a changeset is the one you're looking for.
   1.271 +The \hgcmd{log} command's \hggopt{-v} (or \hggopt{--verbose})
   1.272 +option gives you this extra detail.
   1.273 +\interaction{tour.log-v}
   1.274 +
   1.275 +If you want to see both the description and content of a change, add
   1.276 +the \hgopt{log}{-p} (or \hgopt{log}{--patch}) option.  This displays
   1.277 +the content of a change as a \emph{unified diff} (if you've never seen
   1.278 +a unified diff before, see section~\ref{sec:mq:patch} for an overview).
   1.279 +\interaction{tour.log-vp}
   1.280 +
   1.281 +\section{All about command options}
   1.282 +
   1.283 +Let's take a brief break from exploring Mercurial commands to discuss
   1.284 +a pattern in the way that they work; you may find this useful to keep
   1.285 +in mind as we continue our tour.
   1.286 +
   1.287 +Mercurial has a consistent and straightforward approach to dealing
   1.288 +with the options that you can pass to commands.  It follows the
   1.289 +conventions for options that are common to modern Linux and Unix
   1.290 +systems.
   1.291 +\begin{itemize}
   1.292 +\item Every option has a long name.  For example, as we've already
   1.293 +  seen, the \hgcmd{log} command accepts a \hgopt{log}{--rev} option.
   1.294 +\item Most options have short names, too.  Instead of
   1.295 +  \hgopt{log}{--rev}, we can use \hgopt{log}{-r}.  (The reason that
   1.296 +  some options don't have short names is that the options in question
   1.297 +  are rarely used.)
   1.298 +\item Long options start with two dashes (e.g.~\hgopt{log}{--rev}),
   1.299 +  while short options start with one (e.g.~\hgopt{log}{-r}).
   1.300 +\item Option naming and usage is consistent across commands.  For
   1.301 +  example, every command that lets you specify a changeset~ID or
   1.302 +  revision number accepts both \hgopt{log}{-r} and \hgopt{log}{--rev}
   1.303 +  arguments.
   1.304 +\end{itemize}
   1.305 +In the examples throughout this book, I use short options instead of
   1.306 +long.  This just reflects my own preference, so don't read anything
   1.307 +significant into it.
   1.308 +
   1.309 +Most commands that print output of some kind will print more output
   1.310 +when passed a \hggopt{-v} (or \hggopt{--verbose}) option, and less
   1.311 +when passed \hggopt{-q} (or \hggopt{--quiet}).
   1.312 +
   1.313 +\section{Making and reviewing changes}
   1.314 +
   1.315 +Now that we have a grasp of viewing history in Mercurial, let's take a
   1.316 +look at making some changes and examining them.
   1.317 +
   1.318 +The first thing we'll do is isolate our experiment in a repository of
   1.319 +its own.  We use the \hgcmd{clone} command, but we don't need to
   1.320 +clone a copy of the remote repository.  Since we already have a copy
   1.321 +of it locally, we can just clone that instead.  This is much faster
   1.322 +than cloning over the network, and cloning a local repository uses
   1.323 +less disk space in most cases, too.
   1.324 +\interaction{tour.reclone}
   1.325 +As an aside, it's often good practice to keep a ``pristine'' copy of a
   1.326 +remote repository around, which you can then make temporary clones of
   1.327 +to create sandboxes for each task you want to work on.  This lets you
   1.328 +work on multiple tasks in parallel, each isolated from the others
   1.329 +until it's complete and you're ready to integrate it back.  Because
   1.330 +local clones are so cheap, there's almost no overhead to cloning and
   1.331 +destroying repositories whenever you want.
   1.332 +
   1.333 +In our \dirname{my-hello} repository, we have a file
   1.334 +\filename{hello.c} that contains the classic ``hello, world'' program.
   1.335 +Let's use the ancient and venerable \command{sed} command to edit this
   1.336 +file so that it prints a second line of output.  (I'm only using
   1.337 +\command{sed} to do this because it's easy to write a scripted example
   1.338 +this way.  Since you're not under the same constraint, you probably
   1.339 +won't want to use \command{sed}; simply use your preferred text editor to
   1.340 +do the same thing.)
   1.341 +\interaction{tour.sed}
   1.342 +
   1.343 +Mercurial's \hgcmd{status} command will tell us what Mercurial knows
   1.344 +about the files in the repository.
   1.345 +\interaction{tour.status}
   1.346 +The \hgcmd{status} command prints no output for some files, but a line
   1.347 +starting with ``\texttt{M}'' for \filename{hello.c}.  Unless you tell
   1.348 +it to, \hgcmd{status} will not print any output for files that have
   1.349 +not been modified.  
   1.350 +
   1.351 +The ``\texttt{M}'' indicates that Mercurial has noticed that we
   1.352 +modified \filename{hello.c}.  We didn't need to \emph{inform}
   1.353 +Mercurial that we were going to modify the file before we started, or
   1.354 +that we had modified the file after we were done; it was able to
   1.355 +figure this out itself.
   1.356 +
   1.357 +It's a little bit helpful to know that we've modified
   1.358 +\filename{hello.c}, but we might prefer to know exactly \emph{what}
   1.359 +changes we've made to it.  To do this, we use the \hgcmd{diff}
   1.360 +command.
   1.361 +\interaction{tour.diff}
   1.362 +
   1.363 +\section{Recording changes in a new changeset}
   1.364 +
   1.365 +We can modify files, build and test our changes, and use
   1.366 +\hgcmd{status} and \hgcmd{diff} to review our changes, until we're
   1.367 +satisfied with what we've done and arrive at a natural stopping point
   1.368 +where we want to record our work in a new changeset.
   1.369 +
   1.370 +The \hgcmd{commit} command lets us create a new changeset; we'll
   1.371 +usually refer to this as ``making a commit'' or ``committing''.  
   1.372 +
   1.373 +\subsection{Setting up a username}
   1.374 +
   1.375 +When you try to run \hgcmd{commit} for the first time, it is not
   1.376 +guaranteed to succeed.  Mercurial records your name and address with
   1.377 +each change that you commit, so that you and others will later be able
   1.378 +to tell who made each change.  Mercurial tries to automatically figure
   1.379 +out a sensible username to commit the change with.  It will attempt
   1.380 +each of the following methods, in order:
   1.381 +\begin{enumerate}
   1.382 +\item If you specify a \hgopt{commit}{-u} option to the \hgcmd{commit}
   1.383 +  command on the command line, followed by a username, this is always
   1.384 +  given the highest precedence.
   1.385 +\item If you have set the \envar{HGUSER} environment variable, this is
   1.386 +  checked next.
   1.387 +\item If you create a file in your home directory called
   1.388 +  \sfilename{.hgrc}, with a \rcitem{ui}{username} entry, that will be
   1.389 +  used next.  To see what the contents of this file should look like,
   1.390 +  refer to section~\ref{sec:tour-basic:username} below.
   1.391 +\item If you have set the \envar{EMAIL} environment variable, this
   1.392 +  will be used next.
   1.393 +\item Mercurial will query your system to find out your local user
   1.394 +  name and host name, and construct a username from these components.
   1.395 +  Since this often results in a username that is not very useful, it
   1.396 +  will print a warning if it has to do this.
   1.397 +\end{enumerate}
   1.398 +If all of these mechanisms fail, Mercurial will fail, printing an
   1.399 +error message.  In this case, it will not let you commit until you set
   1.400 +up a username.
   1.401 +
   1.402 +You should think of the \envar{HGUSER} environment variable and the
   1.403 +\hgopt{commit}{-u} option to the \hgcmd{commit} command as ways to
   1.404 +\emph{override} Mercurial's default selection of username.  For normal
   1.405 +use, the simplest and most robust way to set a username for yourself
   1.406 +is by creating a \sfilename{.hgrc} file; see below for details.
   1.407 +
   1.408 +\subsubsection{Creating a Mercurial configuration file}
   1.409 +\label{sec:tour-basic:username}
   1.410 +
   1.411 +To set a user name, use your favourite editor to create a file called
   1.412 +\sfilename{.hgrc} in your home directory.  Mercurial will use this
   1.413 +file to look up your personalised configuration settings.  The initial
   1.414 +contents of your \sfilename{.hgrc} should look like this.
   1.415 +\begin{codesample2}
   1.416 +  # This is a Mercurial configuration file.
   1.417 +  [ui]
   1.418 +  username = Firstname Lastname <email.address@domain.net>
   1.419 +\end{codesample2}
   1.420 +The ``\texttt{[ui]}'' line begins a \emph{section} of the config file,
   1.421 +so you can read the ``\texttt{username = ...}'' line as meaning ``set
   1.422 +the value of the \texttt{username} item in the \texttt{ui} section''.
   1.423 +A section continues until a new section begins, or the end of the
   1.424 +file.  Mercurial ignores empty lines and treats any text from
   1.425 +``\texttt{\#}'' to the end of a line as a comment.
   1.426 +
   1.427 +\subsubsection{Choosing a user name}
   1.428 +
   1.429 +You can use any text you like as the value of the \texttt{username}
   1.430 +config item, since this information is for reading by other people,
   1.431 +but for interpreting by Mercurial.  The convention that most people
   1.432 +follow is to use their name and email address, as in the example
   1.433 +above.
   1.434 +
   1.435 +\begin{note}
   1.436 +  Mercurial's built-in web server obfuscates email addresses, to make
   1.437 +  it more difficult for the email harvesting tools that spammers use.
   1.438 +  This reduces the likelihood that you'll start receiving more junk
   1.439 +  email if you publish a Mercurial repository on the web.
   1.440 +\end{note}
   1.441 +
   1.442 +\subsection{Writing a commit message}
   1.443 +
   1.444 +When we commit a change, Mercurial drops us into a text editor, to
   1.445 +enter a message that will describe the modifications we've made in
   1.446 +this changeset.  This is called the \emph{commit message}.  It will be
   1.447 +a record for readers of what we did and why, and it will be printed by
   1.448 +\hgcmd{log} after we've finished committing.
   1.449 +\interaction{tour.commit}
   1.450 +
   1.451 +The editor that the \hgcmd{commit} command drops us into will contain
   1.452 +an empty line, followed by a number of lines starting with
   1.453 +``\texttt{HG:}''.
   1.454 +\begin{codesample2}
   1.455 +  \emph{empty line}
   1.456 +  HG: changed hello.c
   1.457 +\end{codesample2}
   1.458 +Mercurial ignores the lines that start with ``\texttt{HG:}''; it uses
   1.459 +them only to tell us which files it's recording changes to.  Modifying
   1.460 +or deleting these lines has no effect.
   1.461 +
   1.462 +\subsection{Writing a good commit message}
   1.463 +
   1.464 +Since \hgcmd{log} only prints the first line of a commit message by
   1.465 +default, it's best to write a commit message whose first line stands
   1.466 +alone.  Here's a real example of a commit message that \emph{doesn't}
   1.467 +follow this guideline, and hence has a summary that is not readable.
   1.468 +\begin{codesample2}
   1.469 +  changeset:   73:584af0e231be
   1.470 +  user:        Censored Person <censored.person@example.org>
   1.471 +  date:        Tue Sep 26 21:37:07 2006 -0700
   1.472 +  summary:     include buildmeister/commondefs.   Add an exports and install
   1.473 +\end{codesample2}
   1.474 +
   1.475 +As far as the remainder of the contents of the commit message are
   1.476 +concerned, there are no hard-and-fast rules.  Mercurial itself doesn't
   1.477 +interpret or care about the contents of the commit message, though
   1.478 +your project may have policies that dictate a certain kind of
   1.479 +formatting.
   1.480 +
   1.481 +My personal preference is for short, but informative, commit messages
   1.482 +that tell me something that I can't figure out with a quick glance at
   1.483 +the output of \hgcmdargs{log}{--patch}.
   1.484 +
   1.485 +\subsection{Aborting a commit}
   1.486 +
   1.487 +If you decide that you don't want to commit while in the middle of
   1.488 +editing a commit message, simply exit from your editor without saving
   1.489 +the file that it's editing.  This will cause nothing to happen to
   1.490 +either the repository or the working directory.
   1.491 +
   1.492 +If we run the \hgcmd{commit} command without any arguments, it records
   1.493 +all of the changes we've made, as reported by \hgcmd{status} and
   1.494 +\hgcmd{diff}.
   1.495 +
   1.496 +\subsection{Admiring our new handiwork}
   1.497 +
   1.498 +Once we've finished the commit, we can use the \hgcmd{tip} command to
   1.499 +display the changeset we just created.  This command produces output
   1.500 +that is identical to \hgcmd{log}, but it only displays the newest
   1.501 +revision in the repository.
   1.502 +\interaction{tour.tip}
   1.503 +We refer to the newest revision in the repository as the tip revision,
   1.504 +or simply the tip.
   1.505 +
   1.506 +\section{Sharing changes}
   1.507 +
   1.508 +We mentioned earlier that repositories in Mercurial are
   1.509 +self-contained.  This means that the changeset we just created exists
   1.510 +only in our \dirname{my-hello} repository.  Let's look at a few ways
   1.511 +that we can propagate this change into other repositories.
   1.512 +
   1.513 +\subsection{Pulling changes from another repository}
   1.514 +\label{sec:tour:pull}
   1.515 +
   1.516 +To get started, let's clone our original \dirname{hello} repository,
   1.517 +which does not contain the change we just committed.  We'll call our
   1.518 +temporary repository \dirname{hello-pull}.
   1.519 +\interaction{tour.clone-pull}
   1.520 +
   1.521 +We'll use the \hgcmd{pull} command to bring changes from
   1.522 +\dirname{my-hello} into \dirname{hello-pull}.  However, blindly
   1.523 +pulling unknown changes into a repository is a somewhat scary
   1.524 +prospect.  Mercurial provides the \hgcmd{incoming} command to tell us
   1.525 +what changes the \hgcmd{pull} command \emph{would} pull into the
   1.526 +repository, without actually pulling the changes in.
   1.527 +\interaction{tour.incoming}
   1.528 +(Of course, someone could cause more changesets to appear in the
   1.529 +repository that we ran \hgcmd{incoming} in, before we get a chance to
   1.530 +\hgcmd{pull} the changes, so that we could end up pulling changes that we
   1.531 +didn't expect.)
   1.532 +
   1.533 +Bringing changes into a repository is a simple matter of running the
   1.534 +\hgcmd{pull} command, and telling it which repository to pull from.
   1.535 +\interaction{tour.pull}
   1.536 +As you can see from the before-and-after output of \hgcmd{tip}, we
   1.537 +have successfully pulled changes into our repository.  There remains
   1.538 +one step before we can see these changes in the working directory.
   1.539 +
   1.540 +\subsection{Updating the working directory}
   1.541 +
   1.542 +We have so far glossed over the relationship between a repository and
   1.543 +its working directory.  The \hgcmd{pull} command that we ran in
   1.544 +section~\ref{sec:tour:pull} brought changes into the repository, but
   1.545 +if we check, there's no sign of those changes in the working
   1.546 +directory.  This is because \hgcmd{pull} does not (by default) touch
   1.547 +the working directory.  Instead, we use the \hgcmd{update} command to
   1.548 +do this.
   1.549 +\interaction{tour.update}
   1.550 +
   1.551 +It might seem a bit strange that \hgcmd{pull} doesn't update the
   1.552 +working directory automatically.  There's actually a good reason for
   1.553 +this: you can use \hgcmd{update} to update the working directory to
   1.554 +the state it was in at \emph{any revision} in the history of the
   1.555 +repository.  If you had the working directory updated to an old
   1.556 +revision---to hunt down the origin of a bug, say---and ran a
   1.557 +\hgcmd{pull} which automatically updated the working directory to a
   1.558 +new revision, you might not be terribly happy.
   1.559 +
   1.560 +However, since pull-then-update is such a common thing to do,
   1.561 +Mercurial lets you combine the two by passing the \hgopt{pull}{-u}
   1.562 +option to \hgcmd{pull}.
   1.563 +\begin{codesample2}
   1.564 +  hg pull -u
   1.565 +\end{codesample2}
   1.566 +If you look back at the output of \hgcmd{pull} in
   1.567 +section~\ref{sec:tour:pull} when we ran it without \hgopt{pull}{-u},
   1.568 +you can see that it printed a helpful reminder that we'd have to take
   1.569 +an explicit step to update the working directory:
   1.570 +\begin{codesample2}
   1.571 +  (run 'hg update' to get a working copy)
   1.572 +\end{codesample2}
   1.573 +
   1.574 +To find out what revision the working directory is at, use the
   1.575 +\hgcmd{parents} command.
   1.576 +\interaction{tour.parents}
   1.577 +If you look back at figure~\ref{fig:tour-basic:history}, you'll see
   1.578 +arrows connecting each changeset.  The node that the arrow leads
   1.579 +\emph{from} in each case is a parent, and the node that the arrow
   1.580 +leads \emph{to} is its child.  The working directory has a parent in
   1.581 +just the same way; this is the changeset that the working directory
   1.582 +currently contains.
   1.583 +
   1.584 +To update the working directory to a particular revision, give a
   1.585 +revision number or changeset~ID to the \hgcmd{update} command.
   1.586 +\interaction{tour.older}
   1.587 +If you omit an explicit revision, \hgcmd{update} will update to the
   1.588 +tip revision, as shown by the second call to \hgcmd{update} in the
   1.589 +example above.
   1.590 +
   1.591 +\subsection{Pushing changes to another repository}
   1.592 +
   1.593 +Mercurial lets us push changes to another repository, from the
   1.594 +repository we're currently visiting.  As with the example of
   1.595 +\hgcmd{pull} above, we'll create a temporary repository to push our
   1.596 +changes into.
   1.597 +\interaction{tour.clone-push}
   1.598 +The \hgcmd{outgoing} command tells us what changes would be pushed
   1.599 +into another repository.
   1.600 +\interaction{tour.outgoing}
   1.601 +And the \hgcmd{push} command does the actual push.
   1.602 +\interaction{tour.push}
   1.603 +As with \hgcmd{pull}, the \hgcmd{push} command does not update the
   1.604 +working directory in the repository that it's pushing changes into.
   1.605 +(Unlike \hgcmd{pull}, \hgcmd{push} does not provide a \texttt{-u}
   1.606 +option that updates the other repository's working directory.)
   1.607 +
   1.608 +What happens if we try to pull or push changes and the receiving
   1.609 +repository already has those changes?  Nothing too exciting.
   1.610 +\interaction{tour.push.nothing}
   1.611 +
   1.612 +\subsection{Sharing changes over a network}
   1.613 +
   1.614 +The commands we have covered in the previous few sections are not
   1.615 +limited to working with local repositories.  Each works in exactly the
   1.616 +same fashion over a network connection; simply pass in a URL instead
   1.617 +of a local path.
   1.618 +\interaction{tour.outgoing.net}
   1.619 +In this example, we can see what changes we could push to the remote
   1.620 +repository, but the repository is understandably not set up to let
   1.621 +anonymous users push to it.
   1.622 +\interaction{tour.push.net}
   1.623 +
   1.624 +%%% Local Variables: 
   1.625 +%%% mode: latex
   1.626 +%%% TeX-master: "00book"
   1.627 +%%% End: