# HG changeset patch # User Bryan O'Sullivan # Date 1238564310 25200 # Node ID c44d5854620b4d2edf08e7e0dd413bb6aa436c98 # Parent c17f8bffc9e50022296d3ce507616dd743cf6371 Fix up chapter 1. diff -r c17f8bffc9e5 -r c44d5854620b en/ch00-preface.xml --- a/en/ch00-preface.xml Tue Mar 31 09:04:23 2009 -0700 +++ b/en/ch00-preface.xml Tue Mar 31 22:38:30 2009 -0700 @@ -68,9 +68,10 @@ project. - Most of these reasons are equally valid---at least in - theory---whether you're working on a project by yourself, or - with a hundred other people. + Most of these reasons are equally + valid&emdash;at least in theory&emdash;whether you're working + on a project by yourself, or with a hundred other + people. A key question about the practicality of revision control at these two different scales (lone hacker and @@ -143,7 +144,7 @@ About the examples in this book This book takes an unusual approach to code samples. Every - example is live---each one is actually the result + example is live&emdash;each one is actually the result of a shell script that executes the Mercurial commands you see. Every time an image of the book is built from its sources, all the example scripts are automatically run, and their current @@ -353,8 +354,8 @@ centralised system to fall over under the combined load of just a few dozen concurrent users. Once again, the typical response tends to be an expensive and clunky replication - facility. Since the load on a central server---if you have - one at all---is many times lower with a distributed tool + facility. Since the load on a central server&emdash;if you have + one at all&emdash;is many times lower with a distributed tool (because all of the data is replicated everywhere), a single cheap server can handle the needs of a much larger team, and replication to balance load becomes a simple matter of diff -r c17f8bffc9e5 -r c44d5854620b en/ch01-tour-basic.xml --- a/en/ch01-tour-basic.xml Tue Mar 31 09:04:23 2009 -0700 +++ b/en/ch01-tour-basic.xml Tue Mar 31 22:38:30 2009 -0700 @@ -12,6 +12,26 @@ using Mercurial on your computer immediately. + Windows + + The best version of Mercurial for Windows is + TortoiseHg, which can be found at http://bitbucket.org/tortoisehg/stable/wiki/Home. + This package has no external dependencies; it just + works. It provides both command line and graphical + user interfaces. + + + + + Mac OS X + + Lee Cantey publishes an installer of Mercurial + for Mac OS X at http://mercurial.berkwood.com. + + + Linux Because each Linux distribution has its own packaging @@ -29,18 +49,12 @@ mercurial. - Debian: + Ubuntu and Debian: apt-get install mercurial - Fedora Core: + Fedora and OpenSUSE: yum install mercurial Gentoo: emerge mercurial - OpenSUSE: - yum install mercurial - Ubuntu: Ubuntu's Mercurial package is based on - Debian's. To install it, run the following - command. - apt-get install mercurial @@ -49,49 +63,12 @@ SunFreeWare, at http://www.sunfreeware.com, - is a good source for a large number of pre-built Solaris - packages for 32 and 64 bit Intel and Sparc architectures, - including current versions of Mercurial. + provides prebuilt packages of Mercurial. - - Mac OS X - - Lee Cantey publishes an installer of Mercurial for Mac OS - X at http://mercurial.berkwood.com. - This package works on both Intel- and Power-based Macs. Before - you can use it, you must install a compatible version of - Universal MacPython web:macpython. This - is easy to do; simply follow the instructions on Lee's - site. - - It's also possible to install Mercurial using Fink or - MacPorts, two popular free package managers for Mac OS X. If - you have Fink, use sudo apt-get install - mercurial-py25. If MacPorts, sudo port - install mercurial. - - - Windows - - Lee Cantey publishes an installer of Mercurial for Windows - at http://mercurial.berkwood.com. - This package has no external dependencies; it just - works. + - - The Windows version of Mercurial does not - automatically convert line endings between Windows and Unix - styles. If you want to share work with Unix users, you must - do a little additional configuration work. XXX Flesh this - out. - - - - Getting started @@ -150,10 +127,16 @@ command to make a copy of a repository, it's best to use a built-in command that Mercurial provides. This command is called hg clone, because it - creates an identical copy of an existing repository. + makes an identical copy of an existing repository. &interaction.tour.clone; + One advantage of using hg + clone is that, as we can see above, it lets us clone + repositories over the network. Another is that it remembers + where we cloned from, which we'll find useful soon when we + want to fetch new changes from another repository. + If our clone succeeded, we should now have a local directory called hello. This directory will contain some files. @@ -163,12 +146,12 @@ These files have the same contents and history in our repository as they do in the repository we cloned. - Every Mercurial repository is complete, self-contained, - and independent. It contains its own private copy of a - project's files and history. A cloned repository remembers - the location of the repository it was cloned from, but it does - not communicate with that repository, or any other, unless you - tell it to. + Every Mercurial repository is complete, + self-contained, and independent. It contains its own private + copy of a project's files and history. As we just mentioned, + a cloned repository remembers the location of the repository + it was cloned from, but Mercurial will not communicate with + that repository, or any other, unless you tell it to. What this means for now is that we're free to experiment with our repository, safe in the knowledge that it's a private @@ -211,7 +194,7 @@ One of the first things we might want to do with a new, unfamiliar repository is understand its history. The hg log command gives us a view of - history. + the history of changes in the repository. &interaction.tour.log; @@ -223,13 +206,20 @@ The fields in a record of output from hg log are as follows. + - changeset: This field has the - format of a number, followed by a colon, followed by a - hexadecimal string. These are - identifiers for the changeset. There - are two identifiers because the number is shorter and easier - to type than the hex string. + changeset: This + field has the format of a number, followed by a colon, + followed by a hexadecimal (or hex) + string. These are identifiers for the + changeset. The hex string is a unique identifier: the same + hex string will always refer to the same changeset. The + number is shorter and easier to type than the hex string, + but it isn't unique: the same number in two different clones + of a repository may identify different changesets. Why + provide the number at all, then? For local + convenience. + user: The identity of the person who created the changeset. This is a free-form field, but it most often contains a person's name and email @@ -241,10 +231,19 @@ person who created the changeset.) summary: The first line of the text message that the creator of the changeset entered - to describe the changeset. - The default output printed by hg - log is purely a summary; it is missing a lot of - detail. + to describe the changeset. + + Some changesets, such as the first in the list above, + have a tag field. A tag is another way + to identify a changeset, by giving it an easy-to-remember + name. (The tag named tip is special: it + always refers to the newest change in a repository.) + + + + The default output printed by hg log is purely a summary; it is + missing a lot of detail. provides a graphical representation of the history of the identifies a changeset using both a number and a hexadecimal string. - The revision number is only valid in - that repository, - while the hex string is the + The revision number is a handy + notation that is only valid in that + repository. + The hexadecimal string is the permanent, unchanging identifier that will always identify that exact changeset in every copy of the repository. - This distinction is important. If you send someone an - email talking about revision 33, there's a high - likelihood that their revision 33 will not be the - same as yours. The reason for this is that a - revision number depends on the order in which changes arrived - in a repository, and there is no guarantee that the same - changes will happen in the same order in different - repositories. Three changes $a,b,c$ can easily appear in one - repository as $0,1,2$, while in another as $1,0,2$. + + This distinction is important. If you send + someone an email talking about revision 33, + there's a high likelihood that their revision 33 will + not be the same as yours. The reason for + this is that a revision number depends on the order in which + changes arrived in a repository, and there is no guarantee + that the same changes will happen in the same order in + different repositories. Three changes a,b,c + can easily appear in one repository as + 0,1,2, while in another as + 0,2,1. Mercurial uses revision numbers purely as a convenient shorthand. If you need to discuss a changeset with someone, @@ -317,7 +320,7 @@ log down to a single revision, use the (or ) option. You can use - either a revision number or a long-form changeset identifier, + either a revision number or a hexadecimal identifier, and you can provide as many revisions as you want. &interaction.tour.log-r; @@ -361,8 +364,12 @@ &interaction.tour.log-vp; + The option is + tremendously useful, so it's well worth remembering. + + All about command options @@ -374,26 +381,42 @@ dealing with the options that you can pass to commands. It follows the conventions for options that are common to modern Linux and Unix systems. + - Every option has a long name. For example, as + + Every option has a long name. For example, as we've already seen, the hg log command accepts a option. - Most options have short names, too. Instead of - , we can use . (The reason that some - options don't have short names is that the options in - question are rarely used.) - Long options start with two dashes (e.g. ), while short options - start with one (e.g. ). - Option naming and usage is consistent across + role="hg-opt-log">--rev option. + + + Most options have short names, too. Instead + of , we can use + . (The reason that + some options don't have short names is that the options in + question are rarely used.) + + + Long options start with two dashes (e.g. + ), while short + options start with one (e.g. ). + + + Option naming and usage is consistent across commands. For example, every command that lets you specify a changeset ID or revision number accepts both and - arguments. + role="hg-opt-log">--rev arguments. + + + If you are using short options, you can save typing by + running them together. For example, the command hg log -v -p -r 2 can be written + as hg log -vpr2. + + + In the examples throughout this book, I use short options instead of long. This just reflects my own preference, so don't read anything significant into it. @@ -404,6 +427,18 @@ less when passed (or ). + + Option naming consistency + + Almost always, Mercurial commands use consistent option + names to refer to the same concepts. For instance, if a + command deals with changesets, you'll always identify them + with or . This consistent use of + option names makes it easier to remember what options a + particular command takes. + + Making and reviewing changes @@ -418,7 +453,14 @@ the remote repository. Since we already have a copy of it locally, we can just clone that instead. This is much faster than cloning over the network, and cloning a local repository - uses less disk space in most cases, too. + uses less disk space in most cases, too + The saving of space arises when source and destination + repositories are on the same filesystem, in which case + Mercurial will use hardlinks to do copy-on-write sharing of + its internal metadata. If that explanation meant nothing to + you, don't worry: everything happens transparently and + automatically, and you don't need to understand it. + . &interaction.tour.reclone; @@ -433,16 +475,14 @@ In our my-hello repository, we have a file hello.c that - contains the classic hello, world program. Let's - use the ancient and venerable sed command to - edit this file so that it prints a second line of output. (I'm - only using sed to do this because it's easy - to write a scripted example this way. Since you're not under - the same constraint, you probably won't want to use - sed; simply use your preferred text editor to - do the same thing.) + contains the classic hello, world program. + + &interaction.tour.cat1; - &interaction.tour.sed; + Let's edit this file so that it prints a second line of + output. + + &interaction.tour.cat2; Mercurial's hg status command will tell us what Mercurial knows about the files in the @@ -465,7 +505,7 @@ file after we were done; it was able to figure this out itself. - It's a little bit helpful to know that we've modified + It's somewhat helpful to know that we've modified hello.c, but we might prefer to know exactly what changes we've made to it. To do this, we use the hg diff @@ -473,6 +513,13 @@ &interaction.tour.diff; + + Understanding patches + + Remember to take a look at if you don't know how to read + output above. + Recording changes in a new changeset @@ -549,10 +596,13 @@ configuration settings. The initial contents of your .hgrc should look like this. + + Figure out what the appropriate directory is on + Windows. + # This is a Mercurial configuration file. [ui] -username = Firstname Lastname -<email.address@domain.net> +username = Firstname Lastname <email.address@domain.net> The [ui] line begins a section of the config file, so you can @@ -571,8 +621,8 @@ You can use any text you like as the value of the username config item, since this - information is for reading by other people, but for - interpreting by Mercurial. The convention that most + information is for reading by other people, but will not be + interpreted by Mercurial. The convention that most people follow is to use their name and email address, as in the example above. @@ -600,10 +650,17 @@ The editor that the hg commit command drops us into will contain an - empty line, followed by a number of lines starting with + empty line or two, followed by a number of lines starting with HG:. - XXX fix this XXX + +This is where I type my commit comment. + +HG: Enter commit message. Lines beginning with 'HG:' are removed. +HG: -- +HG: user: Bryan O'Sullivan <bos@serpentine.com> +HG: branch 'default' +HG: changed hello.c Mercurial ignores the lines that start with HG:; it uses them only to @@ -665,9 +722,18 @@ &interaction.tour.tip; - We refer to - the newest revision in the repository as the tip revision, - or simply the tip. + We refer to the newest revision in the + repository as the tip revision, or simply + the tip. + + By the way, the hg tip + command accepts many of the same options as hg log, so above indicates be + verbose, + specifies print a patch. The use of to print patches is another + example of the consistent naming we mentioned earlier. @@ -704,12 +770,13 @@ &interaction.tour.incoming; - (Of course, someone could - cause more changesets to appear in the repository that we - ran hg incoming in, before - we get a chance to hg pull - the changes, so that we could end up pulling changes that we - didn't expect.) + Suppose you're pulling changes from a repository + on the network somewhere. While you are looking at the hg incoming output, and before you + pull those changes, someone might have committed something in + the remote repository. This means that it's possible to pull + more changes than you saw when using hg incoming. Bringing changes into a repository is a simple matter of running the hg @@ -746,8 +813,8 @@ can use hg update to update the working directory to the state it was in at any revision in the history of the repository. If - you had the working directory updated to an old revision---to - hunt down the origin of a bug, say---and ran a hg pull which automatically updated the working directory to a new revision, you might not be terribly happy. @@ -817,14 +884,17 @@ &interaction.tour.push; - As with - hg pull, the hg push command does not update - the working directory in the repository that it's pushing - changes into. (Unlike hg - pull, hg push - does not provide a -u option that updates - the other repository's working directory.) + As with hg + pull, the hg push + command does not update the working directory in the + repository that it's pushing changes into. Unlike hg pull, hg + push does not provide a -u + option that updates the other repository's working directory. + This asymmetry is deliberate: the repository we're pushing to + might be on a remote server and shared between several people. + If we were to update its working directory while someone was + working in it, their work would be disrupted. What happens if we try to pull or push changes and the receiving repository already has those changes? diff -r c17f8bffc9e5 -r c44d5854620b en/examples/auto-snippets.xml --- a/en/examples/auto-snippets.xml Tue Mar 31 09:04:23 2009 -0700 +++ b/en/examples/auto-snippets.xml Tue Mar 31 22:38:30 2009 -0700 @@ -180,6 +180,8 @@ + + diff -r c17f8bffc9e5 -r c44d5854620b en/examples/tour --- a/en/examples/tour Tue Mar 31 09:04:23 2009 -0700 +++ b/en/examples/tour Tue Mar 31 22:38:30 2009 -0700 @@ -52,10 +52,17 @@ hg clone hello my-hello cd my-hello -#$ name: sed +#$ name: cat1 +cat hello.c + +#$ name: sed -i '/printf/a\\tprintf("hello again!\\n");' hello.c +#$ name: cat2 +# ... edit edit edit ... +cat hello.c + #$ name: status ls