# HG changeset patch # User Bryan O'Sullivan # Date 1241403788 25200 # Node ID c8d662d3cb402692416e3e82e0730890ee253caa # Parent 9e33729cafae2b062c58c52fe99bbc5bf0f6c9dc Improve chapter 1 further, based on comments. diff -r 9e33729cafae -r c8d662d3cb40 en/ch01-tour-basic.xml --- a/en/ch01-tour-basic.xml Tue Apr 28 23:33:11 2009 -0700 +++ b/en/ch01-tour-basic.xml Sun May 03 19:23:08 2009 -0700 @@ -51,8 +51,10 @@ Ubuntu and Debian: apt-get install mercurial - Fedora and OpenSUSE: + Fedora: yum install mercurial + OpenSUSE: + zypper install mercurial Gentoo: emerge mercurial @@ -74,9 +76,9 @@ To begin, we'll use the hg version command to find out whether Mercurial is - actually installed properly. The actual version information - that it prints isn't so important; it's whether it prints - anything at all that we care about. + installed properly. The actual version information that it + prints isn't so important; we simply care whether the command + runs and prints anything at all. &interaction.tour.version; @@ -213,12 +215,11 @@ 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 + hex string will always refer to the same changeset in every + copy of this repository. 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. + of a repository may identify different changesets. user: The identity of the person who created the changeset. This is a free-form @@ -417,9 +418,9 @@ - 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. + In the examples throughout this book, I usually + use short options instead of long. This simply reflects my own + preference, so don't read anything significant into it. Most commands that print output of some kind will print more output when passed a @@ -590,19 +591,30 @@ Creating a Mercurial configuration file To set a user name, use your favorite editor - to create a file called .hgrc in your home directory. - Mercurial will use this file to look up your personalised - configuration settings. The initial contents of your - .hgrc should look like - this. + to create a file called .hgrc in your home directory. + Mercurial will use this file to look up your personalised + configuration settings. The initial contents of your + .hgrc should look like + this. + + + <quote>Home directory</quote> on Windows - Figure out what the appropriate directory is on - Windows. + When we refer to your home directory, on an English + language installation of Windows this will usually be a + folder named after your user name in + C:\Documents and Settings. You can + find out the exact name of your home directory by opening + a command prompt window and running the following + command. + + C:\> echo %UserProfile% + # This is a Mercurial configuration file. [ui] -username = Firstname Lastname <email.address@domain.net> +username = Firstname Lastname <email.address@example.net> The [ui] line begins a section of the config file, so you can @@ -620,38 +632,37 @@ Choosing a user name 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 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. + the username config item, since this + 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. Mercurial's built-in web server obfuscates - email addresses, to make it more difficult for the email - harvesting tools that spammers use. This reduces the - likelihood that you'll start receiving more junk email - if you publish a Mercurial repository on the - web. - + email addresses, to make it more difficult for the email + harvesting tools that spammers use. This reduces the + likelihood that you'll start receiving more junk email if + you publish a Mercurial repository on the + web. Writing a commit message When we commit a change, Mercurial drops us into - a text editor, to enter a message that will describe the - modifications we've made in this changeset. This is called - the commit message. It will be a - record for readers of what we did and why, and it will be - printed by hg log after - we've finished committing. + a text editor, to enter a message that will describe the + modifications we've made in this changeset. This is called + the commit message. It will be a record + for readers of what we did and why, and it will be printed by + hg log after we've finished + committing. &interaction.tour.commit; The editor that the hg - commit command drops us into will contain an - empty line or two, followed by a number of lines starting with - HG:. + commit command drops us into will contain an empty + line or two, followed by a number of lines starting with + HG:. This is where I type my commit comment. @@ -663,20 +674,19 @@ HG: changed hello.c Mercurial ignores the lines that start with - HG:; it uses them only to - tell us which files it's recording changes to. Modifying or - deleting these lines has no effect. + HG:; it uses them only to + tell us which files it's recording changes to. Modifying or + deleting these lines has no effect. Writing a good commit message Since hg log - only prints the first line of a commit message by default, - it's best to write a commit message whose first line stands - alone. Here's a real example of a commit message that - doesn't follow this guideline, and - hence has a summary that is not - readable. + only prints the first line of a commit message by default, + it's best to write a commit message whose first line stands + alone. Here's a real example of a commit message that + doesn't follow this guideline, and hence + has a summary that is not readable. changeset: 73:584af0e231be @@ -685,40 +695,51 @@ summary: include buildmeister/commondefs. Add exports. As far as the remainder of the contents of the - commit message are concerned, there are no hard-and-fast - rules. Mercurial itself doesn't interpret or care about the - contents of the commit message, though your project may have - policies that dictate a certain kind of - formatting. + commit message are concerned, there are no hard-and-fast + rules. Mercurial itself doesn't interpret or care about the + contents of the commit message, though your project may have + policies that dictate a certain kind of formatting. My personal preference is for short, but - informative, commit messages that tell me something that I - can't figure out with a quick glance at the output of - hg log - --patch. + informative, commit messages that tell me something that I + can't figure out with a quick glance at the output of hg log --patch. + If we run the hg + commit command without any arguments, it records + all of the changes we've made, as reported by hg status and hg diff. + + + A surprise for Subversion users + + Like other Mercurial commands, if we don't supply + explicit names to commit to the hg + commit, it will operate across a repository's + entire working directory. Be wary of this if you're coming + from the Subversion or CVS world, since you might expect it + to operate only on the current directory that you happen to + be visiting and its subdirectories. + + Aborting a commit If you decide that you don't want to commit - while in the middle of editing a commit message, simply exit - from your editor without saving the file that it's editing. - This will cause nothing to happen to either the repository - or the working directory. - If we run the hg - commit command without any arguments, it records - all of the changes we've made, as reported by hg status and hg diff. + while in the middle of editing a commit message, simply exit + from your editor without saving the file that it's editing. + This will cause nothing to happen to either the repository or + the working directory. + Admiring our new handiwork Once we've finished the commit, we can use the - hg tip command to display - the changeset we just created. This command produces output - that is identical to hg - log, but it only displays the newest revision in - the repository. + hg tip command to display the + changeset we just created. This command produces output that + is identical to hg log, but + it only displays the newest revision in the repository. &interaction.tour.tip; @@ -741,57 +762,74 @@ Sharing changes We mentioned earlier that repositories in - Mercurial are self-contained. This means that the changeset - we just created exists only in our my-hello repository. Let's - look at a few ways that we can propagate this change into - other repositories. + Mercurial are self-contained. This means that the changeset we + just created exists only in our my-hello repository. Let's look + at a few ways that we can propagate this change into other + repositories. Pulling changes from another repository + To get started, let's clone our original - hello repository, - which does not contain the change we just committed. We'll - call our temporary repository hello-pull. + hello repository, which + does not contain the change we just committed. We'll call our + temporary repository hello-pull. &interaction.tour.clone-pull; We'll use the hg - pull command to bring changes from my-hello into hello-pull. However, blindly - pulling unknown changes into a repository is a somewhat - scary prospect. Mercurial provides the hg incoming command to tell us - what changes the hg pull - command would pull into the repository, - without actually pulling the changes in. + pull command to bring changes from my-hello into hello-pull. However, blindly + pulling unknown changes into a repository is a somewhat scary + prospect. Mercurial provides the hg + incoming command to tell us what changes the + hg pull command + would pull into the repository, without + actually pulling the changes in. &interaction.tour.incoming; - 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 - pull command, and telling it which repository to - pull from. + matter of running the hg pull + command, and optionally telling it which repository to pull from. &interaction.tour.pull; - As you can see - from the before-and-after output of hg tip, we have successfully - pulled changes into our repository. There remains one step - before we can see these changes in the working - directory. + As you can see from the before-and-after output + of hg tip, we have + successfully pulled changes into our repository. However, + Mercurial separates pulling changes in from updating the + working directory. There remains one step before we will see + the changes that we just pulled appear in the working + directory. + + + Pulling specific changes + + It is possible that due to the delay between + running hg incoming and + hg pull, you may not see + all changesets that will be brought from the other + repository. 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. + + If you only want to pull precisely the changes that were + listed by hg incoming, or + you have some other reason to pull a subset of changes, + simply identify the change that you want to pull by its + changeset ID, e.g. hg pull + -r7e95bb. + + Updating the working directory @@ -807,20 +845,21 @@ &interaction.tour.update; - It might seem a bit strange that hg - pull doesn't update the working directory - automatically. There's actually a good reason for this: you - 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&emdash;to - hunt down the origin of a bug, say&emdash;and ran a hg pull which automatically updated - the working directory to a new revision, you might not be - terribly happy. - However, since pull-then-update is such a common thing to - do, Mercurial lets you combine the two by passing the option to It might seem a bit strange that hg pull doesn't update the working + directory automatically. There's actually a good reason for + this: you 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&emdash;to hunt down the origin of a bug, + say&emdash;and ran a hg pull + which automatically updated the working directory to a new + revision, you might not be terribly happy. + + Since pull-then-update is such a common sequence + of operations, Mercurial lets you combine the two by passing + the option to hg pull. If you look back at the output of - To find out what revision the working directory is at, use - the hg parents + To find out what revision the working directory + is at, use the hg parents command. &interaction.tour.parents; If you look back at , - you'll see arrows connecting each changeset. The node that - the arrow leads from in each case is a - parent, and the node that the arrow leads - to is its child. The working directory - has a parent in just the same way; this is the changeset that - the working directory currently contains. + linkend="fig:tour-basic:history"/>, you'll see arrows + connecting each changeset. The node that the arrow leads + from in each case is a parent, and the + node that the arrow leads to is its + child. The working directory has a parent in just the same + way; this is the changeset that the working directory + currently contains. - To update the working directory to a particular revision, - - give a revision number or changeset ID to the hg update command. + To update the working directory to a particular + revision, give a revision number or changeset ID to the + hg update command. &interaction.tour.older; @@ -865,22 +903,21 @@ Pushing changes to another repository Mercurial lets us push changes to another - repository, from the repository we're currently visiting. - As with the example of hg - pull above, we'll create a temporary repository - to push our changes into. + repository, from the repository we're currently visiting. As + with the example of hg pull + above, we'll create a temporary repository to push our changes + into. &interaction.tour.clone-push; - The hg outgoing command - tells us what changes would be pushed into another - repository. + The hg outgoing + command tells us what changes would be pushed into another + repository. &interaction.tour.outgoing; - And the - hg push command does the - actual push. + And the hg push + command does the actual push. &interaction.tour.push; @@ -902,6 +939,38 @@ &interaction.tour.push.nothing; + + + Default locations + + When we clone a repository, Mercurial records the location + of the repository we cloned in the + .hg/hgrc file of the new repository. If + we don't supply a location to hg pull from + or hg push to, those commands will use this + location as a default. The hg incoming + and hg outgoing commands do so too. + + If you open a repository's .hg/hgrc + file in a text editor, you will see contents like the + following. + + [paths] +default = http://www.selenic.com/repo/hg + + It is possible&emdash;and often useful&emdash;to have the + default location for hg push and + hg outgoing be different from those for + hg pull and hg incoming. + We can do this by adding a default-push + entry to the [paths] section of the + .hg/hgrc file, as follows. + + [paths] +default = http://www.selenic.com/repo/hg +default-push = http://hg.example.com/hg + + Sharing changes over a network @@ -913,10 +982,10 @@ &interaction.tour.outgoing.net; - In this example, we - can see what changes we could push to the remote repository, - but the repository is understandably not set up to let - anonymous users push to it. + In this example, we can see what changes we + could push to the remote repository, but the repository is + understandably not set up to let anonymous users push to + it. &interaction.tour.push.net; diff -r 9e33729cafae -r c8d662d3cb40 en/examples/auto-snippets.xml --- a/en/examples/auto-snippets.xml Tue Apr 28 23:33:11 2009 -0700 +++ b/en/examples/auto-snippets.xml Sun May 03 19:23:08 2009 -0700 @@ -69,6 +69,7 @@ + diff -r 9e33729cafae -r c8d662d3cb40 en/examples/tour --- a/en/examples/tour Tue Apr 28 23:33:11 2009 -0700 +++ b/en/examples/tour Sun May 03 19:23:08 2009 -0700 @@ -119,6 +119,7 @@ hg update 2 hg parents hg update +hg parents #$ name: clone-push