Online Book Reader

Home Category

Mercurial_ The Definitive Guide - Bryan O'Sullivan [93]

By Root 923 0
bookkeeping; it tracks all of the patches that MQ has applied in this repository.

* * *

Note


You may sometimes want to edit the series file by hand; for example, to change the sequence in which some patches are applied. However, manually editing the status file is almost always a bad idea, as it’s easy to corrupt MQ’s idea of what is happening.

* * *

Once you have created your new patch, you can edit files in the working directory as you usually would. All of the normal Mercurial commands, such as hg diff and hg annotate, work exactly as they did before.

Refreshing a Patch

When you reach a point where you want to save your work, use the qrefresh command to update the patch you are working on.

$ echo 'line 2' >> file1

$ hg diff

diff -r ca4853f45c6e file1

--- a/file1 Tue May 05 06:44:42 2009 +0000

+++ b/file1 Tue May 05 06:44:42 2009 +0000

@@ -1,1 +1,2 @@

line 1

+line 2

$ hg qrefresh

$ hg diff

$ hg tip --style=compact --patch

1[qtip,first.patch,tip,qbase] a560bf0a5cff 2009-05-05 06:44 +0000 bos

[mq]: first.patch

diff -r aaa568b23a06 -r a560bf0a5cff file1

--- a/file1 Tue May 05 06:44:42 2009 +0000

+++ b/file1 Tue May 05 06:44:42 2009 +0000

@@ -1,1 +1,2 @@

line 1

+line 2

This command folds the changes you have made in the working directory into your patch, and updates its corresponding changeset to contain those changes.

You can run qrefresh as often as you like, so it’s a good way to “checkpoint” your work. Refresh your patch at an opportune time, try an experiment, and if the experiment doesn’t work out, hg revert your modifications back to the last time you refreshed.

$ echo 'line 3' >> file1

$ hg status

M file1

$ hg qrefresh

$ hg tip --style=compact --patch

1[qtip,first.patch,tip,qbase] 8c986ab3b0da 2009-05-05 06:44 +0000 bos

[mq]: first.patch

diff -r aaa568b23a06 -r 8c986ab3b0da file1

--- a/file1 Tue May 05 06:44:42 2009 +0000

+++ b/file1 Tue May 05 06:44:42 2009 +0000

@@ -1,1 +1,3 @@

line 1

+line 2

+line 3

Stacking and Tracking Patches

Once you have finished working on a patch, or need to work on another, you can use the qnew command again to create a new patch. Mercurial will apply this patch on top of your existing patch.

$ hg qnew second.patch

$ hg log --style=compact --limit=2

2[qtip,second.patch,tip] 10e2b1e61af7 2009-05-05 06:44 +0000 bos

[mq]: second.patch

1[first.patch,qbase] 8c986ab3b0da 2009-05-05 06:44 +0000 bos

[mq]: first.patch

$ echo 'line 4' >> file1

$ hg qrefresh

$ hg tip --style=compact --patch

2[qtip,second.patch,tip] fd12637a8b18 2009-05-05 06:44 +0000 bos

[mq]: second.patch

diff -r 8c986ab3b0da -r fd12637a8b18 file1

--- a/file1 Tue May 05 06:44:42 2009 +0000

+++ b/file1 Tue May 05 06:44:43 2009 +0000

@@ -1,3 +1,4 @@

line 1

line 2

line 3

+line 4

$ hg annotate file1

0: line 1

1: line 2

1: line 3

2: line 4

Notice that the patch contains the changes in our prior patch as part of its context (you can see this more clearly in the output of hg annotate).

So far, with the exception of qnew and qrefresh, we’ve been careful to only use regular Mercurial commands. However, MQ provides many commands that are easier to use when you are thinking about patches, as illustrated below.

$ hg qseries

first.patch

second.patch

$ hg qapplied

first.patch

second.patch

The qseries command lists every patch that MQ knows about in this repository, from oldest to newest (most recently created).

The qapplied command lists every patch that MQ has applied in this repository, again from oldest to newest (most recently applied).

Manipulating the Patch Stack

The previous discussion implied that there must be a difference between “known” and “applied” patches, and there is. MQ can manage a patch without it being applied in the repository.

An applied patch has a corresponding changeset in the repository, and the effects of the patch and changeset are visible in the working directory. You can undo the application of a patch using the qpop command. MQ still knows about, or manages, a popped patch, but

Return Main Page Previous Page Next Page

®Online Book Reader