Mercurial > hgbook
comparison en/ch11-mq.xml @ 753:1c13ed2130a7
Merge with http://hg.serpentine.com/mercurial/book
author | Dongsheng Song <dongsheng.song@gmail.com> |
---|---|
date | Mon, 30 Mar 2009 16:23:33 +0800 |
parents | 7e7c47481e4f 0b45854f0b7b |
children | b338f5490029 |
comparison
equal
deleted
inserted
replaced
752:6b1577ef5135 | 753:1c13ed2130a7 |
---|---|
1 <!-- vim: set filetype=docbkxml shiftwidth=2 autoindent expandtab tw=77 : --> | 1 <!-- vim: set filetype=docbkxml shiftwidth=2 autoindent expandtab tw=77 : --> |
2 | 2 |
3 <chapter id="chap.mq"> | 3 <chapter id="chap:mq"> |
4 <?dbhtml filename="managing-change-with-mercurial-queues.html"?> | 4 <?dbhtml filename="managing-change-with-mercurial-queues.html"?> |
5 <title>Managing change with Mercurial Queues</title> | 5 <title>Managing change with Mercurial Queues</title> |
6 | 6 |
7 <sect1 id="sec.mq.patch-mgmt"> | 7 <sect1 id="sec:mq:patch-mgmt"> |
8 <title>The patch management problem</title> | 8 <title>The patch management problem</title> |
9 | 9 |
10 <para>Here is a common scenario: you need to install a software | 10 <para id="x_3ac">Here is a common scenario: you need to install a software |
11 package from source, but you find a bug that you must fix in the | 11 package from source, but you find a bug that you must fix in the |
12 source before you can start using the package. You make your | 12 source before you can start using the package. You make your |
13 changes, forget about the package for a while, and a few months | 13 changes, forget about the package for a while, and a few months |
14 later you need to upgrade to a newer version of the package. If | 14 later you need to upgrade to a newer version of the package. If |
15 the newer version of the package still has the bug, you must | 15 the newer version of the package still has the bug, you must |
16 extract your fix from the older source tree and apply it against | 16 extract your fix from the older source tree and apply it against |
17 the newer version. This is a tedious task, and it's easy to | 17 the newer version. This is a tedious task, and it's easy to |
18 make mistakes.</para> | 18 make mistakes.</para> |
19 | 19 |
20 <para>This is a simple case of the <quote>patch management</quote> | 20 <para id="x_3ad">This is a simple case of the <quote>patch management</quote> |
21 problem. You have an <quote>upstream</quote> source tree that | 21 problem. You have an <quote>upstream</quote> source tree that |
22 you can't change; you need to make some local changes on top of | 22 you can't change; you need to make some local changes on top of |
23 the upstream tree; and you'd like to be able to keep those | 23 the upstream tree; and you'd like to be able to keep those |
24 changes separate, so that you can apply them to newer versions | 24 changes separate, so that you can apply them to newer versions |
25 of the upstream source.</para> | 25 of the upstream source.</para> |
26 | 26 |
27 <para>The patch management problem arises in many situations. | 27 <para id="x_3ae">The patch management problem arises in many situations. |
28 Probably the most visible is that a user of an open source | 28 Probably the most visible is that a user of an open source |
29 software project will contribute a bug fix or new feature to the | 29 software project will contribute a bug fix or new feature to the |
30 project's maintainers in the form of a patch.</para> | 30 project's maintainers in the form of a patch.</para> |
31 | 31 |
32 <para>Distributors of operating systems that include open source | 32 <para id="x_3af">Distributors of operating systems that include open source |
33 software often need to make changes to the packages they | 33 software often need to make changes to the packages they |
34 distribute so that they will build properly in their | 34 distribute so that they will build properly in their |
35 environments.</para> | 35 environments.</para> |
36 | 36 |
37 <para>When you have few changes to maintain, it is easy to manage | 37 <para id="x_3b0">When you have few changes to maintain, it is easy to manage |
38 a single patch using the standard <command>diff</command> and | 38 a single patch using the standard <command>diff</command> and |
39 <command>patch</command> programs (see section <xref | 39 <command>patch</command> programs (see <xref |
40 linkend="sec.mq.patch"/> for a discussion of these | 40 linkend="sec:mq:patch"/> for a discussion of these |
41 tools). Once the number of changes grows, it starts to make | 41 tools). Once the number of changes grows, it starts to make |
42 sense to maintain patches as discrete <quote>chunks of | 42 sense to maintain patches as discrete <quote>chunks of |
43 work,</quote> so that for example a single patch will contain | 43 work,</quote> so that for example a single patch will contain |
44 only one bug fix (the patch might modify several files, but it's | 44 only one bug fix (the patch might modify several files, but it's |
45 doing <quote>only one thing</quote>), and you may have a number | 45 doing <quote>only one thing</quote>), and you may have a number |
47 changes you require. In this situation, if you submit a bug fix | 47 changes you require. In this situation, if you submit a bug fix |
48 patch to the upstream maintainers of a package and they include | 48 patch to the upstream maintainers of a package and they include |
49 your fix in a subsequent release, you can simply drop that | 49 your fix in a subsequent release, you can simply drop that |
50 single patch when you're updating to the newer release.</para> | 50 single patch when you're updating to the newer release.</para> |
51 | 51 |
52 <para>Maintaining a single patch against an upstream tree is a | 52 <para id="x_3b1">Maintaining a single patch against an upstream tree is a |
53 little tedious and error-prone, but not difficult. However, the | 53 little tedious and error-prone, but not difficult. However, the |
54 complexity of the problem grows rapidly as the number of patches | 54 complexity of the problem grows rapidly as the number of patches |
55 you have to maintain increases. With more than a tiny number of | 55 you have to maintain increases. With more than a tiny number of |
56 patches in hand, understanding which ones you have applied and | 56 patches in hand, understanding which ones you have applied and |
57 maintaining them moves from messy to overwhelming.</para> | 57 maintaining them moves from messy to overwhelming.</para> |
58 | 58 |
59 <para>Fortunately, Mercurial includes a powerful extension, | 59 <para id="x_3b2">Fortunately, Mercurial includes a powerful extension, |
60 Mercurial Queues (or simply <quote>MQ</quote>), that massively | 60 Mercurial Queues (or simply <quote>MQ</quote>), that massively |
61 simplifies the patch management problem.</para> | 61 simplifies the patch management problem.</para> |
62 | 62 |
63 </sect1> | 63 </sect1> |
64 <sect1 id="sec.mq.history"> | 64 <sect1 id="sec:mq:history"> |
65 <title>The prehistory of Mercurial Queues</title> | 65 <title>The prehistory of Mercurial Queues</title> |
66 | 66 |
67 <para>During the late 1990s, several Linux kernel developers | 67 <para id="x_3b3">During the late 1990s, several Linux kernel developers |
68 started to maintain <quote>patch series</quote> that modified | 68 started to maintain <quote>patch series</quote> that modified |
69 the behaviour of the Linux kernel. Some of these series were | 69 the behaviour of the Linux kernel. Some of these series were |
70 focused on stability, some on feature coverage, and others were | 70 focused on stability, some on feature coverage, and others were |
71 more speculative.</para> | 71 more speculative.</para> |
72 | 72 |
73 <para>The sizes of these patch series grew rapidly. In 2002, | 73 <para id="x_3b4">The sizes of these patch series grew rapidly. In 2002, |
74 Andrew Morton published some shell scripts he had been using to | 74 Andrew Morton published some shell scripts he had been using to |
75 automate the task of managing his patch queues. Andrew was | 75 automate the task of managing his patch queues. Andrew was |
76 successfully using these scripts to manage hundreds (sometimes | 76 successfully using these scripts to manage hundreds (sometimes |
77 thousands) of patches on top of the Linux kernel.</para> | 77 thousands) of patches on top of the Linux kernel.</para> |
78 | 78 |
79 <sect2 id="sec.mq.quilt"> | 79 <sect2 id="sec:mq:quilt"> |
80 <title>A patchwork quilt</title> | 80 <title>A patchwork quilt</title> |
81 | 81 |
82 <para>In early 2003, Andreas Gruenbacher and Martin Quinson | 82 <para id="x_3b5">In early 2003, Andreas Gruenbacher and Martin Quinson |
83 borrowed the approach of Andrew's scripts and published a tool | 83 borrowed the approach of Andrew's scripts and published a tool |
84 called <quote>patchwork quilt</quote> | 84 called <quote>patchwork quilt</quote> |
85 <citation>web:quilt</citation>, or simply <quote>quilt</quote> | 85 <citation>web:quilt</citation>, or simply <quote>quilt</quote> |
86 (see <citation>gruenbacher:2005</citation> for a paper | 86 (see <citation>gruenbacher:2005</citation> for a paper |
87 describing it). Because quilt substantially automated patch | 87 describing it). Because quilt substantially automated patch |
88 management, it rapidly gained a large following among open | 88 management, it rapidly gained a large following among open |
89 source software developers.</para> | 89 source software developers.</para> |
90 | 90 |
91 <para>Quilt manages a <emphasis>stack of patches</emphasis> on | 91 <para id="x_3b6">Quilt manages a <emphasis>stack of patches</emphasis> on |
92 top of a directory tree. To begin, you tell quilt to manage a | 92 top of a directory tree. To begin, you tell quilt to manage a |
93 directory tree, and tell it which files you want to manage; it | 93 directory tree, and tell it which files you want to manage; it |
94 stores away the names and contents of those files. To fix a | 94 stores away the names and contents of those files. To fix a |
95 bug, you create a new patch (using a single command), edit the | 95 bug, you create a new patch (using a single command), edit the |
96 files you need to fix, then <quote>refresh</quote> the | 96 files you need to fix, then <quote>refresh</quote> the |
97 patch.</para> | 97 patch.</para> |
98 | 98 |
99 <para>The refresh step causes quilt to scan the directory tree; | 99 <para id="x_3b7">The refresh step causes quilt to scan the directory tree; |
100 it updates the patch with all of the changes you have made. | 100 it updates the patch with all of the changes you have made. |
101 You can create another patch on top of the first, which will | 101 You can create another patch on top of the first, which will |
102 track the changes required to modify the tree from <quote>tree | 102 track the changes required to modify the tree from <quote>tree |
103 with one patch applied</quote> to <quote>tree with two | 103 with one patch applied</quote> to <quote>tree with two |
104 patches applied</quote>.</para> | 104 patches applied</quote>.</para> |
105 | 105 |
106 <para>You can <emphasis>change</emphasis> which patches are | 106 <para id="x_3b8">You can <emphasis>change</emphasis> which patches are |
107 applied to the tree. If you <quote>pop</quote> a patch, the | 107 applied to the tree. If you <quote>pop</quote> a patch, the |
108 changes made by that patch will vanish from the directory | 108 changes made by that patch will vanish from the directory |
109 tree. Quilt remembers which patches you have popped, though, | 109 tree. Quilt remembers which patches you have popped, though, |
110 so you can <quote>push</quote> a popped patch again, and the | 110 so you can <quote>push</quote> a popped patch again, and the |
111 directory tree will be restored to contain the modifications | 111 directory tree will be restored to contain the modifications |
113 <quote>refresh</quote> command at any time, and the topmost | 113 <quote>refresh</quote> command at any time, and the topmost |
114 applied patch will be updated. This means that you can, at | 114 applied patch will be updated. This means that you can, at |
115 any time, change both which patches are applied and what | 115 any time, change both which patches are applied and what |
116 modifications those patches make.</para> | 116 modifications those patches make.</para> |
117 | 117 |
118 <para>Quilt knows nothing about revision control tools, so it | 118 <para id="x_3b9">Quilt knows nothing about revision control tools, so it |
119 works equally well on top of an unpacked tarball or a | 119 works equally well on top of an unpacked tarball or a |
120 Subversion working copy.</para> | 120 Subversion working copy.</para> |
121 | 121 |
122 </sect2> | 122 </sect2> |
123 <sect2 id="sec.mq.quilt-mq"> | 123 <sect2 id="sec:mq:quilt-mq"> |
124 <title>From patchwork quilt to Mercurial Queues</title> | 124 <title>From patchwork quilt to Mercurial Queues</title> |
125 | 125 |
126 <para>In mid-2005, Chris Mason took the features of quilt and | 126 <para id="x_3ba">In mid-2005, Chris Mason took the features of quilt and |
127 wrote an extension that he called Mercurial Queues, which | 127 wrote an extension that he called Mercurial Queues, which |
128 added quilt-like behaviour to Mercurial.</para> | 128 added quilt-like behaviour to Mercurial.</para> |
129 | 129 |
130 <para>The key difference between quilt and MQ is that quilt | 130 <para id="x_3bb">The key difference between quilt and MQ is that quilt |
131 knows nothing about revision control systems, while MQ is | 131 knows nothing about revision control systems, while MQ is |
132 <emphasis>integrated</emphasis> into Mercurial. Each patch | 132 <emphasis>integrated</emphasis> into Mercurial. Each patch |
133 that you push is represented as a Mercurial changeset. Pop a | 133 that you push is represented as a Mercurial changeset. Pop a |
134 patch, and the changeset goes away.</para> | 134 patch, and the changeset goes away.</para> |
135 | 135 |
136 <para>Because quilt does not care about revision control tools, | 136 <para id="x_3bc">Because quilt does not care about revision control tools, |
137 it is still a tremendously useful piece of software to know | 137 it is still a tremendously useful piece of software to know |
138 about for situations where you cannot use Mercurial and | 138 about for situations where you cannot use Mercurial and |
139 MQ.</para> | 139 MQ.</para> |
140 | 140 |
141 </sect2> | 141 </sect2> |
142 </sect1> | 142 </sect1> |
143 <sect1> | 143 <sect1> |
144 <title>The huge advantage of MQ</title> | 144 <title>The huge advantage of MQ</title> |
145 | 145 |
146 <para>I cannot overstate the value that MQ offers through the | 146 <para id="x_3bd">I cannot overstate the value that MQ offers through the |
147 unification of patches and revision control.</para> | 147 unification of patches and revision control.</para> |
148 | 148 |
149 <para>A major reason that patches have persisted in the free | 149 <para id="x_3be">A major reason that patches have persisted in the free |
150 software and open source world&emdash;in spite of the | 150 software and open source world&emdash;in spite of the |
151 availability of increasingly capable revision control tools over | 151 availability of increasingly capable revision control tools over |
152 the years&emdash;is the <emphasis>agility</emphasis> they | 152 the years&emdash;is the <emphasis>agility</emphasis> they |
153 offer.</para> | 153 offer.</para> |
154 | 154 |
155 <para>Traditional revision control tools make a permanent, | 155 <para id="x_3bf">Traditional revision control tools make a permanent, |
156 irreversible record of everything that you do. While this has | 156 irreversible record of everything that you do. While this has |
157 great value, it's also somewhat stifling. If you want to | 157 great value, it's also somewhat stifling. If you want to |
158 perform a wild-eyed experiment, you have to be careful in how | 158 perform a wild-eyed experiment, you have to be careful in how |
159 you go about it, or you risk leaving unneeded&emdash;or worse, | 159 you go about it, or you risk leaving unneeded&emdash;or worse, |
160 misleading or destabilising&emdash;traces of your missteps and | 160 misleading or destabilising&emdash;traces of your missteps and |
161 errors in the permanent revision record.</para> | 161 errors in the permanent revision record.</para> |
162 | 162 |
163 <para>By contrast, MQ's marriage of distributed revision control | 163 <para id="x_3c0">By contrast, MQ's marriage of distributed revision control |
164 with patches makes it much easier to isolate your work. Your | 164 with patches makes it much easier to isolate your work. Your |
165 patches live on top of normal revision history, and you can make | 165 patches live on top of normal revision history, and you can make |
166 them disappear or reappear at will. If you don't like a patch, | 166 them disappear or reappear at will. If you don't like a patch, |
167 you can drop it. If a patch isn't quite as you want it to be, | 167 you can drop it. If a patch isn't quite as you want it to be, |
168 simply fix it&emdash;as many times as you need to, until you | 168 simply fix it&emdash;as many times as you need to, until you |
169 have refined it into the form you desire.</para> | 169 have refined it into the form you desire.</para> |
170 | 170 |
171 <para>As an example, the integration of patches with revision | 171 <para id="x_3c1">As an example, the integration of patches with revision |
172 control makes understanding patches and debugging their | 172 control makes understanding patches and debugging their |
173 effects&emdash;and their interplay with the code they're based | 173 effects&emdash;and their interplay with the code they're based |
174 on&emdash;<emphasis>enormously</emphasis> easier. Since every | 174 on&emdash;<emphasis>enormously</emphasis> easier. Since every |
175 applied patch has an associated changeset, you can give <command | 175 applied patch has an associated changeset, you can give <command |
176 role="hg-cmd">hg log</command> a file name to see which | 176 role="hg-cmd">hg log</command> a file name to see which |
181 role="hg-cmd">hg annotate</command> command to see which | 181 role="hg-cmd">hg annotate</command> command to see which |
182 changeset or patch modified a particular line of a source file. | 182 changeset or patch modified a particular line of a source file. |
183 And so on.</para> | 183 And so on.</para> |
184 | 184 |
185 </sect1> | 185 </sect1> |
186 <sect1 id="sec.mq.patch"> | 186 <sect1 id="sec:mq:patch"> |
187 <title>Understanding patches</title> | 187 <title>Understanding patches</title> |
188 | 188 |
189 <para>Because MQ doesn't hide its patch-oriented nature, it is | 189 <para id="x_3c2">Because MQ doesn't hide its patch-oriented nature, it is |
190 helpful to understand what patches are, and a little about the | 190 helpful to understand what patches are, and a little about the |
191 tools that work with them.</para> | 191 tools that work with them.</para> |
192 | 192 |
193 <para>The traditional Unix <command>diff</command> command | 193 <para id="x_3c3">The traditional Unix <command>diff</command> command |
194 compares two files, and prints a list of differences between | 194 compares two files, and prints a list of differences between |
195 them. The <command>patch</command> command understands these | 195 them. The <command>patch</command> command understands these |
196 differences as <emphasis>modifications</emphasis> to make to a | 196 differences as <emphasis>modifications</emphasis> to make to a |
197 file. Take a look below for a simple example of these commands | 197 file. Take a look below for a simple example of these commands |
198 in action.</para> | 198 in action.</para> |
199 | 199 |
200 &interaction.mq.dodiff.diff; | 200 &interaction.mq.dodiff.diff; |
201 | 201 |
202 <para>The type of file that <command>diff</command> generates (and | 202 <para id="x_3c4">The type of file that <command>diff</command> generates (and |
203 <command>patch</command> takes as input) is called a | 203 <command>patch</command> takes as input) is called a |
204 <quote>patch</quote> or a <quote>diff</quote>; there is no | 204 <quote>patch</quote> or a <quote>diff</quote>; there is no |
205 difference between a patch and a diff. (We'll use the term | 205 difference between a patch and a diff. (We'll use the term |
206 <quote>patch</quote>, since it's more commonly used.)</para> | 206 <quote>patch</quote>, since it's more commonly used.)</para> |
207 | 207 |
208 <para>A patch file can start with arbitrary text; the | 208 <para id="x_3c5">A patch file can start with arbitrary text; the |
209 <command>patch</command> command ignores this text, but MQ uses | 209 <command>patch</command> command ignores this text, but MQ uses |
210 it as the commit message when creating changesets. To find the | 210 it as the commit message when creating changesets. To find the |
211 beginning of the patch content, <command>patch</command> | 211 beginning of the patch content, <command>patch</command> |
212 searches for the first line that starts with the string | 212 searches for the first line that starts with the string |
213 <quote><literal>diff -</literal></quote>.</para> | 213 <quote><literal>diff -</literal></quote>.</para> |
214 | 214 |
215 <para>MQ works with <emphasis>unified</emphasis> diffs | 215 <para id="x_3c6">MQ works with <emphasis>unified</emphasis> diffs |
216 (<command>patch</command> can accept several other diff formats, | 216 (<command>patch</command> can accept several other diff formats, |
217 but MQ doesn't). A unified diff contains two kinds of header. | 217 but MQ doesn't). A unified diff contains two kinds of header. |
218 The <emphasis>file header</emphasis> describes the file being | 218 The <emphasis>file header</emphasis> describes the file being |
219 modified; it contains the name of the file to modify. When | 219 modified; it contains the name of the file to modify. When |
220 <command>patch</command> sees a new file header, it looks for a | 220 <command>patch</command> sees a new file header, it looks for a |
221 file with that name to start modifying.</para> | 221 file with that name to start modifying.</para> |
222 | 222 |
223 <para>After the file header comes a series of | 223 <para id="x_3c7">After the file header comes a series of |
224 <emphasis>hunks</emphasis>. Each hunk starts with a header; | 224 <emphasis>hunks</emphasis>. Each hunk starts with a header; |
225 this identifies the range of line numbers within the file that | 225 this identifies the range of line numbers within the file that |
226 the hunk should modify. Following the header, a hunk starts and | 226 the hunk should modify. Following the header, a hunk starts and |
227 ends with a few (usually three) lines of text from the | 227 ends with a few (usually three) lines of text from the |
228 unmodified file; these are called the | 228 unmodified file; these are called the |
230 small amount of context between successive hunks, | 230 small amount of context between successive hunks, |
231 <command>diff</command> doesn't print a new hunk header; it just | 231 <command>diff</command> doesn't print a new hunk header; it just |
232 runs the hunks together, with a few lines of context between | 232 runs the hunks together, with a few lines of context between |
233 modifications.</para> | 233 modifications.</para> |
234 | 234 |
235 <para>Each line of context begins with a space character. Within | 235 <para id="x_3c8">Each line of context begins with a space character. Within |
236 the hunk, a line that begins with | 236 the hunk, a line that begins with |
237 <quote><literal>-</literal></quote> means <quote>remove this | 237 <quote><literal>-</literal></quote> means <quote>remove this |
238 line,</quote> while a line that begins with | 238 line,</quote> while a line that begins with |
239 <quote><literal>+</literal></quote> means <quote>insert this | 239 <quote><literal>+</literal></quote> means <quote>insert this |
240 line.</quote> For example, a line that is modified is | 240 line.</quote> For example, a line that is modified is |
241 represented by one deletion and one insertion.</para> | 241 represented by one deletion and one insertion.</para> |
242 | 242 |
243 <para>We will return to some of the more subtle aspects of patches | 243 <para id="x_3c9">We will return to some of the more subtle aspects of patches |
244 later (in section <xref linkend="sec.mq.adv-patch"/>), but you | 244 later (in <xref linkend="sec:mq:adv-patch"/>), but you |
245 should have | 245 should have |
246 enough information now to use MQ.</para> | 246 enough information now to use MQ.</para> |
247 | 247 |
248 </sect1> | 248 </sect1> |
249 <sect1 id="sec.mq.start"> | 249 <sect1 id="sec:mq:start"> |
250 <title>Getting started with Mercurial Queues</title> | 250 <title>Getting started with Mercurial Queues</title> |
251 | 251 |
252 <para>Because MQ is implemented as an extension, you must | 252 <para id="x_3ca">Because MQ is implemented as an extension, you must |
253 explicitly enable before you can use it. (You don't need to | 253 explicitly enable before you can use it. (You don't need to |
254 download anything; MQ ships with the standard Mercurial | 254 download anything; MQ ships with the standard Mercurial |
255 distribution.) To enable MQ, edit your <filename | 255 distribution.) To enable MQ, edit your <filename |
256 role="home">~/.hgrc</filename> file, and add the lines | 256 role="home">~/.hgrc</filename> file, and add the lines |
257 below.</para> | 257 below.</para> |
258 | 258 |
259 <programlisting>[extensions] | 259 <programlisting>[extensions] |
260 hgext.mq =</programlisting> | 260 hgext.mq =</programlisting> |
261 | 261 |
262 <para>Once the extension is enabled, it will make a number of new | 262 <para id="x_3cb">Once the extension is enabled, it will make a number of new |
263 commands available. To verify that the extension is working, | 263 commands available. To verify that the extension is working, |
264 you can use <command role="hg-cmd">hg help</command> to see if | 264 you can use <command role="hg-cmd">hg help</command> to see if |
265 the <command role="hg-ext-mq">qinit</command> command is now | 265 the <command role="hg-ext-mq">qinit</command> command is now |
266 available.</para> | 266 available.</para> |
267 | 267 |
268 &interaction.mq.qinit-help.help; | 268 &interaction.mq.qinit-help.help; |
269 | 269 |
270 <para>You can use MQ with <emphasis>any</emphasis> Mercurial | 270 <para id="x_3cc">You can use MQ with <emphasis>any</emphasis> Mercurial |
271 repository, and its commands only operate within that | 271 repository, and its commands only operate within that |
272 repository. To get started, simply prepare the repository using | 272 repository. To get started, simply prepare the repository using |
273 the <command role="hg-ext-mq">qinit</command> command.</para> | 273 the <command role="hg-ext-mq">qinit</command> command.</para> |
274 | 274 |
275 &interaction.mq.tutorial.qinit; | 275 &interaction.mq.tutorial.qinit; |
276 | 276 |
277 <para>This command creates an empty directory called <filename | 277 <para id="x_3cd">This command creates an empty directory called <filename |
278 role="special" class="directory">.hg/patches</filename>, where | 278 role="special" class="directory">.hg/patches</filename>, where |
279 MQ will keep its metadata. As with many Mercurial commands, the | 279 MQ will keep its metadata. As with many Mercurial commands, the |
280 <command role="hg-ext-mq">qinit</command> command prints nothing | 280 <command role="hg-ext-mq">qinit</command> command prints nothing |
281 if it succeeds.</para> | 281 if it succeeds.</para> |
282 | 282 |
283 <sect2> | 283 <sect2> |
284 <title>Creating a new patch</title> | 284 <title>Creating a new patch</title> |
285 | 285 |
286 <para>To begin work on a new patch, use the <command | 286 <para id="x_3ce">To begin work on a new patch, use the <command |
287 role="hg-ext-mq">qnew</command> command. This command takes | 287 role="hg-ext-mq">qnew</command> command. This command takes |
288 one argument, the name of the patch to create.</para> | 288 one argument, the name of the patch to create.</para> |
289 | 289 |
290 <para>MQ will use this as the name of an actual file in the | 290 <para id="x_3cf">MQ will use this as the name of an actual file in the |
291 <filename role="special" | 291 <filename role="special" |
292 class="directory">.hg/patches</filename> directory, as you | 292 class="directory">.hg/patches</filename> directory, as you |
293 can see below.</para> | 293 can see below.</para> |
294 | 294 |
295 &interaction.mq.tutorial.qnew; | 295 &interaction.mq.tutorial.qnew; |
296 | 296 |
297 <para>Also newly present in the <filename role="special" | 297 <para id="x_3d0">Also newly present in the <filename role="special" |
298 class="directory">.hg/patches</filename> directory are two | 298 class="directory">.hg/patches</filename> directory are two |
299 other files, <filename role="special">series</filename> and | 299 other files, <filename role="special">series</filename> and |
300 <filename role="special">status</filename>. The <filename | 300 <filename role="special">status</filename>. The <filename |
301 role="special">series</filename> file lists all of the | 301 role="special">series</filename> file lists all of the |
302 patches that MQ knows about for this repository, with one | 302 patches that MQ knows about for this repository, with one |
304 role="special">status</filename> file for internal | 304 role="special">status</filename> file for internal |
305 book-keeping; it tracks all of the patches that MQ has | 305 book-keeping; it tracks all of the patches that MQ has |
306 <emphasis>applied</emphasis> in this repository.</para> | 306 <emphasis>applied</emphasis> in this repository.</para> |
307 | 307 |
308 <note> | 308 <note> |
309 <para> You may sometimes want to edit the <filename | 309 <para id="x_3d1"> You may sometimes want to edit the <filename |
310 role="special">series</filename> file by hand; for | 310 role="special">series</filename> file by hand; for |
311 example, to change the sequence in which some patches are | 311 example, to change the sequence in which some patches are |
312 applied. However, manually editing the <filename | 312 applied. However, manually editing the <filename |
313 role="special">status</filename> file is almost always a | 313 role="special">status</filename> file is almost always a |
314 bad idea, as it's easy to corrupt MQ's idea of what is | 314 bad idea, as it's easy to corrupt MQ's idea of what is |
315 happening.</para> | 315 happening.</para> |
316 </note> | 316 </note> |
317 | 317 |
318 <para>Once you have created your new patch, you can edit files | 318 <para id="x_3d2">Once you have created your new patch, you can edit files |
319 in the working directory as you usually would. All of the | 319 in the working directory as you usually would. All of the |
320 normal Mercurial commands, such as <command role="hg-cmd">hg | 320 normal Mercurial commands, such as <command role="hg-cmd">hg |
321 diff</command> and <command role="hg-cmd">hg | 321 diff</command> and <command role="hg-cmd">hg |
322 annotate</command>, work exactly as they did before.</para> | 322 annotate</command>, work exactly as they did before.</para> |
323 | 323 |
324 </sect2> | 324 </sect2> |
325 <sect2> | 325 <sect2> |
326 <title>Refreshing a patch</title> | 326 <title>Refreshing a patch</title> |
327 | 327 |
328 <para>When you reach a point where you want to save your work, | 328 <para id="x_3d3">When you reach a point where you want to save your work, |
329 use the <command role="hg-ext-mq">qrefresh</command> command | 329 use the <command role="hg-ext-mq">qrefresh</command> command |
330 to update the patch you are working on.</para> | 330 to update the patch you are working on.</para> |
331 | 331 |
332 &interaction.mq.tutorial.qrefresh; | 332 &interaction.mq.tutorial.qrefresh; |
333 | 333 |
334 <para>This command folds the changes you have made in the | 334 <para id="x_3d4">This command folds the changes you have made in the |
335 working directory into your patch, and updates its | 335 working directory into your patch, and updates its |
336 corresponding changeset to contain those changes.</para> | 336 corresponding changeset to contain those changes.</para> |
337 | 337 |
338 <para>You can run <command role="hg-ext-mq">qrefresh</command> | 338 <para id="x_3d5">You can run <command role="hg-ext-mq">qrefresh</command> |
339 as often as you like, so it's a good way to | 339 as often as you like, so it's a good way to |
340 <quote>checkpoint</quote> your work. Refresh your patch at an | 340 <quote>checkpoint</quote> your work. Refresh your patch at an |
341 opportune time; try an experiment; and if the experiment | 341 opportune time; try an experiment; and if the experiment |
342 doesn't work out, <command role="hg-cmd">hg revert</command> | 342 doesn't work out, <command role="hg-cmd">hg revert</command> |
343 your modifications back to the last time you refreshed.</para> | 343 your modifications back to the last time you refreshed.</para> |
346 | 346 |
347 </sect2> | 347 </sect2> |
348 <sect2> | 348 <sect2> |
349 <title>Stacking and tracking patches</title> | 349 <title>Stacking and tracking patches</title> |
350 | 350 |
351 <para>Once you have finished working on a patch, or need to work | 351 <para id="x_3d6">Once you have finished working on a patch, or need to work |
352 on another, you can use the <command | 352 on another, you can use the <command |
353 role="hg-ext-mq">qnew</command> command again to create a | 353 role="hg-ext-mq">qnew</command> command again to create a |
354 new patch. Mercurial will apply this patch on top of your | 354 new patch. Mercurial will apply this patch on top of your |
355 existing patch.</para> | 355 existing patch.</para> |
356 | 356 |
357 &interaction.mq.tutorial.qnew2; | 357 &interaction.mq.tutorial.qnew2; |
358 <para>Notice that the patch contains the changes in our prior | 358 <para id="x_3d7">Notice that the patch contains the changes in our prior |
359 patch as part of its context (you can see this more clearly in | 359 patch as part of its context (you can see this more clearly in |
360 the output of <command role="hg-cmd">hg | 360 the output of <command role="hg-cmd">hg |
361 annotate</command>).</para> | 361 annotate</command>).</para> |
362 | 362 |
363 <para>So far, with the exception of <command | 363 <para id="x_3d8">So far, with the exception of <command |
364 role="hg-ext-mq">qnew</command> and <command | 364 role="hg-ext-mq">qnew</command> and <command |
365 role="hg-ext-mq">qrefresh</command>, we've been careful to | 365 role="hg-ext-mq">qrefresh</command>, we've been careful to |
366 only use regular Mercurial commands. However, MQ provides | 366 only use regular Mercurial commands. However, MQ provides |
367 many commands that are easier to use when you are thinking | 367 many commands that are easier to use when you are thinking |
368 about patches, as illustrated below.</para> | 368 about patches, as illustrated below.</para> |
369 | 369 |
370 &interaction.mq.tutorial.qseries; | 370 &interaction.mq.tutorial.qseries; |
371 | 371 |
372 <itemizedlist> | 372 <itemizedlist> |
373 <listitem><para>The <command | 373 <listitem><para id="x_3d9">The <command |
374 role="hg-ext-mq">qseries</command> command lists every | 374 role="hg-ext-mq">qseries</command> command lists every |
375 patch that MQ knows about in this repository, from oldest | 375 patch that MQ knows about in this repository, from oldest |
376 to newest (most recently | 376 to newest (most recently |
377 <emphasis>created</emphasis>).</para> | 377 <emphasis>created</emphasis>).</para> |
378 </listitem> | 378 </listitem> |
379 <listitem><para>The <command | 379 <listitem><para id="x_3da">The <command |
380 role="hg-ext-mq">qapplied</command> command lists every | 380 role="hg-ext-mq">qapplied</command> command lists every |
381 patch that MQ has <emphasis>applied</emphasis> in this | 381 patch that MQ has <emphasis>applied</emphasis> in this |
382 repository, again from oldest to newest (most recently | 382 repository, again from oldest to newest (most recently |
383 applied).</para> | 383 applied).</para> |
384 </listitem></itemizedlist> | 384 </listitem></itemizedlist> |
385 | 385 |
386 </sect2> | 386 </sect2> |
387 <sect2> | 387 <sect2> |
388 <title>Manipulating the patch stack</title> | 388 <title>Manipulating the patch stack</title> |
389 | 389 |
390 <para>The previous discussion implied that there must be a | 390 <para id="x_3db">The previous discussion implied that there must be a |
391 difference between <quote>known</quote> and | 391 difference between <quote>known</quote> and |
392 <quote>applied</quote> patches, and there is. MQ can manage a | 392 <quote>applied</quote> patches, and there is. MQ can manage a |
393 patch without it being applied in the repository.</para> | 393 patch without it being applied in the repository.</para> |
394 | 394 |
395 <para>An <emphasis>applied</emphasis> patch has a corresponding | 395 <para id="x_3dc">An <emphasis>applied</emphasis> patch has a corresponding |
396 changeset in the repository, and the effects of the patch and | 396 changeset in the repository, and the effects of the patch and |
397 changeset are visible in the working directory. You can undo | 397 changeset are visible in the working directory. You can undo |
398 the application of a patch using the <command | 398 the application of a patch using the <command |
399 role="hg-ext-mq">qpop</command> command. MQ still | 399 role="hg-ext-mq">qpop</command> command. MQ still |
400 <emphasis>knows about</emphasis>, or manages, a popped patch, | 400 <emphasis>knows about</emphasis>, or manages, a popped patch, |
401 but the patch no longer has a corresponding changeset in the | 401 but the patch no longer has a corresponding changeset in the |
402 repository, and the working directory does not contain the | 402 repository, and the working directory does not contain the |
403 changes made by the patch. Figure <xref | 403 changes made by the patch. <xref |
404 endterm="fig.mq.stack.caption" linkend="fig.mq.stack"/> illustrates | 404 linkend="fig:mq:stack"/> illustrates |
405 the difference between applied and tracked patches.</para> | 405 the difference between applied and tracked patches.</para> |
406 | 406 |
407 <informalfigure id="fig.mq.stack"> | 407 <figure id="fig:mq:stack"> |
408 <mediaobject> | 408 <title>Applied and unapplied patches in the MQ patch |
409 <imageobject><imagedata fileref="images/mq-stack.png"/></imageobject> | 409 stack</title> |
410 <textobject><phrase>XXX add text</phrase></textobject> | 410 <mediaobject> |
411 <caption><para id="fig.mq.stack.caption">Applied and unapplied patches | 411 <imageobject><imagedata fileref="figs/mq-stack.png"/></imageobject> |
412 in the MQ patch stack</para></caption> | 412 <textobject><phrase>XXX add text</phrase></textobject> |
413 </mediaobject> | 413 </mediaobject> |
414 </informalfigure> | 414 </figure> |
415 | 415 |
416 <para>You can reapply an unapplied, or popped, patch using the | 416 <para id="x_3de">You can reapply an unapplied, or popped, patch using the |
417 <command role="hg-ext-mq">qpush</command> command. This | 417 <command role="hg-ext-mq">qpush</command> command. This |
418 creates a new changeset to correspond to the patch, and the | 418 creates a new changeset to correspond to the patch, and the |
419 patch's changes once again become present in the working | 419 patch's changes once again become present in the working |
420 directory. See below for examples of <command | 420 directory. See below for examples of <command |
421 role="hg-ext-mq">qpop</command> and <command | 421 role="hg-ext-mq">qpop</command> and <command |
422 role="hg-ext-mq">qpush</command> in action.</para> | 422 role="hg-ext-mq">qpush</command> in action.</para> |
423 &interaction.mq.tutorial.qpop; | 423 &interaction.mq.tutorial.qpop; |
424 | 424 |
425 <para>Notice that once we have popped a patch or two patches, | 425 <para id="x_3df">Notice that once we have popped a patch or two patches, |
426 the output of <command role="hg-ext-mq">qseries</command> | 426 the output of <command role="hg-ext-mq">qseries</command> |
427 remains the same, while that of <command | 427 remains the same, while that of <command |
428 role="hg-ext-mq">qapplied</command> has changed.</para> | 428 role="hg-ext-mq">qapplied</command> has changed.</para> |
429 | 429 |
430 | 430 |
431 </sect2> | 431 </sect2> |
432 <sect2> | 432 <sect2> |
433 <title>Pushing and popping many patches</title> | 433 <title>Pushing and popping many patches</title> |
434 | 434 |
435 <para>While <command role="hg-ext-mq">qpush</command> and | 435 <para id="x_3e0">While <command role="hg-ext-mq">qpush</command> and |
436 <command role="hg-ext-mq">qpop</command> each operate on a | 436 <command role="hg-ext-mq">qpop</command> each operate on a |
437 single patch at a time by default, you can push and pop many | 437 single patch at a time by default, you can push and pop many |
438 patches in one go. The <option | 438 patches in one go. The <option |
439 role="hg-ext-mq-cmd-qpush-opt">hg -a</option> option to | 439 role="hg-ext-mq-cmd-qpush-opt">hg -a</option> option to |
440 <command role="hg-ext-mq">qpush</command> causes it to push | 440 <command role="hg-ext-mq">qpush</command> causes it to push |
441 all unapplied patches, while the <option | 441 all unapplied patches, while the <option |
442 role="hg-ext-mq-cmd-qpop-opt">-a</option> option to <command | 442 role="hg-ext-mq-cmd-qpop-opt">-a</option> option to <command |
443 role="hg-ext-mq">qpop</command> causes it to pop all applied | 443 role="hg-ext-mq">qpop</command> causes it to pop all applied |
444 patches. (For some more ways to push and pop many patches, | 444 patches. (For some more ways to push and pop many patches, |
445 see section <xref linkend="sec.mq.perf"/> | 445 see <xref linkend="sec:mq:perf"/> below.)</para> |
446 below.)</para> | |
447 | 446 |
448 &interaction.mq.tutorial.qpush-a; | 447 &interaction.mq.tutorial.qpush-a; |
449 | 448 |
450 </sect2> | 449 </sect2> |
451 <sect2> | 450 <sect2> |
452 <title>Safety checks, and overriding them</title> | 451 <title>Safety checks, and overriding them</title> |
453 | 452 |
454 <para>Several MQ commands check the working directory before | 453 <para id="x_3e1">Several MQ commands check the working directory before |
455 they do anything, and fail if they find any modifications. | 454 they do anything, and fail if they find any modifications. |
456 They do this to ensure that you won't lose any changes that | 455 They do this to ensure that you won't lose any changes that |
457 you have made, but not yet incorporated into a patch. The | 456 you have made, but not yet incorporated into a patch. The |
458 example below illustrates this; the <command | 457 example below illustrates this; the <command |
459 role="hg-ext-mq">qnew</command> command will not create a | 458 role="hg-ext-mq">qnew</command> command will not create a |
461 case by the <command role="hg-cmd">hg add</command> of | 460 case by the <command role="hg-cmd">hg add</command> of |
462 <filename>file3</filename>.</para> | 461 <filename>file3</filename>.</para> |
463 | 462 |
464 &interaction.mq.tutorial.add; | 463 &interaction.mq.tutorial.add; |
465 | 464 |
466 <para>Commands that check the working directory all take an | 465 <para id="x_3e2">Commands that check the working directory all take an |
467 <quote>I know what I'm doing</quote> option, which is always | 466 <quote>I know what I'm doing</quote> option, which is always |
468 named <option>-f</option>. The exact meaning of | 467 named <option>-f</option>. The exact meaning of |
469 <option>-f</option> depends on the command. For example, | 468 <option>-f</option> depends on the command. For example, |
470 <command role="hg-cmd">hg qnew <option | 469 <command role="hg-cmd">hg qnew <option |
471 role="hg-ext-mq-cmd-qnew-opt">hg -f</option></command> | 470 role="hg-ext-mq-cmd-qnew-opt">hg -f</option></command> |
478 | 477 |
479 </sect2> | 478 </sect2> |
480 <sect2> | 479 <sect2> |
481 <title>Working on several patches at once</title> | 480 <title>Working on several patches at once</title> |
482 | 481 |
483 <para>The <command role="hg-ext-mq">qrefresh</command> command | 482 <para id="x_3e3">The <command role="hg-ext-mq">qrefresh</command> command |
484 always refreshes the <emphasis>topmost</emphasis> applied | 483 always refreshes the <emphasis>topmost</emphasis> applied |
485 patch. This means that you can suspend work on one patch (by | 484 patch. This means that you can suspend work on one patch (by |
486 refreshing it), pop or push to make a different patch the top, | 485 refreshing it), pop or push to make a different patch the top, |
487 and work on <emphasis>that</emphasis> patch for a | 486 and work on <emphasis>that</emphasis> patch for a |
488 while.</para> | 487 while.</para> |
489 | 488 |
490 <para>Here's an example that illustrates how you can use this | 489 <para id="x_3e4">Here's an example that illustrates how you can use this |
491 ability. Let's say you're developing a new feature as two | 490 ability. Let's say you're developing a new feature as two |
492 patches. The first is a change to the core of your software, | 491 patches. The first is a change to the core of your software, |
493 and the second&emdash;layered on top of the | 492 and the second&emdash;layered on top of the |
494 first&emdash;changes the user interface to use the code you | 493 first&emdash;changes the user interface to use the code you |
495 just added to the core. If you notice a bug in the core while | 494 just added to the core. If you notice a bug in the core while |
501 core patch, and <command role="hg-ext-mq">qpush</command> back | 500 core patch, and <command role="hg-ext-mq">qpush</command> back |
502 to the UI patch to continue where you left off.</para> | 501 to the UI patch to continue where you left off.</para> |
503 | 502 |
504 </sect2> | 503 </sect2> |
505 </sect1> | 504 </sect1> |
506 <sect1 id="sec.mq.adv-patch"> | 505 <sect1 id="sec:mq:adv-patch"> |
507 <title>More about patches</title> | 506 <title>More about patches</title> |
508 | 507 |
509 <para>MQ uses the GNU <command>patch</command> command to apply | 508 <para id="x_3e5">MQ uses the GNU <command>patch</command> command to apply |
510 patches, so it's helpful to know a few more detailed aspects of | 509 patches, so it's helpful to know a few more detailed aspects of |
511 how <command>patch</command> works, and about patches | 510 how <command>patch</command> works, and about patches |
512 themselves.</para> | 511 themselves.</para> |
513 | 512 |
514 <sect2> | 513 <sect2> |
515 <title>The strip count</title> | 514 <title>The strip count</title> |
516 | 515 |
517 <para>If you look at the file headers in a patch, you will | 516 <para id="x_3e6">If you look at the file headers in a patch, you will |
518 notice that the pathnames usually have an extra component on | 517 notice that the pathnames usually have an extra component on |
519 the front that isn't present in the actual path name. This is | 518 the front that isn't present in the actual path name. This is |
520 a holdover from the way that people used to generate patches | 519 a holdover from the way that people used to generate patches |
521 (people still do this, but it's somewhat rare with modern | 520 (people still do this, but it's somewhat rare with modern |
522 revision control tools).</para> | 521 revision control tools).</para> |
523 | 522 |
524 <para>Alice would unpack a tarball, edit her files, then decide | 523 <para id="x_3e7">Alice would unpack a tarball, edit her files, then decide |
525 that she wanted to create a patch. So she'd rename her | 524 that she wanted to create a patch. So she'd rename her |
526 working directory, unpack the tarball again (hence the need | 525 working directory, unpack the tarball again (hence the need |
527 for the rename), and use the <option | 526 for the rename), and use the <option |
528 role="cmd-opt-diff">-r</option> and <option | 527 role="cmd-opt-diff">-r</option> and <option |
529 role="cmd-opt-diff">-N</option> options to | 528 role="cmd-opt-diff">-N</option> options to |
532 result would be that the name of the unmodified directory | 531 result would be that the name of the unmodified directory |
533 would be at the front of the left-hand path in every file | 532 would be at the front of the left-hand path in every file |
534 header, and the name of the modified directory would be at the | 533 header, and the name of the modified directory would be at the |
535 front of the right-hand path.</para> | 534 front of the right-hand path.</para> |
536 | 535 |
537 <para>Since someone receiving a patch from the Alices of the net | 536 <para id="x_3e8">Since someone receiving a patch from the Alices of the net |
538 would be unlikely to have unmodified and modified directories | 537 would be unlikely to have unmodified and modified directories |
539 with exactly the same names, the <command>patch</command> | 538 with exactly the same names, the <command>patch</command> |
540 command has a <option role="cmd-opt-patch">-p</option> option | 539 command has a <option role="cmd-opt-patch">-p</option> option |
541 that indicates the number of leading path name components to | 540 that indicates the number of leading path name components to |
542 strip when trying to apply a patch. This number is called the | 541 strip when trying to apply a patch. This number is called the |
543 <emphasis>strip count</emphasis>.</para> | 542 <emphasis>strip count</emphasis>.</para> |
544 | 543 |
545 <para>An option of <quote><literal>-p1</literal></quote> means | 544 <para id="x_3e9">An option of <quote><literal>-p1</literal></quote> means |
546 <quote>use a strip count of one</quote>. If | 545 <quote>use a strip count of one</quote>. If |
547 <command>patch</command> sees a file name | 546 <command>patch</command> sees a file name |
548 <filename>foo/bar/baz</filename> in a file header, it will | 547 <filename>foo/bar/baz</filename> in a file header, it will |
549 strip <filename>foo</filename> and try to patch a file named | 548 strip <filename>foo</filename> and try to patch a file named |
550 <filename>bar/baz</filename>. (Strictly speaking, the strip | 549 <filename>bar/baz</filename>. (Strictly speaking, the strip |
553 ) to strip. A strip count of one will turn | 552 ) to strip. A strip count of one will turn |
554 <filename>foo/bar</filename> into <filename>bar</filename>, | 553 <filename>foo/bar</filename> into <filename>bar</filename>, |
555 but <filename>/foo/bar</filename> (notice the extra leading | 554 but <filename>/foo/bar</filename> (notice the extra leading |
556 slash) into <filename>foo/bar</filename>.)</para> | 555 slash) into <filename>foo/bar</filename>.)</para> |
557 | 556 |
558 <para>The <quote>standard</quote> strip count for patches is | 557 <para id="x_3ea">The <quote>standard</quote> strip count for patches is |
559 one; almost all patches contain one leading path name | 558 one; almost all patches contain one leading path name |
560 component that needs to be stripped. Mercurial's <command | 559 component that needs to be stripped. Mercurial's <command |
561 role="hg-cmd">hg diff</command> command generates path names | 560 role="hg-cmd">hg diff</command> command generates path names |
562 in this form, and the <command role="hg-cmd">hg | 561 in this form, and the <command role="hg-cmd">hg |
563 import</command> command and MQ expect patches to have a | 562 import</command> command and MQ expect patches to have a |
564 strip count of one.</para> | 563 strip count of one.</para> |
565 | 564 |
566 <para>If you receive a patch from someone that you want to add | 565 <para id="x_3eb">If you receive a patch from someone that you want to add |
567 to your patch queue, and the patch needs a strip count other | 566 to your patch queue, and the patch needs a strip count other |
568 than one, you cannot just <command | 567 than one, you cannot just <command |
569 role="hg-ext-mq">qimport</command> the patch, because | 568 role="hg-ext-mq">qimport</command> the patch, because |
570 <command role="hg-ext-mq">qimport</command> does not yet have | 569 <command role="hg-ext-mq">qimport</command> does not yet have |
571 a <literal>-p</literal> option (see <ulink role="hg-bug" | 570 a <literal>-p</literal> option (see <ulink role="hg-bug" |
582 </para> | 581 </para> |
583 </sect2> | 582 </sect2> |
584 <sect2> | 583 <sect2> |
585 <title>Strategies for applying a patch</title> | 584 <title>Strategies for applying a patch</title> |
586 | 585 |
587 <para>When <command>patch</command> applies a hunk, it tries a | 586 <para id="x_3ec">When <command>patch</command> applies a hunk, it tries a |
588 handful of successively less accurate strategies to try to | 587 handful of successively less accurate strategies to try to |
589 make the hunk apply. This falling-back technique often makes | 588 make the hunk apply. This falling-back technique often makes |
590 it possible to take a patch that was generated against an old | 589 it possible to take a patch that was generated against an old |
591 version of a file, and apply it against a newer version of | 590 version of a file, and apply it against a newer version of |
592 that file.</para> | 591 that file.</para> |
593 | 592 |
594 <para>First, <command>patch</command> tries an exact match, | 593 <para id="x_3ed">First, <command>patch</command> tries an exact match, |
595 where the line numbers, the context, and the text to be | 594 where the line numbers, the context, and the text to be |
596 modified must apply exactly. If it cannot make an exact | 595 modified must apply exactly. If it cannot make an exact |
597 match, it tries to find an exact match for the context, | 596 match, it tries to find an exact match for the context, |
598 without honouring the line numbering information. If this | 597 without honouring the line numbering information. If this |
599 succeeds, it prints a line of output saying that the hunk was | 598 succeeds, it prints a line of output saying that the hunk was |
600 applied, but at some <emphasis>offset</emphasis> from the | 599 applied, but at some <emphasis>offset</emphasis> from the |
601 original line number.</para> | 600 original line number.</para> |
602 | 601 |
603 <para>If a context-only match fails, <command>patch</command> | 602 <para id="x_3ee">If a context-only match fails, <command>patch</command> |
604 removes the first and last lines of the context, and tries a | 603 removes the first and last lines of the context, and tries a |
605 <emphasis>reduced</emphasis> context-only match. If the hunk | 604 <emphasis>reduced</emphasis> context-only match. If the hunk |
606 with reduced context succeeds, it prints a message saying that | 605 with reduced context succeeds, it prints a message saying that |
607 it applied the hunk with a <emphasis>fuzz factor</emphasis> | 606 it applied the hunk with a <emphasis>fuzz factor</emphasis> |
608 (the number after the fuzz factor indicates how many lines of | 607 (the number after the fuzz factor indicates how many lines of |
609 context <command>patch</command> had to trim before the patch | 608 context <command>patch</command> had to trim before the patch |
610 applied).</para> | 609 applied).</para> |
611 | 610 |
612 <para>When neither of these techniques works, | 611 <para id="x_3ef">When neither of these techniques works, |
613 <command>patch</command> prints a message saying that the hunk | 612 <command>patch</command> prints a message saying that the hunk |
614 in question was rejected. It saves rejected hunks (also | 613 in question was rejected. It saves rejected hunks (also |
615 simply called <quote>rejects</quote>) to a file with the same | 614 simply called <quote>rejects</quote>) to a file with the same |
616 name, and an added <filename role="special">.rej</filename> | 615 name, and an added <filename role="special">.rej</filename> |
617 extension. It also saves an unmodified copy of the file with | 616 extension. It also saves an unmodified copy of the file with |
627 | 626 |
628 </sect2> | 627 </sect2> |
629 <sect2> | 628 <sect2> |
630 <title>Some quirks of patch representation</title> | 629 <title>Some quirks of patch representation</title> |
631 | 630 |
632 <para>There are a few useful things to know about how | 631 <para id="x_3f0">There are a few useful things to know about how |
633 <command>patch</command> works with files.</para> | 632 <command>patch</command> works with files.</para> |
634 <itemizedlist> | 633 <itemizedlist> |
635 <listitem><para>This should already be obvious, but | 634 <listitem><para id="x_3f1">This should already be obvious, but |
636 <command>patch</command> cannot handle binary | 635 <command>patch</command> cannot handle binary |
637 files.</para> | 636 files.</para> |
638 </listitem> | 637 </listitem> |
639 <listitem><para>Neither does it care about the executable bit; | 638 <listitem><para id="x_3f2">Neither does it care about the executable bit; |
640 it creates new files as readable, but not | 639 it creates new files as readable, but not |
641 executable.</para> | 640 executable.</para> |
642 </listitem> | 641 </listitem> |
643 <listitem><para><command>patch</command> treats the removal of | 642 <listitem><para id="x_3f3"><command>patch</command> treats the removal of |
644 a file as a diff between the file to be removed and the | 643 a file as a diff between the file to be removed and the |
645 empty file. So your idea of <quote>I deleted this | 644 empty file. So your idea of <quote>I deleted this |
646 file</quote> looks like <quote>every line of this file | 645 file</quote> looks like <quote>every line of this file |
647 was deleted</quote> in a patch.</para> | 646 was deleted</quote> in a patch.</para> |
648 </listitem> | 647 </listitem> |
649 <listitem><para>It treats the addition of a file as a diff | 648 <listitem><para id="x_3f4">It treats the addition of a file as a diff |
650 between the empty file and the file to be added. So in a | 649 between the empty file and the file to be added. So in a |
651 patch, your idea of <quote>I added this file</quote> looks | 650 patch, your idea of <quote>I added this file</quote> looks |
652 like <quote>every line of this file was | 651 like <quote>every line of this file was |
653 added</quote>.</para> | 652 added</quote>.</para> |
654 </listitem> | 653 </listitem> |
655 <listitem><para>It treats a renamed file as the removal of the | 654 <listitem><para id="x_3f5">It treats a renamed file as the removal of the |
656 old name, and the addition of the new name. This means | 655 old name, and the addition of the new name. This means |
657 that renamed files have a big footprint in patches. (Note | 656 that renamed files have a big footprint in patches. (Note |
658 also that Mercurial does not currently try to infer when | 657 also that Mercurial does not currently try to infer when |
659 files have been renamed or copied in a patch.)</para> | 658 files have been renamed or copied in a patch.)</para> |
660 </listitem> | 659 </listitem> |
661 <listitem><para><command>patch</command> cannot represent | 660 <listitem><para id="x_3f6"><command>patch</command> cannot represent |
662 empty files, so you cannot use a patch to represent the | 661 empty files, so you cannot use a patch to represent the |
663 notion <quote>I added this empty file to the | 662 notion <quote>I added this empty file to the |
664 tree</quote>.</para> | 663 tree</quote>.</para> |
665 </listitem></itemizedlist> | 664 </listitem></itemizedlist> |
666 </sect2> | 665 </sect2> |
667 <sect2> | 666 <sect2> |
668 <title>Beware the fuzz</title> | 667 <title>Beware the fuzz</title> |
669 | 668 |
670 <para>While applying a hunk at an offset, or with a fuzz factor, | 669 <para id="x_3f7">While applying a hunk at an offset, or with a fuzz factor, |
671 will often be completely successful, these inexact techniques | 670 will often be completely successful, these inexact techniques |
672 naturally leave open the possibility of corrupting the patched | 671 naturally leave open the possibility of corrupting the patched |
673 file. The most common cases typically involve applying a | 672 file. The most common cases typically involve applying a |
674 patch twice, or at an incorrect location in the file. If | 673 patch twice, or at an incorrect location in the file. If |
675 <command>patch</command> or <command | 674 <command>patch</command> or <command |
676 role="hg-ext-mq">qpush</command> ever mentions an offset or | 675 role="hg-ext-mq">qpush</command> ever mentions an offset or |
677 fuzz factor, you should make sure that the modified files are | 676 fuzz factor, you should make sure that the modified files are |
678 correct afterwards.</para> | 677 correct afterwards.</para> |
679 | 678 |
680 <para>It's often a good idea to refresh a patch that has applied | 679 <para id="x_3f8">It's often a good idea to refresh a patch that has applied |
681 with an offset or fuzz factor; refreshing the patch generates | 680 with an offset or fuzz factor; refreshing the patch generates |
682 new context information that will make it apply cleanly. I | 681 new context information that will make it apply cleanly. I |
683 say <quote>often,</quote> not <quote>always,</quote> because | 682 say <quote>often,</quote> not <quote>always,</quote> because |
684 sometimes refreshing a patch will make it fail to apply | 683 sometimes refreshing a patch will make it fail to apply |
685 against a different revision of the underlying files. In some | 684 against a different revision of the underlying files. In some |
690 | 689 |
691 </sect2> | 690 </sect2> |
692 <sect2> | 691 <sect2> |
693 <title>Handling rejection</title> | 692 <title>Handling rejection</title> |
694 | 693 |
695 <para>If <command role="hg-ext-mq">qpush</command> fails to | 694 <para id="x_3f9">If <command role="hg-ext-mq">qpush</command> fails to |
696 apply a patch, it will print an error message and exit. If it | 695 apply a patch, it will print an error message and exit. If it |
697 has left <filename role="special">.rej</filename> files | 696 has left <filename role="special">.rej</filename> files |
698 behind, it is usually best to fix up the rejected hunks before | 697 behind, it is usually best to fix up the rejected hunks before |
699 you push more patches or do any further work.</para> | 698 you push more patches or do any further work.</para> |
700 | 699 |
701 <para>If your patch <emphasis>used to</emphasis> apply cleanly, | 700 <para id="x_3fa">If your patch <emphasis>used to</emphasis> apply cleanly, |
702 and no longer does because you've changed the underlying code | 701 and no longer does because you've changed the underlying code |
703 that your patches are based on, Mercurial Queues can help; see | 702 that your patches are based on, Mercurial Queues can help; see |
704 section <xref | 703 <xref linkend="sec:mq:merge"/> for details.</para> |
705 linkend="sec.mq.merge"/> for details.</para> | 704 |
706 | 705 <para id="x_3fb">Unfortunately, there aren't any great techniques for |
707 <para>Unfortunately, there aren't any great techniques for | |
708 dealing with rejected hunks. Most often, you'll need to view | 706 dealing with rejected hunks. Most often, you'll need to view |
709 the <filename role="special">.rej</filename> file and edit the | 707 the <filename role="special">.rej</filename> file and edit the |
710 target file, applying the rejected hunks by hand.</para> | 708 target file, applying the rejected hunks by hand.</para> |
711 | 709 |
712 <para>If you're feeling adventurous, Neil Brown, a Linux kernel | 710 <para id="x_3fc">If you're feeling adventurous, Neil Brown, a Linux kernel |
713 hacker, wrote a tool called <command>wiggle</command> | 711 hacker, wrote a tool called <command>wiggle</command> |
714 <citation>web:wiggle</citation>, which is more vigorous than | 712 <citation>web:wiggle</citation>, which is more vigorous than |
715 <command>patch</command> in its attempts to make a patch | 713 <command>patch</command> in its attempts to make a patch |
716 apply.</para> | 714 apply.</para> |
717 | 715 |
718 <para>Another Linux kernel hacker, Chris Mason (the author of | 716 <para id="x_3fd">Another Linux kernel hacker, Chris Mason (the author of |
719 Mercurial Queues), wrote a similar tool called | 717 Mercurial Queues), wrote a similar tool called |
720 <command>mpatch</command> <citation>web:mpatch</citation>, | 718 <command>mpatch</command> <citation>web:mpatch</citation>, |
721 which takes a simple approach to automating the application of | 719 which takes a simple approach to automating the application of |
722 hunks rejected by <command>patch</command>. The | 720 hunks rejected by <command>patch</command>. The |
723 <command>mpatch</command> command can help with four common | 721 <command>mpatch</command> command can help with four common |
724 reasons that a hunk may be rejected:</para> | 722 reasons that a hunk may be rejected:</para> |
725 | 723 |
726 <itemizedlist> | 724 <itemizedlist> |
727 <listitem><para>The context in the middle of a hunk has | 725 <listitem><para id="x_3fe">The context in the middle of a hunk has |
728 changed.</para> | 726 changed.</para> |
729 </listitem> | 727 </listitem> |
730 <listitem><para>A hunk is missing some context at the | 728 <listitem><para id="x_3ff">A hunk is missing some context at the |
731 beginning or end.</para> | 729 beginning or end.</para> |
732 </listitem> | 730 </listitem> |
733 <listitem><para>A large hunk might apply better&emdash;either | 731 <listitem><para id="x_400">A large hunk might apply better&emdash;either |
734 entirely or in part&emdash;if it was broken up into | 732 entirely or in part&emdash;if it was broken up into |
735 smaller hunks.</para> | 733 smaller hunks.</para> |
736 </listitem> | 734 </listitem> |
737 <listitem><para>A hunk removes lines with slightly different | 735 <listitem><para id="x_401">A hunk removes lines with slightly different |
738 content than those currently present in the file.</para> | 736 content than those currently present in the file.</para> |
739 </listitem></itemizedlist> | 737 </listitem></itemizedlist> |
740 | 738 |
741 <para>If you use <command>wiggle</command> or | 739 <para id="x_402">If you use <command>wiggle</command> or |
742 <command>mpatch</command>, you should be doubly careful to | 740 <command>mpatch</command>, you should be doubly careful to |
743 check your results when you're done. In fact, | 741 check your results when you're done. In fact, |
744 <command>mpatch</command> enforces this method of | 742 <command>mpatch</command> enforces this method of |
745 double-checking the tool's output, by automatically dropping | 743 double-checking the tool's output, by automatically dropping |
746 you into a merge program when it has done its job, so that you | 744 you into a merge program when it has done its job, so that you |
747 can verify its work and finish off any remaining | 745 can verify its work and finish off any remaining |
748 merges.</para> | 746 merges.</para> |
749 | 747 |
750 </sect2> | 748 </sect2> |
751 </sect1> | 749 </sect1> |
752 <sect1 id="sec.mq.perf"> | 750 <sect1 id="sec:mq:perf"> |
753 <title>Getting the best performance out of MQ</title> | 751 <title>Getting the best performance out of MQ</title> |
754 | 752 |
755 <para>MQ is very efficient at handling a large number of patches. | 753 <para id="x_403">MQ is very efficient at handling a large number of patches. |
756 I ran some performance experiments in mid-2006 for a talk that I | 754 I ran some performance experiments in mid-2006 for a talk that I |
757 gave at the 2006 EuroPython conference | 755 gave at the 2006 EuroPython conference |
758 <citation>web:europython</citation>. I used as my data set the | 756 <citation>web:europython</citation>. I used as my data set the |
759 Linux 2.6.17-mm1 patch series, which consists of 1,738 patches. | 757 Linux 2.6.17-mm1 patch series, which consists of 1,738 patches. |
760 I applied these on top of a Linux kernel repository containing | 758 I applied these on top of a Linux kernel repository containing |
761 all 27,472 revisions between Linux 2.6.12-rc2 and Linux | 759 all 27,472 revisions between Linux 2.6.12-rc2 and Linux |
762 2.6.17.</para> | 760 2.6.17.</para> |
763 | 761 |
764 <para>On my old, slow laptop, I was able to <command | 762 <para id="x_404">On my old, slow laptop, I was able to <command |
765 role="hg-cmd">hg qpush <option | 763 role="hg-cmd">hg qpush <option |
766 role="hg-ext-mq-cmd-qpush-opt">hg -a</option></command> all | 764 role="hg-ext-mq-cmd-qpush-opt">hg -a</option></command> all |
767 1,738 patches in 3.5 minutes, and <command role="hg-cmd">hg qpop | 765 1,738 patches in 3.5 minutes, and <command role="hg-cmd">hg qpop |
768 <option role="hg-ext-mq-cmd-qpop-opt">hg -a</option></command> | 766 <option role="hg-ext-mq-cmd-qpop-opt">hg -a</option></command> |
769 them all in 30 seconds. (On a newer laptop, the time to push | 767 them all in 30 seconds. (On a newer laptop, the time to push |
770 all patches dropped to two minutes.) I could <command | 768 all patches dropped to two minutes.) I could <command |
771 role="hg-ext-mq">qrefresh</command> one of the biggest patches | 769 role="hg-ext-mq">qrefresh</command> one of the biggest patches |
772 (which made 22,779 lines of changes to 287 files) in 6.6 | 770 (which made 22,779 lines of changes to 287 files) in 6.6 |
773 seconds.</para> | 771 seconds.</para> |
774 | 772 |
775 <para>Clearly, MQ is well suited to working in large trees, but | 773 <para id="x_405">Clearly, MQ is well suited to working in large trees, but |
776 there are a few tricks you can use to get the best performance | 774 there are a few tricks you can use to get the best performance |
777 of it.</para> | 775 of it.</para> |
778 | 776 |
779 <para>First of all, try to <quote>batch</quote> operations | 777 <para id="x_406">First of all, try to <quote>batch</quote> operations |
780 together. Every time you run <command | 778 together. Every time you run <command |
781 role="hg-ext-mq">qpush</command> or <command | 779 role="hg-ext-mq">qpush</command> or <command |
782 role="hg-ext-mq">qpop</command>, these commands scan the | 780 role="hg-ext-mq">qpop</command>, these commands scan the |
783 working directory once to make sure you haven't made some | 781 working directory once to make sure you haven't made some |
784 changes and then forgotten to run <command | 782 changes and then forgotten to run <command |
785 role="hg-ext-mq">qrefresh</command>. On a small tree, the | 783 role="hg-ext-mq">qrefresh</command>. On a small tree, the |
786 time that this scan takes is unnoticeable. However, on a | 784 time that this scan takes is unnoticeable. However, on a |
787 medium-sized tree (containing tens of thousands of files), it | 785 medium-sized tree (containing tens of thousands of files), it |
788 can take a second or more.</para> | 786 can take a second or more.</para> |
789 | 787 |
790 <para>The <command role="hg-ext-mq">qpush</command> and <command | 788 <para id="x_407">The <command role="hg-ext-mq">qpush</command> and <command |
791 role="hg-ext-mq">qpop</command> commands allow you to push and | 789 role="hg-ext-mq">qpop</command> commands allow you to push and |
792 pop multiple patches at a time. You can identify the | 790 pop multiple patches at a time. You can identify the |
793 <quote>destination patch</quote> that you want to end up at. | 791 <quote>destination patch</quote> that you want to end up at. |
794 When you <command role="hg-ext-mq">qpush</command> with a | 792 When you <command role="hg-ext-mq">qpush</command> with a |
795 destination specified, it will push patches until that patch is | 793 destination specified, it will push patches until that patch is |
796 at the top of the applied stack. When you <command | 794 at the top of the applied stack. When you <command |
797 role="hg-ext-mq">qpop</command> to a destination, MQ will pop | 795 role="hg-ext-mq">qpop</command> to a destination, MQ will pop |
798 patches until the destination patch is at the top.</para> | 796 patches until the destination patch is at the top.</para> |
799 | 797 |
800 <para>You can identify a destination patch using either the name | 798 <para id="x_408">You can identify a destination patch using either the name |
801 of the patch, or by number. If you use numeric addressing, | 799 of the patch, or by number. If you use numeric addressing, |
802 patches are counted from zero; this means that the first patch | 800 patches are counted from zero; this means that the first patch |
803 is zero, the second is one, and so on.</para> | 801 is zero, the second is one, and so on.</para> |
804 | 802 |
805 </sect1> | 803 </sect1> |
806 <sect1 id="sec.mq.merge"> | 804 <sect1 id="sec:mq:merge"> |
807 <title>Updating your patches when the underlying code | 805 <title>Updating your patches when the underlying code |
808 changes</title> | 806 changes</title> |
809 | 807 |
810 <para>It's common to have a stack of patches on top of an | 808 <para id="x_409">It's common to have a stack of patches on top of an |
811 underlying repository that you don't modify directly. If you're | 809 underlying repository that you don't modify directly. If you're |
812 working on changes to third-party code, or on a feature that is | 810 working on changes to third-party code, or on a feature that is |
813 taking longer to develop than the rate of change of the code | 811 taking longer to develop than the rate of change of the code |
814 beneath, you will often need to sync up with the underlying | 812 beneath, you will often need to sync up with the underlying |
815 code, and fix up any hunks in your patches that no longer apply. | 813 code, and fix up any hunks in your patches that no longer apply. |
816 This is called <emphasis>rebasing</emphasis> your patch | 814 This is called <emphasis>rebasing</emphasis> your patch |
817 series.</para> | 815 series.</para> |
818 | 816 |
819 <para>The simplest way to do this is to <command role="hg-cmd">hg | 817 <para id="x_40a">The simplest way to do this is to <command role="hg-cmd">hg |
820 qpop <option role="hg-ext-mq-cmd-qpop-opt">hg | 818 qpop <option role="hg-ext-mq-cmd-qpop-opt">hg |
821 -a</option></command> your patches, then <command | 819 -a</option></command> your patches, then <command |
822 role="hg-cmd">hg pull</command> changes into the underlying | 820 role="hg-cmd">hg pull</command> changes into the underlying |
823 repository, and finally <command role="hg-cmd">hg qpush <option | 821 repository, and finally <command role="hg-cmd">hg qpush <option |
824 role="hg-ext-mq-cmd-qpop-opt">hg -a</option></command> your | 822 role="hg-ext-mq-cmd-qpop-opt">hg -a</option></command> your |
826 patch that fails to apply during conflicts, allowing you to fix | 824 patch that fails to apply during conflicts, allowing you to fix |
827 your conflicts, <command role="hg-ext-mq">qrefresh</command> the | 825 your conflicts, <command role="hg-ext-mq">qrefresh</command> the |
828 affected patch, and continue pushing until you have fixed your | 826 affected patch, and continue pushing until you have fixed your |
829 entire stack.</para> | 827 entire stack.</para> |
830 | 828 |
831 <para>This approach is easy to use and works well if you don't | 829 <para id="x_40b">This approach is easy to use and works well if you don't |
832 expect changes to the underlying code to affect how well your | 830 expect changes to the underlying code to affect how well your |
833 patches apply. If your patch stack touches code that is modified | 831 patches apply. If your patch stack touches code that is modified |
834 frequently or invasively in the underlying repository, however, | 832 frequently or invasively in the underlying repository, however, |
835 fixing up rejected hunks by hand quickly becomes | 833 fixing up rejected hunks by hand quickly becomes |
836 tiresome.</para> | 834 tiresome.</para> |
837 | 835 |
838 <para>It's possible to partially automate the rebasing process. | 836 <para id="x_40c">It's possible to partially automate the rebasing process. |
839 If your patches apply cleanly against some revision of the | 837 If your patches apply cleanly against some revision of the |
840 underlying repo, MQ can use this information to help you to | 838 underlying repo, MQ can use this information to help you to |
841 resolve conflicts between your patches and a different | 839 resolve conflicts between your patches and a different |
842 revision.</para> | 840 revision.</para> |
843 | 841 |
844 <para>The process is a little involved.</para> | 842 <para id="x_40d">The process is a little involved.</para> |
845 <orderedlist> | 843 <orderedlist> |
846 <listitem><para>To begin, <command role="hg-cmd">hg qpush | 844 <listitem><para id="x_40e">To begin, <command role="hg-cmd">hg qpush |
847 -a</command> all of your patches on top of the revision | 845 -a</command> all of your patches on top of the revision |
848 where you know that they apply cleanly.</para> | 846 where you know that they apply cleanly.</para> |
849 </listitem> | 847 </listitem> |
850 <listitem><para>Save a backup copy of your patch directory using | 848 <listitem><para id="x_40f">Save a backup copy of your patch directory using |
851 <command role="hg-cmd">hg qsave <option | 849 <command role="hg-cmd">hg qsave <option |
852 role="hg-ext-mq-cmd-qsave-opt">hg -e</option> <option | 850 role="hg-ext-mq-cmd-qsave-opt">hg -e</option> <option |
853 role="hg-ext-mq-cmd-qsave-opt">hg -c</option></command>. | 851 role="hg-ext-mq-cmd-qsave-opt">hg -c</option></command>. |
854 This prints the name of the directory that it has saved the | 852 This prints the name of the directory that it has saved the |
855 patches in. It will save the patches to a directory called | 853 patches in. It will save the patches to a directory called |
859 <quote>save changeset</quote> on top of your applied | 857 <quote>save changeset</quote> on top of your applied |
860 patches; this is for internal book-keeping, and records the | 858 patches; this is for internal book-keeping, and records the |
861 states of the <filename role="special">series</filename> and | 859 states of the <filename role="special">series</filename> and |
862 <filename role="special">status</filename> files.</para> | 860 <filename role="special">status</filename> files.</para> |
863 </listitem> | 861 </listitem> |
864 <listitem><para>Use <command role="hg-cmd">hg pull</command> to | 862 <listitem><para id="x_410">Use <command role="hg-cmd">hg pull</command> to |
865 bring new changes into the underlying repository. (Don't | 863 bring new changes into the underlying repository. (Don't |
866 run <command role="hg-cmd">hg pull -u</command>; see below | 864 run <command role="hg-cmd">hg pull -u</command>; see below |
867 for why.)</para> | 865 for why.)</para> |
868 </listitem> | 866 </listitem> |
869 <listitem><para>Update to the new tip revision, using <command | 867 <listitem><para id="x_411">Update to the new tip revision, using <command |
870 role="hg-cmd">hg update <option | 868 role="hg-cmd">hg update <option |
871 role="hg-opt-update">-C</option></command> to override | 869 role="hg-opt-update">-C</option></command> to override |
872 the patches you have pushed.</para> | 870 the patches you have pushed.</para> |
873 </listitem> | 871 </listitem> |
874 <listitem><para>Merge all patches using <command>hg qpush -m | 872 <listitem><para id="x_412">Merge all patches using <command>hg qpush -m |
875 -a</command>. The <option | 873 -a</command>. The <option |
876 role="hg-ext-mq-cmd-qpush-opt">-m</option> option to | 874 role="hg-ext-mq-cmd-qpush-opt">-m</option> option to |
877 <command role="hg-ext-mq">qpush</command> tells MQ to | 875 <command role="hg-ext-mq">qpush</command> tells MQ to |
878 perform a three-way merge if the patch fails to | 876 perform a three-way merge if the patch fails to |
879 apply.</para> | 877 apply.</para> |
880 </listitem></orderedlist> | 878 </listitem></orderedlist> |
881 | 879 |
882 <para>During the <command role="hg-cmd">hg qpush <option | 880 <para id="x_413">During the <command role="hg-cmd">hg qpush <option |
883 role="hg-ext-mq-cmd-qpush-opt">hg -m</option></command>, | 881 role="hg-ext-mq-cmd-qpush-opt">hg -m</option></command>, |
884 each patch in the <filename role="special">series</filename> | 882 each patch in the <filename role="special">series</filename> |
885 file is applied normally. If a patch applies with fuzz or | 883 file is applied normally. If a patch applies with fuzz or |
886 rejects, MQ looks at the queue you <command | 884 rejects, MQ looks at the queue you <command |
887 role="hg-ext-mq">qsave</command>d, and performs a three-way | 885 role="hg-ext-mq">qsave</command>d, and performs a three-way |
888 merge with the corresponding changeset. This merge uses | 886 merge with the corresponding changeset. This merge uses |
889 Mercurial's normal merge machinery, so it may pop up a GUI merge | 887 Mercurial's normal merge machinery, so it may pop up a GUI merge |
890 tool to help you to resolve problems.</para> | 888 tool to help you to resolve problems.</para> |
891 | 889 |
892 <para>When you finish resolving the effects of a patch, MQ | 890 <para id="x_414">When you finish resolving the effects of a patch, MQ |
893 refreshes your patch based on the result of the merge.</para> | 891 refreshes your patch based on the result of the merge.</para> |
894 | 892 |
895 <para>At the end of this process, your repository will have one | 893 <para id="x_415">At the end of this process, your repository will have one |
896 extra head from the old patch queue, and a copy of the old patch | 894 extra head from the old patch queue, and a copy of the old patch |
897 queue will be in <filename role="special" | 895 queue will be in <filename role="special" |
898 class="directory">.hg/patches.N</filename>. You can remove the | 896 class="directory">.hg/patches.N</filename>. You can remove the |
899 extra head using <command role="hg-cmd">hg qpop -a -n | 897 extra head using <command role="hg-cmd">hg qpop -a -n |
900 patches.N</command> or <command role="hg-cmd">hg | 898 patches.N</command> or <command role="hg-cmd">hg |
904 | 902 |
905 </sect1> | 903 </sect1> |
906 <sect1> | 904 <sect1> |
907 <title>Identifying patches</title> | 905 <title>Identifying patches</title> |
908 | 906 |
909 <para>MQ commands that work with patches let you refer to a patch | 907 <para id="x_416">MQ commands that work with patches let you refer to a patch |
910 either by using its name or by a number. By name is obvious | 908 either by using its name or by a number. By name is obvious |
911 enough; pass the name <filename>foo.patch</filename> to <command | 909 enough; pass the name <filename>foo.patch</filename> to <command |
912 role="hg-ext-mq">qpush</command>, for example, and it will | 910 role="hg-ext-mq">qpush</command>, for example, and it will |
913 push patches until <filename>foo.patch</filename> is | 911 push patches until <filename>foo.patch</filename> is |
914 applied.</para> | 912 applied.</para> |
915 | 913 |
916 <para>As a shortcut, you can refer to a patch using both a name | 914 <para id="x_417">As a shortcut, you can refer to a patch using both a name |
917 and a numeric offset; <literal>foo.patch-2</literal> means | 915 and a numeric offset; <literal>foo.patch-2</literal> means |
918 <quote>two patches before <literal>foo.patch</literal></quote>, | 916 <quote>two patches before <literal>foo.patch</literal></quote>, |
919 while <literal>bar.patch+4</literal> means <quote>four patches | 917 while <literal>bar.patch+4</literal> means <quote>four patches |
920 after <literal>bar.patch</literal></quote>.</para> | 918 after <literal>bar.patch</literal></quote>.</para> |
921 | 919 |
922 <para>Referring to a patch by index isn't much different. The | 920 <para id="x_418">Referring to a patch by index isn't much different. The |
923 first patch printed in the output of <command | 921 first patch printed in the output of <command |
924 role="hg-ext-mq">qseries</command> is patch zero (yes, it's | 922 role="hg-ext-mq">qseries</command> is patch zero (yes, it's |
925 one of those start-at-zero counting systems); the second is | 923 one of those start-at-zero counting systems); the second is |
926 patch one; and so on.</para> | 924 patch one; and so on.</para> |
927 | 925 |
928 <para>MQ also makes it easy to work with patches when you are | 926 <para id="x_419">MQ also makes it easy to work with patches when you are |
929 using normal Mercurial commands. Every command that accepts a | 927 using normal Mercurial commands. Every command that accepts a |
930 changeset ID will also accept the name of an applied patch. MQ | 928 changeset ID will also accept the name of an applied patch. MQ |
931 augments the tags normally in the repository with an eponymous | 929 augments the tags normally in the repository with an eponymous |
932 one for each applied patch. In addition, the special tags | 930 one for each applied patch. In addition, the special tags |
933 <literal role="tag">qbase</literal> and | 931 <literal role="tag">qbase</literal> and |
934 <literal role="tag">qtip</literal> identify | 932 <literal role="tag">qtip</literal> identify |
935 the <quote>bottom-most</quote> and topmost applied patches, | 933 the <quote>bottom-most</quote> and topmost applied patches, |
936 respectively.</para> | 934 respectively.</para> |
937 | 935 |
938 <para>These additions to Mercurial's normal tagging capabilities | 936 <para id="x_41a">These additions to Mercurial's normal tagging capabilities |
939 make dealing with patches even more of a breeze.</para> | 937 make dealing with patches even more of a breeze.</para> |
940 <itemizedlist> | 938 <itemizedlist> |
941 <listitem><para>Want to patchbomb a mailing list with your | 939 <listitem><para id="x_41b">Want to patchbomb a mailing list with your |
942 latest series of changes?</para> | 940 latest series of changes?</para> |
943 <programlisting>hg email qbase:qtip</programlisting> | 941 <programlisting>hg email qbase:qtip</programlisting> |
944 <para> (Don't know what <quote>patchbombing</quote> is? See | 942 <para id="x_41c"> (Don't know what <quote>patchbombing</quote> is? See |
945 section <xref linkend="sec.hgext.patchbomb"/>.)</para> | 943 <xref linkend="sec:hgext:patchbomb"/>.)</para> |
946 </listitem> | 944 </listitem> |
947 <listitem><para>Need to see all of the patches since | 945 <listitem><para id="x_41d">Need to see all of the patches since |
948 <literal>foo.patch</literal> that have touched files in a | 946 <literal>foo.patch</literal> that have touched files in a |
949 subdirectory of your tree?</para> | 947 subdirectory of your tree?</para> |
950 <programlisting>hg log -r foo.patch:qtip subdir</programlisting> | 948 <programlisting>hg log -r foo.patch:qtip subdir</programlisting> |
951 </listitem> | 949 </listitem> |
952 </itemizedlist> | 950 </itemizedlist> |
953 | 951 |
954 <para>Because MQ makes the names of patches available to the rest | 952 <para id="x_41e">Because MQ makes the names of patches available to the rest |
955 of Mercurial through its normal internal tag machinery, you | 953 of Mercurial through its normal internal tag machinery, you |
956 don't need to type in the entire name of a patch when you want | 954 don't need to type in the entire name of a patch when you want |
957 to identify it by name.</para> | 955 to identify it by name.</para> |
958 | 956 |
959 <para>Another nice consequence of representing patch names as tags | 957 <para id="x_41f">Another nice consequence of representing patch names as tags |
960 is that when you run the <command role="hg-cmd">hg log</command> | 958 is that when you run the <command role="hg-cmd">hg log</command> |
961 command, it will display a patch's name as a tag, simply as part | 959 command, it will display a patch's name as a tag, simply as part |
962 of its normal output. This makes it easy to visually | 960 of its normal output. This makes it easy to visually |
963 distinguish applied patches from underlying | 961 distinguish applied patches from underlying |
964 <quote>normal</quote> revisions. The following example shows a | 962 <quote>normal</quote> revisions. The following example shows a |
969 | 967 |
970 </sect1> | 968 </sect1> |
971 <sect1> | 969 <sect1> |
972 <title>Useful things to know about</title> | 970 <title>Useful things to know about</title> |
973 | 971 |
974 <para>There are a number of aspects of MQ usage that don't fit | 972 <para id="x_420">There are a number of aspects of MQ usage that don't fit |
975 tidily into sections of their own, but that are good to know. | 973 tidily into sections of their own, but that are good to know. |
976 Here they are, in one place.</para> | 974 Here they are, in one place.</para> |
977 | 975 |
978 <itemizedlist> | 976 <itemizedlist> |
979 <listitem><para>Normally, when you <command | 977 <listitem><para id="x_421">Normally, when you <command |
980 role="hg-ext-mq">qpop</command> a patch and <command | 978 role="hg-ext-mq">qpop</command> a patch and <command |
981 role="hg-ext-mq">qpush</command> it again, the changeset | 979 role="hg-ext-mq">qpush</command> it again, the changeset |
982 that represents the patch after the pop/push will have a | 980 that represents the patch after the pop/push will have a |
983 <emphasis>different identity</emphasis> than the changeset | 981 <emphasis>different identity</emphasis> than the changeset |
984 that represented the hash beforehand. See section <xref | 982 that represented the hash beforehand. See <xref |
985 linkend="sec.mqref.cmd.qpush"/> for | 983 linkend="sec:mqref:cmd:qpush"/> for |
986 information as to why this is.</para> | 984 information as to why this is.</para> |
987 </listitem> | 985 </listitem> |
988 <listitem><para>It's not a good idea to <command | 986 <listitem><para id="x_422">It's not a good idea to <command |
989 role="hg-cmd">hg merge</command> changes from another | 987 role="hg-cmd">hg merge</command> changes from another |
990 branch with a patch changeset, at least if you want to | 988 branch with a patch changeset, at least if you want to |
991 maintain the <quote>patchiness</quote> of that changeset and | 989 maintain the <quote>patchiness</quote> of that changeset and |
992 changesets below it on the patch stack. If you try to do | 990 changesets below it on the patch stack. If you try to do |
993 this, it will appear to succeed, but MQ will become | 991 this, it will appear to succeed, but MQ will become |
994 confused.</para> | 992 confused.</para> |
995 </listitem></itemizedlist> | 993 </listitem></itemizedlist> |
996 | 994 |
997 </sect1> | 995 </sect1> |
998 <sect1 id="sec.mq.repo"> | 996 <sect1 id="sec:mq:repo"> |
999 <title>Managing patches in a repository</title> | 997 <title>Managing patches in a repository</title> |
1000 | 998 |
1001 <para>Because MQ's <filename role="special" | 999 <para id="x_423">Because MQ's <filename role="special" |
1002 class="directory">.hg/patches</filename> directory resides | 1000 class="directory">.hg/patches</filename> directory resides |
1003 outside a Mercurial repository's working directory, the | 1001 outside a Mercurial repository's working directory, the |
1004 <quote>underlying</quote> Mercurial repository knows nothing | 1002 <quote>underlying</quote> Mercurial repository knows nothing |
1005 about the management or presence of patches.</para> | 1003 about the management or presence of patches.</para> |
1006 | 1004 |
1007 <para>This presents the interesting possibility of managing the | 1005 <para id="x_424">This presents the interesting possibility of managing the |
1008 contents of the patch directory as a Mercurial repository in its | 1006 contents of the patch directory as a Mercurial repository in its |
1009 own right. This can be a useful way to work. For example, you | 1007 own right. This can be a useful way to work. For example, you |
1010 can work on a patch for a while, <command | 1008 can work on a patch for a while, <command |
1011 role="hg-ext-mq">qrefresh</command> it, then <command | 1009 role="hg-ext-mq">qrefresh</command> it, then <command |
1012 role="hg-cmd">hg commit</command> the current state of the | 1010 role="hg-cmd">hg commit</command> the current state of the |
1013 patch. This lets you <quote>roll back</quote> to that version | 1011 patch. This lets you <quote>roll back</quote> to that version |
1014 of the patch later on.</para> | 1012 of the patch later on.</para> |
1015 | 1013 |
1016 <para>You can then share different versions of the same patch | 1014 <para id="x_425">You can then share different versions of the same patch |
1017 stack among multiple underlying repositories. I use this when I | 1015 stack among multiple underlying repositories. I use this when I |
1018 am developing a Linux kernel feature. I have a pristine copy of | 1016 am developing a Linux kernel feature. I have a pristine copy of |
1019 my kernel sources for each of several CPU architectures, and a | 1017 my kernel sources for each of several CPU architectures, and a |
1020 cloned repository under each that contains the patches I am | 1018 cloned repository under each that contains the patches I am |
1021 working on. When I want to test a change on a different | 1019 working on. When I want to test a change on a different |
1022 architecture, I push my current patches to the patch repository | 1020 architecture, I push my current patches to the patch repository |
1023 associated with that kernel tree, pop and push all of my | 1021 associated with that kernel tree, pop and push all of my |
1024 patches, and build and test that kernel.</para> | 1022 patches, and build and test that kernel.</para> |
1025 | 1023 |
1026 <para>Managing patches in a repository makes it possible for | 1024 <para id="x_426">Managing patches in a repository makes it possible for |
1027 multiple developers to work on the same patch series without | 1025 multiple developers to work on the same patch series without |
1028 colliding with each other, all on top of an underlying source | 1026 colliding with each other, all on top of an underlying source |
1029 base that they may or may not control.</para> | 1027 base that they may or may not control.</para> |
1030 | 1028 |
1031 <sect2> | 1029 <sect2> |
1032 <title>MQ support for patch repositories</title> | 1030 <title>MQ support for patch repositories</title> |
1033 | 1031 |
1034 <para>MQ helps you to work with the <filename role="special" | 1032 <para id="x_427">MQ helps you to work with the <filename role="special" |
1035 class="directory">.hg/patches</filename> directory as a | 1033 class="directory">.hg/patches</filename> directory as a |
1036 repository; when you prepare a repository for working with | 1034 repository; when you prepare a repository for working with |
1037 patches using <command role="hg-ext-mq">qinit</command>, you | 1035 patches using <command role="hg-ext-mq">qinit</command>, you |
1038 can pass the <option role="hg-ext-mq-cmd-qinit-opt">hg | 1036 can pass the <option role="hg-ext-mq-cmd-qinit-opt">hg |
1039 -c</option> option to create the <filename role="special" | 1037 -c</option> option to create the <filename role="special" |
1040 class="directory">.hg/patches</filename> directory as a | 1038 class="directory">.hg/patches</filename> directory as a |
1041 Mercurial repository.</para> | 1039 Mercurial repository.</para> |
1042 | 1040 |
1043 <note> | 1041 <note> |
1044 <para> If you forget to use the <option | 1042 <para id="x_428"> If you forget to use the <option |
1045 role="hg-ext-mq-cmd-qinit-opt">hg -c</option> option, you | 1043 role="hg-ext-mq-cmd-qinit-opt">hg -c</option> option, you |
1046 can simply go into the <filename role="special" | 1044 can simply go into the <filename role="special" |
1047 class="directory">.hg/patches</filename> directory at any | 1045 class="directory">.hg/patches</filename> directory at any |
1048 time and run <command role="hg-cmd">hg init</command>. | 1046 time and run <command role="hg-cmd">hg init</command>. |
1049 Don't forget to add an entry for the <filename | 1047 Don't forget to add an entry for the <filename |
1050 role="special">status</filename> file to the <filename | 1048 role="special">status</filename> file to the <filename |
1051 role="special">.hgignore</filename> file, though</para> | 1049 role="special">.hgignore</filename> file, though</para> |
1052 | 1050 |
1053 <para> (<command role="hg-cmd">hg qinit <option | 1051 <para id="x_429"> (<command role="hg-cmd">hg qinit <option |
1054 role="hg-ext-mq-cmd-qinit-opt">hg -c</option></command> | 1052 role="hg-ext-mq-cmd-qinit-opt">hg -c</option></command> |
1055 does this for you automatically); you | 1053 does this for you automatically); you |
1056 <emphasis>really</emphasis> don't want to manage the | 1054 <emphasis>really</emphasis> don't want to manage the |
1057 <filename role="special">status</filename> file.</para> | 1055 <filename role="special">status</filename> file.</para> |
1058 </note> | 1056 </note> |
1059 | 1057 |
1060 <para>As a convenience, if MQ notices that the <filename | 1058 <para id="x_42a">As a convenience, if MQ notices that the <filename |
1061 class="directory">.hg/patches</filename> directory is a | 1059 class="directory">.hg/patches</filename> directory is a |
1062 repository, it will automatically <command role="hg-cmd">hg | 1060 repository, it will automatically <command role="hg-cmd">hg |
1063 add</command> every patch that you create and import.</para> | 1061 add</command> every patch that you create and import.</para> |
1064 | 1062 |
1065 <para>MQ provides a shortcut command, <command | 1063 <para id="x_42b">MQ provides a shortcut command, <command |
1066 role="hg-ext-mq">qcommit</command>, that runs <command | 1064 role="hg-ext-mq">qcommit</command>, that runs <command |
1067 role="hg-cmd">hg commit</command> in the <filename | 1065 role="hg-cmd">hg commit</command> in the <filename |
1068 role="special" class="directory">.hg/patches</filename> | 1066 role="special" class="directory">.hg/patches</filename> |
1069 directory. This saves some bothersome typing.</para> | 1067 directory. This saves some bothersome typing.</para> |
1070 | 1068 |
1071 <para>Finally, as a convenience to manage the patch directory, | 1069 <para id="x_42c">Finally, as a convenience to manage the patch directory, |
1072 you can define the alias <command>mq</command> on Unix | 1070 you can define the alias <command>mq</command> on Unix |
1073 systems. For example, on Linux systems using the | 1071 systems. For example, on Linux systems using the |
1074 <command>bash</command> shell, you can include the following | 1072 <command>bash</command> shell, you can include the following |
1075 snippet in your <filename | 1073 snippet in your <filename |
1076 role="home">~/.bashrc</filename>.</para> | 1074 role="home">~/.bashrc</filename>.</para> |
1077 | 1075 |
1078 <programlisting>alias mq=`hg -R $(hg root)/.hg/patches'</programlisting> | 1076 <programlisting>alias mq=`hg -R $(hg root)/.hg/patches'</programlisting> |
1079 | 1077 |
1080 <para>You can then issue commands of the form <command>mq | 1078 <para id="x_42d">You can then issue commands of the form <command>mq |
1081 pull</command> from the main repository.</para> | 1079 pull</command> from the main repository.</para> |
1082 | 1080 |
1083 </sect2> | 1081 </sect2> |
1084 <sect2> | 1082 <sect2> |
1085 <title>A few things to watch out for</title> | 1083 <title>A few things to watch out for</title> |
1086 | 1084 |
1087 <para>MQ's support for working with a repository full of patches | 1085 <para id="x_42e">MQ's support for working with a repository full of patches |
1088 is limited in a few small respects.</para> | 1086 is limited in a few small respects.</para> |
1089 | 1087 |
1090 <para>MQ cannot automatically detect changes that you make to | 1088 <para id="x_42f">MQ cannot automatically detect changes that you make to |
1091 the patch directory. If you <command role="hg-cmd">hg | 1089 the patch directory. If you <command role="hg-cmd">hg |
1092 pull</command>, manually edit, or <command role="hg-cmd">hg | 1090 pull</command>, manually edit, or <command role="hg-cmd">hg |
1093 update</command> changes to patches or the <filename | 1091 update</command> changes to patches or the <filename |
1094 role="special">series</filename> file, you will have to | 1092 role="special">series</filename> file, you will have to |
1095 <command role="hg-cmd">hg qpop <option | 1093 <command role="hg-cmd">hg qpop <option |
1100 If you forget to do this, you can confuse MQ's idea of which | 1098 If you forget to do this, you can confuse MQ's idea of which |
1101 patches are applied.</para> | 1099 patches are applied.</para> |
1102 | 1100 |
1103 </sect2> | 1101 </sect2> |
1104 </sect1> | 1102 </sect1> |
1105 <sect1 id="sec.mq.tools"> | 1103 <sect1 id="sec:mq:tools"> |
1106 <title>Third party tools for working with patches</title> | 1104 <title>Third party tools for working with patches</title> |
1107 | 1105 |
1108 <para>Once you've been working with patches for a while, you'll | 1106 <para id="x_430">Once you've been working with patches for a while, you'll |
1109 find yourself hungry for tools that will help you to understand | 1107 find yourself hungry for tools that will help you to understand |
1110 and manipulate the patches you're dealing with.</para> | 1108 and manipulate the patches you're dealing with.</para> |
1111 | 1109 |
1112 <para>The <command>diffstat</command> command | 1110 <para id="x_431">The <command>diffstat</command> command |
1113 <citation>web:diffstat</citation> generates a histogram of the | 1111 <citation>web:diffstat</citation> generates a histogram of the |
1114 modifications made to each file in a patch. It provides a good | 1112 modifications made to each file in a patch. It provides a good |
1115 way to <quote>get a sense of</quote> a patch&emdash;which files | 1113 way to <quote>get a sense of</quote> a patch&emdash;which files |
1116 it affects, and how much change it introduces to each file and | 1114 it affects, and how much change it introduces to each file and |
1117 as a whole. (I find that it's a good idea to use | 1115 as a whole. (I find that it's a good idea to use |
1121 prefixes of file names that inevitably confuse at least | 1119 prefixes of file names that inevitably confuse at least |
1122 me.)</para> | 1120 me.)</para> |
1123 | 1121 |
1124 &interaction.mq.tools.tools; | 1122 &interaction.mq.tools.tools; |
1125 | 1123 |
1126 <para>The <literal role="package">patchutils</literal> package | 1124 <para id="x_432">The <literal role="package">patchutils</literal> package |
1127 <citation>web:patchutils</citation> is invaluable. It provides a | 1125 <citation>web:patchutils</citation> is invaluable. It provides a |
1128 set of small utilities that follow the <quote>Unix | 1126 set of small utilities that follow the <quote>Unix |
1129 philosophy;</quote> each does one useful thing with a patch. | 1127 philosophy;</quote> each does one useful thing with a patch. |
1130 The <literal role="package">patchutils</literal> command I use | 1128 The <literal role="package">patchutils</literal> command I use |
1131 most is <command>filterdiff</command>, which extracts subsets | 1129 most is <command>filterdiff</command>, which extracts subsets |
1132 from a patch file. For example, given a patch that modifies | 1130 from a patch file. For example, given a patch that modifies |
1133 hundreds of files across dozens of directories, a single | 1131 hundreds of files across dozens of directories, a single |
1134 invocation of <command>filterdiff</command> can generate a | 1132 invocation of <command>filterdiff</command> can generate a |
1135 smaller patch that only touches files whose names match a | 1133 smaller patch that only touches files whose names match a |
1136 particular glob pattern. See section <xref | 1134 particular glob pattern. See <xref |
1137 linkend="mq-collab.tips.interdiff"/> for another | 1135 linkend="mq-collab:tips:interdiff"/> for another |
1138 example.</para> | 1136 example.</para> |
1139 | 1137 |
1140 </sect1> | 1138 </sect1> |
1141 <sect1> | 1139 <sect1> |
1142 <title>Good ways to work with patches</title> | 1140 <title>Good ways to work with patches</title> |
1143 | 1141 |
1144 <para>Whether you are working on a patch series to submit to a | 1142 <para id="x_433">Whether you are working on a patch series to submit to a |
1145 free software or open source project, or a series that you | 1143 free software or open source project, or a series that you |
1146 intend to treat as a sequence of regular changesets when you're | 1144 intend to treat as a sequence of regular changesets when you're |
1147 done, you can use some simple techniques to keep your work well | 1145 done, you can use some simple techniques to keep your work well |
1148 organised.</para> | 1146 organised.</para> |
1149 | 1147 |
1150 <para>Give your patches descriptive names. A good name for a | 1148 <para id="x_434">Give your patches descriptive names. A good name for a |
1151 patch might be <filename>rework-device-alloc.patch</filename>, | 1149 patch might be <filename>rework-device-alloc.patch</filename>, |
1152 because it will immediately give you a hint what the purpose of | 1150 because it will immediately give you a hint what the purpose of |
1153 the patch is. Long names shouldn't be a problem; you won't be | 1151 the patch is. Long names shouldn't be a problem; you won't be |
1154 typing the names often, but you <emphasis>will</emphasis> be | 1152 typing the names often, but you <emphasis>will</emphasis> be |
1155 running commands like <command | 1153 running commands like <command |
1157 role="hg-ext-mq">qtop</command> over and over. Good naming | 1155 role="hg-ext-mq">qtop</command> over and over. Good naming |
1158 becomes especially important when you have a number of patches | 1156 becomes especially important when you have a number of patches |
1159 to work with, or if you are juggling a number of different tasks | 1157 to work with, or if you are juggling a number of different tasks |
1160 and your patches only get a fraction of your attention.</para> | 1158 and your patches only get a fraction of your attention.</para> |
1161 | 1159 |
1162 <para>Be aware of what patch you're working on. Use the <command | 1160 <para id="x_435">Be aware of what patch you're working on. Use the <command |
1163 role="hg-ext-mq">qtop</command> command and skim over the text | 1161 role="hg-ext-mq">qtop</command> command and skim over the text |
1164 of your patches frequently&emdash;for example, using <command | 1162 of your patches frequently&emdash;for example, using <command |
1165 role="hg-cmd">hg tip <option | 1163 role="hg-cmd">hg tip <option |
1166 role="hg-opt-tip">-p</option></command>)&emdash;to be sure | 1164 role="hg-opt-tip">-p</option></command>)&emdash;to be sure |
1167 of where you stand. I have several times worked on and <command | 1165 of where you stand. I have several times worked on and <command |
1168 role="hg-ext-mq">qrefresh</command>ed a patch other than the | 1166 role="hg-ext-mq">qrefresh</command>ed a patch other than the |
1169 one I intended, and it's often tricky to migrate changes into | 1167 one I intended, and it's often tricky to migrate changes into |
1170 the right patch after making them in the wrong one.</para> | 1168 the right patch after making them in the wrong one.</para> |
1171 | 1169 |
1172 <para>For this reason, it is very much worth investing a little | 1170 <para id="x_436">For this reason, it is very much worth investing a little |
1173 time to learn how to use some of the third-party tools I | 1171 time to learn how to use some of the third-party tools I |
1174 described in section <xref linkend="sec.mq.tools"/>, | 1172 described in <xref linkend="sec:mq:tools"/>, |
1175 particularly | 1173 particularly |
1176 <command>diffstat</command> and <command>filterdiff</command>. | 1174 <command>diffstat</command> and <command>filterdiff</command>. |
1177 The former will give you a quick idea of what changes your patch | 1175 The former will give you a quick idea of what changes your patch |
1178 is making, while the latter makes it easy to splice hunks | 1176 is making, while the latter makes it easy to splice hunks |
1179 selectively out of one patch and into another.</para> | 1177 selectively out of one patch and into another.</para> |
1183 <title>MQ cookbook</title> | 1181 <title>MQ cookbook</title> |
1184 | 1182 |
1185 <sect2> | 1183 <sect2> |
1186 <title>Manage <quote>trivial</quote> patches</title> | 1184 <title>Manage <quote>trivial</quote> patches</title> |
1187 | 1185 |
1188 <para>Because the overhead of dropping files into a new | 1186 <para id="x_437">Because the overhead of dropping files into a new |
1189 Mercurial repository is so low, it makes a lot of sense to | 1187 Mercurial repository is so low, it makes a lot of sense to |
1190 manage patches this way even if you simply want to make a few | 1188 manage patches this way even if you simply want to make a few |
1191 changes to a source tarball that you downloaded.</para> | 1189 changes to a source tarball that you downloaded.</para> |
1192 | 1190 |
1193 <para>Begin by downloading and unpacking the source tarball, and | 1191 <para id="x_438">Begin by downloading and unpacking the source tarball, and |
1194 turning it into a Mercurial repository.</para> | 1192 turning it into a Mercurial repository.</para> |
1195 | 1193 |
1196 &interaction.mq.tarball.download; | 1194 &interaction.mq.tarball.download; |
1197 | 1195 |
1198 <para>Continue by creating a patch stack and making your | 1196 <para id="x_439">Continue by creating a patch stack and making your |
1199 changes.</para> | 1197 changes.</para> |
1200 | 1198 |
1201 &interaction.mq.tarball.qinit; | 1199 &interaction.mq.tarball.qinit; |
1202 | 1200 |
1203 <para>Let's say a few weeks or months pass, and your package | 1201 <para id="x_43a">Let's say a few weeks or months pass, and your package |
1204 author releases a new version. First, bring their changes | 1202 author releases a new version. First, bring their changes |
1205 into the repository.</para> | 1203 into the repository.</para> |
1206 | 1204 |
1207 &interaction.mq.tarball.newsource; | 1205 &interaction.mq.tarball.newsource; |
1208 | 1206 |
1209 <para>The pipeline starting with <command role="hg-cmd">hg | 1207 <para id="x_43b">The pipeline starting with <command role="hg-cmd">hg |
1210 locate</command> above deletes all files in the working | 1208 locate</command> above deletes all files in the working |
1211 directory, so that <command role="hg-cmd">hg | 1209 directory, so that <command role="hg-cmd">hg |
1212 commit</command>'s <option | 1210 commit</command>'s <option |
1213 role="hg-opt-commit">--addremove</option> option can | 1211 role="hg-opt-commit">--addremove</option> option can |
1214 actually tell which files have really been removed in the | 1212 actually tell which files have really been removed in the |
1215 newer version of the source.</para> | 1213 newer version of the source.</para> |
1216 | 1214 |
1217 <para>Finally, you can apply your patches on top of the new | 1215 <para id="x_43c">Finally, you can apply your patches on top of the new |
1218 tree.</para> | 1216 tree.</para> |
1219 | 1217 |
1220 &interaction.mq.tarball.repush; | 1218 &interaction.mq.tarball.repush; |
1221 | 1219 |
1222 </sect2> | 1220 </sect2> |
1223 <sect2 id="sec.mq.combine"> | 1221 <sect2 id="sec:mq:combine"> |
1224 <title>Combining entire patches</title> | 1222 <title>Combining entire patches</title> |
1225 | 1223 |
1226 <para>MQ provides a command, <command | 1224 <para id="x_43d">MQ provides a command, <command |
1227 role="hg-ext-mq">qfold</command> that lets you combine | 1225 role="hg-ext-mq">qfold</command> that lets you combine |
1228 entire patches. This <quote>folds</quote> the patches you | 1226 entire patches. This <quote>folds</quote> the patches you |
1229 name, in the order you name them, into the topmost applied | 1227 name, in the order you name them, into the topmost applied |
1230 patch, and concatenates their descriptions onto the end of its | 1228 patch, and concatenates their descriptions onto the end of its |
1231 description. The patches that you fold must be unapplied | 1229 description. The patches that you fold must be unapplied |
1232 before you fold them.</para> | 1230 before you fold them.</para> |
1233 | 1231 |
1234 <para>The order in which you fold patches matters. If your | 1232 <para id="x_43e">The order in which you fold patches matters. If your |
1235 topmost applied patch is <literal>foo</literal>, and you | 1233 topmost applied patch is <literal>foo</literal>, and you |
1236 <command role="hg-ext-mq">qfold</command> | 1234 <command role="hg-ext-mq">qfold</command> |
1237 <literal>bar</literal> and <literal>quux</literal> into it, | 1235 <literal>bar</literal> and <literal>quux</literal> into it, |
1238 you will end up with a patch that has the same effect as if | 1236 you will end up with a patch that has the same effect as if |
1239 you applied first <literal>foo</literal>, then | 1237 you applied first <literal>foo</literal>, then |
1242 | 1240 |
1243 </sect2> | 1241 </sect2> |
1244 <sect2> | 1242 <sect2> |
1245 <title>Merging part of one patch into another</title> | 1243 <title>Merging part of one patch into another</title> |
1246 | 1244 |
1247 <para>Merging <emphasis>part</emphasis> of one patch into | 1245 <para id="x_43f">Merging <emphasis>part</emphasis> of one patch into |
1248 another is more difficult than combining entire | 1246 another is more difficult than combining entire |
1249 patches.</para> | 1247 patches.</para> |
1250 | 1248 |
1251 <para>If you want to move changes to entire files, you can use | 1249 <para id="x_440">If you want to move changes to entire files, you can use |
1252 <command>filterdiff</command>'s <option | 1250 <command>filterdiff</command>'s <option |
1253 role="cmd-opt-filterdiff">-i</option> and <option | 1251 role="cmd-opt-filterdiff">-i</option> and <option |
1254 role="cmd-opt-filterdiff">-x</option> options to choose the | 1252 role="cmd-opt-filterdiff">-x</option> options to choose the |
1255 modifications to snip out of one patch, concatenating its | 1253 modifications to snip out of one patch, concatenating its |
1256 output onto the end of the patch you want to merge into. You | 1254 output onto the end of the patch you want to merge into. You |
1259 when you <command role="hg-ext-mq">qpush</command> it (from | 1257 when you <command role="hg-ext-mq">qpush</command> it (from |
1260 the hunks you moved into the other patch), and you can simply | 1258 the hunks you moved into the other patch), and you can simply |
1261 <command role="hg-ext-mq">qrefresh</command> the patch to drop | 1259 <command role="hg-ext-mq">qrefresh</command> the patch to drop |
1262 the duplicate hunks.</para> | 1260 the duplicate hunks.</para> |
1263 | 1261 |
1264 <para>If you have a patch that has multiple hunks modifying a | 1262 <para id="x_441">If you have a patch that has multiple hunks modifying a |
1265 file, and you only want to move a few of those hunks, the job | 1263 file, and you only want to move a few of those hunks, the job |
1266 becomes more messy, but you can still partly automate it. Use | 1264 becomes more messy, but you can still partly automate it. Use |
1267 <command>lsdiff -nvv</command> to print some metadata about | 1265 <command>lsdiff -nvv</command> to print some metadata about |
1268 the patch.</para> | 1266 the patch.</para> |
1269 | 1267 |
1270 &interaction.mq.tools.lsdiff; | 1268 &interaction.mq.tools.lsdiff; |
1271 | 1269 |
1272 <para>This command prints three different kinds of | 1270 <para id="x_442">This command prints three different kinds of |
1273 number:</para> | 1271 number:</para> |
1274 <itemizedlist> | 1272 <itemizedlist> |
1275 <listitem><para>(in the first column) a <emphasis>file | 1273 <listitem><para id="x_443">(in the first column) a <emphasis>file |
1276 number</emphasis> to identify each file modified in the | 1274 number</emphasis> to identify each file modified in the |
1277 patch;</para> | 1275 patch;</para> |
1278 </listitem> | 1276 </listitem> |
1279 <listitem><para>(on the next line, indented) the line number | 1277 <listitem><para id="x_444">(on the next line, indented) the line number |
1280 within a modified file where a hunk starts; and</para> | 1278 within a modified file where a hunk starts; and</para> |
1281 </listitem> | 1279 </listitem> |
1282 <listitem><para>(on the same line) a <emphasis>hunk | 1280 <listitem><para id="x_445">(on the same line) a <emphasis>hunk |
1283 number</emphasis> to identify that hunk.</para> | 1281 number</emphasis> to identify that hunk.</para> |
1284 </listitem></itemizedlist> | 1282 </listitem></itemizedlist> |
1285 | 1283 |
1286 <para>You'll have to use some visual inspection, and reading of | 1284 <para id="x_446">You'll have to use some visual inspection, and reading of |
1287 the patch, to identify the file and hunk numbers you'll want, | 1285 the patch, to identify the file and hunk numbers you'll want, |
1288 but you can then pass them to to | 1286 but you can then pass them to to |
1289 <command>filterdiff</command>'s <option | 1287 <command>filterdiff</command>'s <option |
1290 role="cmd-opt-filterdiff">--files</option> and <option | 1288 role="cmd-opt-filterdiff">--files</option> and <option |
1291 role="cmd-opt-filterdiff">--hunks</option> options, to | 1289 role="cmd-opt-filterdiff">--hunks</option> options, to |
1292 select exactly the file and hunk you want to extract.</para> | 1290 select exactly the file and hunk you want to extract.</para> |
1293 | 1291 |
1294 <para>Once you have this hunk, you can concatenate it onto the | 1292 <para id="x_447">Once you have this hunk, you can concatenate it onto the |
1295 end of your destination patch and continue with the remainder | 1293 end of your destination patch and continue with the remainder |
1296 of section <xref linkend="sec.mq.combine"/>.</para> | 1294 of <xref linkend="sec:mq:combine"/>.</para> |
1297 | 1295 |
1298 </sect2> | 1296 </sect2> |
1299 </sect1> | 1297 </sect1> |
1300 <sect1> | 1298 <sect1> |
1301 <title>Differences between quilt and MQ</title> | 1299 <title>Differences between quilt and MQ</title> |
1302 | 1300 |
1303 <para>If you are already familiar with quilt, MQ provides a | 1301 <para id="x_448">If you are already familiar with quilt, MQ provides a |
1304 similar command set. There are a few differences in the way | 1302 similar command set. There are a few differences in the way |
1305 that it works.</para> | 1303 that it works.</para> |
1306 | 1304 |
1307 <para>You will already have noticed that most quilt commands have | 1305 <para id="x_449">You will already have noticed that most quilt commands have |
1308 MQ counterparts that simply begin with a | 1306 MQ counterparts that simply begin with a |
1309 <quote><literal>q</literal></quote>. The exceptions are quilt's | 1307 <quote><literal>q</literal></quote>. The exceptions are quilt's |
1310 <literal>add</literal> and <literal>remove</literal> commands, | 1308 <literal>add</literal> and <literal>remove</literal> commands, |
1311 the counterparts for which are the normal Mercurial <command | 1309 the counterparts for which are the normal Mercurial <command |
1312 role="hg-cmd">hg add</command> and <command role="hg-cmd">hg | 1310 role="hg-cmd">hg add</command> and <command role="hg-cmd">hg |