Mercurial > hgbook
comparison en/mq.tex @ 233:696b1e0c01df
Tag all MQ commands as belonging to the mq extension.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Sun, 27 May 2007 09:41:55 -0700 |
parents | 28ddbf9f3729 |
children | 30e97616d808 |
comparison
equal
deleted
inserted
replaced
232:2469608b4a08 | 233:696b1e0c01df |
---|---|
225 \caption{Contents to add to \tildefile{.hgrc} to enable the MQ extension} | 225 \caption{Contents to add to \tildefile{.hgrc} to enable the MQ extension} |
226 \end{figure} | 226 \end{figure} |
227 | 227 |
228 Once the extension is enabled, it will make a number of new commands | 228 Once the extension is enabled, it will make a number of new commands |
229 available. To verify that the extension is working, you can use | 229 available. To verify that the extension is working, you can use |
230 \hgcmd{help} to see if the \hgcmd{qinit} command is now available; see | 230 \hgcmd{help} to see if the \hgxcmd{mq}{qinit} command is now available; see |
231 the example in figure~\ref{ex:mq:enabled}. | 231 the example in figure~\ref{ex:mq:enabled}. |
232 | 232 |
233 \begin{figure}[ht] | 233 \begin{figure}[ht] |
234 \interaction{mq.qinit-help.help} | 234 \interaction{mq.qinit-help.help} |
235 \caption{How to verify that MQ is enabled} | 235 \caption{How to verify that MQ is enabled} |
236 \label{ex:mq:enabled} | 236 \label{ex:mq:enabled} |
237 \end{figure} | 237 \end{figure} |
238 | 238 |
239 You can use MQ with \emph{any} Mercurial repository, and its commands | 239 You can use MQ with \emph{any} Mercurial repository, and its commands |
240 only operate within that repository. To get started, simply prepare | 240 only operate within that repository. To get started, simply prepare |
241 the repository using the \hgcmd{qinit} command (see | 241 the repository using the \hgxcmd{mq}{qinit} command (see |
242 figure~\ref{ex:mq:qinit}). This command creates an empty directory | 242 figure~\ref{ex:mq:qinit}). This command creates an empty directory |
243 called \sdirname{.hg/patches}, where MQ will keep its metadata. As | 243 called \sdirname{.hg/patches}, where MQ will keep its metadata. As |
244 with many Mercurial commands, the \hgcmd{qinit} command prints nothing | 244 with many Mercurial commands, the \hgxcmd{mq}{qinit} command prints nothing |
245 if it succeeds. | 245 if it succeeds. |
246 | 246 |
247 \begin{figure}[ht] | 247 \begin{figure}[ht] |
248 \interaction{mq.tutorial.qinit} | 248 \interaction{mq.tutorial.qinit} |
249 \caption{Preparing a repository for use with MQ} | 249 \caption{Preparing a repository for use with MQ} |
256 \label{ex:mq:qnew} | 256 \label{ex:mq:qnew} |
257 \end{figure} | 257 \end{figure} |
258 | 258 |
259 \subsection{Creating a new patch} | 259 \subsection{Creating a new patch} |
260 | 260 |
261 To begin work on a new patch, use the \hgcmd{qnew} command. This | 261 To begin work on a new patch, use the \hgxcmd{mq}{qnew} command. This |
262 command takes one argument, the name of the patch to create. MQ will | 262 command takes one argument, the name of the patch to create. MQ will |
263 use this as the name of an actual file in the \sdirname{.hg/patches} | 263 use this as the name of an actual file in the \sdirname{.hg/patches} |
264 directory, as you can see in figure~\ref{ex:mq:qnew}. | 264 directory, as you can see in figure~\ref{ex:mq:qnew}. |
265 | 265 |
266 Also newly present in the \sdirname{.hg/patches} directory are two | 266 Also newly present in the \sdirname{.hg/patches} directory are two |
284 they did before. | 284 they did before. |
285 | 285 |
286 \subsection{Refreshing a patch} | 286 \subsection{Refreshing a patch} |
287 | 287 |
288 When you reach a point where you want to save your work, use the | 288 When you reach a point where you want to save your work, use the |
289 \hgcmd{qrefresh} command (figure~\ref{ex:mq:qnew}) to update the patch | 289 \hgxcmd{mq}{qrefresh} command (figure~\ref{ex:mq:qnew}) to update the patch |
290 you are working on. This command folds the changes you have made in | 290 you are working on. This command folds the changes you have made in |
291 the working directory into your patch, and updates its corresponding | 291 the working directory into your patch, and updates its corresponding |
292 changeset to contain those changes. | 292 changeset to contain those changes. |
293 | 293 |
294 \begin{figure}[ht] | 294 \begin{figure}[ht] |
295 \interaction{mq.tutorial.qrefresh} | 295 \interaction{mq.tutorial.qrefresh} |
296 \caption{Refreshing a patch} | 296 \caption{Refreshing a patch} |
297 \label{ex:mq:qrefresh} | 297 \label{ex:mq:qrefresh} |
298 \end{figure} | 298 \end{figure} |
299 | 299 |
300 You can run \hgcmd{qrefresh} as often as you like, so it's a good way | 300 You can run \hgxcmd{mq}{qrefresh} as often as you like, so it's a good way |
301 to ``checkpoint'' your work. Refresh your patch at an opportune | 301 to ``checkpoint'' your work. Refresh your patch at an opportune |
302 time; try an experiment; and if the experiment doesn't work out, | 302 time; try an experiment; and if the experiment doesn't work out, |
303 \hgcmd{revert} your modifications back to the last time you refreshed. | 303 \hgcmd{revert} your modifications back to the last time you refreshed. |
304 | 304 |
305 \begin{figure}[ht] | 305 \begin{figure}[ht] |
309 \end{figure} | 309 \end{figure} |
310 | 310 |
311 \subsection{Stacking and tracking patches} | 311 \subsection{Stacking and tracking patches} |
312 | 312 |
313 Once you have finished working on a patch, or need to work on another, | 313 Once you have finished working on a patch, or need to work on another, |
314 you can use the \hgcmd{qnew} command again to create a new patch. | 314 you can use the \hgxcmd{mq}{qnew} command again to create a new patch. |
315 Mercurial will apply this patch on top of your existing patch. See | 315 Mercurial will apply this patch on top of your existing patch. See |
316 figure~\ref{ex:mq:qnew2} for an example. Notice that the patch | 316 figure~\ref{ex:mq:qnew2} for an example. Notice that the patch |
317 contains the changes in our prior patch as part of its context (you | 317 contains the changes in our prior patch as part of its context (you |
318 can see this more clearly in the output of \hgcmd{annotate}). | 318 can see this more clearly in the output of \hgcmd{annotate}). |
319 | 319 |
321 \interaction{mq.tutorial.qnew2} | 321 \interaction{mq.tutorial.qnew2} |
322 \caption{Stacking a second patch on top of the first} | 322 \caption{Stacking a second patch on top of the first} |
323 \label{ex:mq:qnew2} | 323 \label{ex:mq:qnew2} |
324 \end{figure} | 324 \end{figure} |
325 | 325 |
326 So far, with the exception of \hgcmd{qnew} and \hgcmd{qrefresh}, we've | 326 So far, with the exception of \hgxcmd{mq}{qnew} and \hgxcmd{mq}{qrefresh}, we've |
327 been careful to only use regular Mercurial commands. However, MQ | 327 been careful to only use regular Mercurial commands. However, MQ |
328 provides many commands that are easier to use when you are thinking | 328 provides many commands that are easier to use when you are thinking |
329 about patches, as illustrated in figure~\ref{ex:mq:qseries}: | 329 about patches, as illustrated in figure~\ref{ex:mq:qseries}: |
330 | 330 |
331 \begin{itemize} | 331 \begin{itemize} |
332 \item The \hgcmd{qseries} command lists every patch that MQ knows | 332 \item The \hgxcmd{mq}{qseries} command lists every patch that MQ knows |
333 about in this repository, from oldest to newest (most recently | 333 about in this repository, from oldest to newest (most recently |
334 \emph{created}). | 334 \emph{created}). |
335 \item The \hgcmd{qapplied} command lists every patch that MQ has | 335 \item The \hgxcmd{mq}{qapplied} command lists every patch that MQ has |
336 \emph{applied} in this repository, again from oldest to newest (most | 336 \emph{applied} in this repository, again from oldest to newest (most |
337 recently applied). | 337 recently applied). |
338 \end{itemize} | 338 \end{itemize} |
339 | 339 |
340 \begin{figure}[ht] | 340 \begin{figure}[ht] |
341 \interaction{mq.tutorial.qseries} | 341 \interaction{mq.tutorial.qseries} |
342 \caption{Understanding the patch stack with \hgcmd{qseries} and | 342 \caption{Understanding the patch stack with \hgxcmd{mq}{qseries} and |
343 \hgcmd{qapplied}} | 343 \hgxcmd{mq}{qapplied}} |
344 \label{ex:mq:qseries} | 344 \label{ex:mq:qseries} |
345 \end{figure} | 345 \end{figure} |
346 | 346 |
347 \subsection{Manipulating the patch stack} | 347 \subsection{Manipulating the patch stack} |
348 | 348 |
351 manage a patch without it being applied in the repository. | 351 manage a patch without it being applied in the repository. |
352 | 352 |
353 An \emph{applied} patch has a corresponding changeset in the | 353 An \emph{applied} patch has a corresponding changeset in the |
354 repository, and the effects of the patch and changeset are visible in | 354 repository, and the effects of the patch and changeset are visible in |
355 the working directory. You can undo the application of a patch using | 355 the working directory. You can undo the application of a patch using |
356 the \hgcmd{qpop} command. MQ still \emph{knows about}, or manages, a | 356 the \hgxcmd{mq}{qpop} command. MQ still \emph{knows about}, or manages, a |
357 popped patch, but the patch no longer has a corresponding changeset in | 357 popped patch, but the patch no longer has a corresponding changeset in |
358 the repository, and the working directory does not contain the changes | 358 the repository, and the working directory does not contain the changes |
359 made by the patch. Figure~\ref{fig:mq:stack} illustrates the | 359 made by the patch. Figure~\ref{fig:mq:stack} illustrates the |
360 difference between applied and tracked patches. | 360 difference between applied and tracked patches. |
361 | 361 |
364 \grafix{mq-stack} | 364 \grafix{mq-stack} |
365 \caption{Applied and unapplied patches in the MQ patch stack} | 365 \caption{Applied and unapplied patches in the MQ patch stack} |
366 \label{fig:mq:stack} | 366 \label{fig:mq:stack} |
367 \end{figure} | 367 \end{figure} |
368 | 368 |
369 You can reapply an unapplied, or popped, patch using the \hgcmd{qpush} | 369 You can reapply an unapplied, or popped, patch using the \hgxcmd{mq}{qpush} |
370 command. This creates a new changeset to correspond to the patch, and | 370 command. This creates a new changeset to correspond to the patch, and |
371 the patch's changes once again become present in the working | 371 the patch's changes once again become present in the working |
372 directory. See figure~\ref{ex:mq:qpop} for examples of \hgcmd{qpop} | 372 directory. See figure~\ref{ex:mq:qpop} for examples of \hgxcmd{mq}{qpop} |
373 and \hgcmd{qpush} in action. Notice that once we have popped a patch | 373 and \hgxcmd{mq}{qpush} in action. Notice that once we have popped a patch |
374 or two patches, the output of \hgcmd{qseries} remains the same, while | 374 or two patches, the output of \hgxcmd{mq}{qseries} remains the same, while |
375 that of \hgcmd{qapplied} has changed. | 375 that of \hgxcmd{mq}{qapplied} has changed. |
376 | 376 |
377 \begin{figure}[ht] | 377 \begin{figure}[ht] |
378 \interaction{mq.tutorial.qpop} | 378 \interaction{mq.tutorial.qpop} |
379 \caption{Modifying the stack of applied patches} | 379 \caption{Modifying the stack of applied patches} |
380 \label{ex:mq:qpop} | 380 \label{ex:mq:qpop} |
381 \end{figure} | 381 \end{figure} |
382 | 382 |
383 \subsection{Pushing and popping many patches} | 383 \subsection{Pushing and popping many patches} |
384 | 384 |
385 While \hgcmd{qpush} and \hgcmd{qpop} each operate on a single patch at | 385 While \hgxcmd{mq}{qpush} and \hgxcmd{mq}{qpop} each operate on a single patch at |
386 a time by default, you can push and pop many patches in one go. The | 386 a time by default, you can push and pop many patches in one go. The |
387 \hgopt{qpush}{-a} option to \hgcmd{qpush} causes it to push all | 387 \hgopt{qpush}{-a} option to \hgxcmd{mq}{qpush} causes it to push all |
388 unapplied patches, while the \hgopt{qpop}{-a} option to \hgcmd{qpop} | 388 unapplied patches, while the \hgopt{qpop}{-a} option to \hgxcmd{mq}{qpop} |
389 causes it to pop all applied patches. (For some more ways to push and | 389 causes it to pop all applied patches. (For some more ways to push and |
390 pop many patches, see section~\ref{sec:mq:perf} below.) | 390 pop many patches, see section~\ref{sec:mq:perf} below.) |
391 | 391 |
392 \begin{figure}[ht] | 392 \begin{figure}[ht] |
393 \interaction{mq.tutorial.qpush-a} | 393 \interaction{mq.tutorial.qpush-a} |
399 | 399 |
400 Several MQ commands check the working directory before they do | 400 Several MQ commands check the working directory before they do |
401 anything, and fail if they find any modifications. They do this to | 401 anything, and fail if they find any modifications. They do this to |
402 ensure that you won't lose any changes that you have made, but not yet | 402 ensure that you won't lose any changes that you have made, but not yet |
403 incorporated into a patch. Figure~\ref{ex:mq:add} illustrates this; | 403 incorporated into a patch. Figure~\ref{ex:mq:add} illustrates this; |
404 the \hgcmd{qnew} command will not create a new patch if there are | 404 the \hgxcmd{mq}{qnew} command will not create a new patch if there are |
405 outstanding changes, caused in this case by the \hgcmd{add} of | 405 outstanding changes, caused in this case by the \hgcmd{add} of |
406 \filename{file3}. | 406 \filename{file3}. |
407 | 407 |
408 \begin{figure}[ht] | 408 \begin{figure}[ht] |
409 \interaction{mq.tutorial.add} | 409 \interaction{mq.tutorial.add} |
420 files affected by the patch that it is popping. Be sure to read the | 420 files affected by the patch that it is popping. Be sure to read the |
421 documentation for a command's \option{-f} option before you use it! | 421 documentation for a command's \option{-f} option before you use it! |
422 | 422 |
423 \subsection{Working on several patches at once} | 423 \subsection{Working on several patches at once} |
424 | 424 |
425 The \hgcmd{qrefresh} command always refreshes the \emph{topmost} | 425 The \hgxcmd{mq}{qrefresh} command always refreshes the \emph{topmost} |
426 applied patch. This means that you can suspend work on one patch (by | 426 applied patch. This means that you can suspend work on one patch (by |
427 refreshing it), pop or push to make a different patch the top, and | 427 refreshing it), pop or push to make a different patch the top, and |
428 work on \emph{that} patch for a while. | 428 work on \emph{that} patch for a while. |
429 | 429 |
430 Here's an example that illustrates how you can use this ability. | 430 Here's an example that illustrates how you can use this ability. |
431 Let's say you're developing a new feature as two patches. The first | 431 Let's say you're developing a new feature as two patches. The first |
432 is a change to the core of your software, and the second---layered on | 432 is a change to the core of your software, and the second---layered on |
433 top of the first---changes the user interface to use the code you just | 433 top of the first---changes the user interface to use the code you just |
434 added to the core. If you notice a bug in the core while you're | 434 added to the core. If you notice a bug in the core while you're |
435 working on the UI patch, it's easy to fix the core. Simply | 435 working on the UI patch, it's easy to fix the core. Simply |
436 \hgcmd{qrefresh} the UI patch to save your in-progress changes, and | 436 \hgxcmd{mq}{qrefresh} the UI patch to save your in-progress changes, and |
437 \hgcmd{qpop} down to the core patch. Fix the core bug, | 437 \hgxcmd{mq}{qpop} down to the core patch. Fix the core bug, |
438 \hgcmd{qrefresh} the core patch, and \hgcmd{qpush} back to the UI | 438 \hgxcmd{mq}{qrefresh} the core patch, and \hgxcmd{mq}{qpush} back to the UI |
439 patch to continue where you left off. | 439 patch to continue where you left off. |
440 | 440 |
441 \section{More about patches} | 441 \section{More about patches} |
442 \label{sec:mq:adv-patch} | 442 \label{sec:mq:adv-patch} |
443 | 443 |
485 and the \hgcmd{import} command and MQ expect patches to have a strip | 485 and the \hgcmd{import} command and MQ expect patches to have a strip |
486 count of one. | 486 count of one. |
487 | 487 |
488 If you receive a patch from someone that you want to add to your patch | 488 If you receive a patch from someone that you want to add to your patch |
489 queue, and the patch needs a strip count other than one, you cannot | 489 queue, and the patch needs a strip count other than one, you cannot |
490 just \hgcmd{qimport} the patch, because \hgcmd{qimport} does not yet | 490 just \hgxcmd{mq}{qimport} the patch, because \hgxcmd{mq}{qimport} does not yet |
491 have a \texttt{-p} option (see~\bug{311}). Your best bet is to | 491 have a \texttt{-p} option (see~\bug{311}). Your best bet is to |
492 \hgcmd{qnew} a patch of your own, then use \cmdargs{patch}{-p\emph{N}} | 492 \hgxcmd{mq}{qnew} a patch of your own, then use \cmdargs{patch}{-p\emph{N}} |
493 to apply their patch, followed by \hgcmd{addremove} to pick up any | 493 to apply their patch, followed by \hgcmd{addremove} to pick up any |
494 files added or removed by the patch, followed by \hgcmd{qrefresh}. | 494 files added or removed by the patch, followed by \hgxcmd{mq}{qrefresh}. |
495 This complexity may become unnecessary; see~\bug{311} for details. | 495 This complexity may become unnecessary; see~\bug{311} for details. |
496 \subsection{Strategies for applying a patch} | 496 \subsection{Strategies for applying a patch} |
497 | 497 |
498 When \command{patch} applies a hunk, it tries a handful of | 498 When \command{patch} applies a hunk, it tries a handful of |
499 successively less accurate strategies to try to make the hunk apply. | 499 successively less accurate strategies to try to make the hunk apply. |
555 | 555 |
556 While applying a hunk at an offset, or with a fuzz factor, will often | 556 While applying a hunk at an offset, or with a fuzz factor, will often |
557 be completely successful, these inexact techniques naturally leave | 557 be completely successful, these inexact techniques naturally leave |
558 open the possibility of corrupting the patched file. The most common | 558 open the possibility of corrupting the patched file. The most common |
559 cases typically involve applying a patch twice, or at an incorrect | 559 cases typically involve applying a patch twice, or at an incorrect |
560 location in the file. If \command{patch} or \hgcmd{qpush} ever | 560 location in the file. If \command{patch} or \hgxcmd{mq}{qpush} ever |
561 mentions an offset or fuzz factor, you should make sure that the | 561 mentions an offset or fuzz factor, you should make sure that the |
562 modified files are correct afterwards. | 562 modified files are correct afterwards. |
563 | 563 |
564 It's often a good idea to refresh a patch that has applied with an | 564 It's often a good idea to refresh a patch that has applied with an |
565 offset or fuzz factor; refreshing the patch generates new context | 565 offset or fuzz factor; refreshing the patch generates new context |
571 apply with some fuzz, provided you've verified the results of the | 571 apply with some fuzz, provided you've verified the results of the |
572 patching process in such cases. | 572 patching process in such cases. |
573 | 573 |
574 \subsection{Handling rejection} | 574 \subsection{Handling rejection} |
575 | 575 |
576 If \hgcmd{qpush} fails to apply a patch, it will print an error | 576 If \hgxcmd{mq}{qpush} fails to apply a patch, it will print an error |
577 message and exit. If it has left \sfilename{.rej} files behind, it is | 577 message and exit. If it has left \sfilename{.rej} files behind, it is |
578 usually best to fix up the rejected hunks before you push more patches | 578 usually best to fix up the rejected hunks before you push more patches |
579 or do any further work. | 579 or do any further work. |
580 | 580 |
581 If your patch \emph{used to} apply cleanly, and no longer does because | 581 If your patch \emph{used to} apply cleanly, and no longer does because |
625 | 625 |
626 On my old, slow laptop, I was able to | 626 On my old, slow laptop, I was able to |
627 \hgcmdargs{qpush}{\hgopt{qpush}{-a}} all 1,738 patches in 3.5 minutes, | 627 \hgcmdargs{qpush}{\hgopt{qpush}{-a}} all 1,738 patches in 3.5 minutes, |
628 and \hgcmdargs{qpop}{\hgopt{qpop}{-a}} them all in 30 seconds. (On a | 628 and \hgcmdargs{qpop}{\hgopt{qpop}{-a}} them all in 30 seconds. (On a |
629 newer laptop, the time to push all patches dropped to two minutes.) I | 629 newer laptop, the time to push all patches dropped to two minutes.) I |
630 could \hgcmd{qrefresh} one of the biggest patches (which made 22,779 | 630 could \hgxcmd{mq}{qrefresh} one of the biggest patches (which made 22,779 |
631 lines of changes to 287 files) in 6.6 seconds. | 631 lines of changes to 287 files) in 6.6 seconds. |
632 | 632 |
633 Clearly, MQ is well suited to working in large trees, but there are a | 633 Clearly, MQ is well suited to working in large trees, but there are a |
634 few tricks you can use to get the best performance of it. | 634 few tricks you can use to get the best performance of it. |
635 | 635 |
636 First of all, try to ``batch'' operations together. Every time you | 636 First of all, try to ``batch'' operations together. Every time you |
637 run \hgcmd{qpush} or \hgcmd{qpop}, these commands scan the working | 637 run \hgxcmd{mq}{qpush} or \hgxcmd{mq}{qpop}, these commands scan the working |
638 directory once to make sure you haven't made some changes and then | 638 directory once to make sure you haven't made some changes and then |
639 forgotten to run \hgcmd{qrefresh}. On a small tree, the time that | 639 forgotten to run \hgxcmd{mq}{qrefresh}. On a small tree, the time that |
640 this scan takes is unnoticeable. However, on a medium-sized tree | 640 this scan takes is unnoticeable. However, on a medium-sized tree |
641 (containing tens of thousands of files), it can take a second or more. | 641 (containing tens of thousands of files), it can take a second or more. |
642 | 642 |
643 The \hgcmd{qpush} and \hgcmd{qpop} commands allow you to push and pop | 643 The \hgxcmd{mq}{qpush} and \hgxcmd{mq}{qpop} commands allow you to push and pop |
644 multiple patches at a time. You can identify the ``destination | 644 multiple patches at a time. You can identify the ``destination |
645 patch'' that you want to end up at. When you \hgcmd{qpush} with a | 645 patch'' that you want to end up at. When you \hgxcmd{mq}{qpush} with a |
646 destination specified, it will push patches until that patch is at the | 646 destination specified, it will push patches until that patch is at the |
647 top of the applied stack. When you \hgcmd{qpop} to a destination, MQ | 647 top of the applied stack. When you \hgxcmd{mq}{qpop} to a destination, MQ |
648 will pop patches until the destination patch is at the top. | 648 will pop patches until the destination patch is at the top. |
649 | 649 |
650 You can identify a destination patch using either the name of the | 650 You can identify a destination patch using either the name of the |
651 patch, or by number. If you use numeric addressing, patches are | 651 patch, or by number. If you use numeric addressing, patches are |
652 counted from zero; this means that the first patch is zero, the second | 652 counted from zero; this means that the first patch is zero, the second |
666 The simplest way to do this is to \hgcmdargs{qpop}{\hgopt{qpop}{-a}} | 666 The simplest way to do this is to \hgcmdargs{qpop}{\hgopt{qpop}{-a}} |
667 your patches, then \hgcmd{pull} changes into the underlying | 667 your patches, then \hgcmd{pull} changes into the underlying |
668 repository, and finally \hgcmdargs{qpush}{\hgopt{qpop}{-a}} your | 668 repository, and finally \hgcmdargs{qpush}{\hgopt{qpop}{-a}} your |
669 patches again. MQ will stop pushing any time it runs across a patch | 669 patches again. MQ will stop pushing any time it runs across a patch |
670 that fails to apply during conflicts, allowing you to fix your | 670 that fails to apply during conflicts, allowing you to fix your |
671 conflicts, \hgcmd{qrefresh} the affected patch, and continue pushing | 671 conflicts, \hgxcmd{mq}{qrefresh} the affected patch, and continue pushing |
672 until you have fixed your entire stack. | 672 until you have fixed your entire stack. |
673 | 673 |
674 This approach is easy to use and works well if you don't expect | 674 This approach is easy to use and works well if you don't expect |
675 changes to the underlying code to affect how well your patches apply. | 675 changes to the underlying code to affect how well your patches apply. |
676 If your patch stack touches code that is modified frequently or | 676 If your patch stack touches code that is modified frequently or |
698 repository. (Don't run \hgcmdargs{pull}{-u}; see below for why.) | 698 repository. (Don't run \hgcmdargs{pull}{-u}; see below for why.) |
699 \item Update to the new tip revision, using | 699 \item Update to the new tip revision, using |
700 \hgcmdargs{update}{\hgopt{update}{-C}} to override the patches you | 700 \hgcmdargs{update}{\hgopt{update}{-C}} to override the patches you |
701 have pushed. | 701 have pushed. |
702 \item Merge all patches using \hgcmdargs{qpush}{\hgopt{qpush}{-m} | 702 \item Merge all patches using \hgcmdargs{qpush}{\hgopt{qpush}{-m} |
703 \hgopt{qpush}{-a}}. The \hgopt{qpush}{-m} option to \hgcmd{qpush} | 703 \hgopt{qpush}{-a}}. The \hgopt{qpush}{-m} option to \hgxcmd{mq}{qpush} |
704 tells MQ to perform a three-way merge if the patch fails to apply. | 704 tells MQ to perform a three-way merge if the patch fails to apply. |
705 \end{enumerate} | 705 \end{enumerate} |
706 | 706 |
707 During the \hgcmdargs{qpush}{\hgopt{qpush}{-m}}, each patch in the | 707 During the \hgcmdargs{qpush}{\hgopt{qpush}{-m}}, each patch in the |
708 \sfilename{series} file is applied normally. If a patch applies with | 708 \sfilename{series} file is applied normally. If a patch applies with |
709 fuzz or rejects, MQ looks at the queue you \hgcmd{qsave}d, and | 709 fuzz or rejects, MQ looks at the queue you \hgxcmd{mq}{qsave}d, and |
710 performs a three-way merge with the corresponding changeset. This | 710 performs a three-way merge with the corresponding changeset. This |
711 merge uses Mercurial's normal merge machinery, so it may pop up a GUI | 711 merge uses Mercurial's normal merge machinery, so it may pop up a GUI |
712 merge tool to help you to resolve problems. | 712 merge tool to help you to resolve problems. |
713 | 713 |
714 When you finish resolving the effects of a patch, MQ refreshes your | 714 When you finish resolving the effects of a patch, MQ refreshes your |
723 | 723 |
724 \section{Identifying patches} | 724 \section{Identifying patches} |
725 | 725 |
726 MQ commands that work with patches let you refer to a patch either by | 726 MQ commands that work with patches let you refer to a patch either by |
727 using its name or by a number. By name is obvious enough; pass the | 727 using its name or by a number. By name is obvious enough; pass the |
728 name \filename{foo.patch} to \hgcmd{qpush}, for example, and it will | 728 name \filename{foo.patch} to \hgxcmd{mq}{qpush}, for example, and it will |
729 push patches until \filename{foo.patch} is applied. | 729 push patches until \filename{foo.patch} is applied. |
730 | 730 |
731 As a shortcut, you can refer to a patch using both a name and a | 731 As a shortcut, you can refer to a patch using both a name and a |
732 numeric offset; \texttt{foo.patch-2} means ``two patches before | 732 numeric offset; \texttt{foo.patch-2} means ``two patches before |
733 \texttt{foo.patch}'', while \texttt{bar.patch+4} means ``four patches | 733 \texttt{foo.patch}'', while \texttt{bar.patch+4} means ``four patches |
734 after \texttt{bar.patch}''. | 734 after \texttt{bar.patch}''. |
735 | 735 |
736 Referring to a patch by index isn't much different. The first patch | 736 Referring to a patch by index isn't much different. The first patch |
737 printed in the output of \hgcmd{qseries} is patch zero (yes, it's one | 737 printed in the output of \hgxcmd{mq}{qseries} is patch zero (yes, it's one |
738 of those start-at-zero counting systems); the second is patch one; and | 738 of those start-at-zero counting systems); the second is patch one; and |
739 so on | 739 so on |
740 | 740 |
741 MQ also makes it easy to work with patches when you are using normal | 741 MQ also makes it easy to work with patches when you are using normal |
742 Mercurial commands. Every command that accepts a changeset ID will | 742 Mercurial commands. Every command that accepts a changeset ID will |
787 There are a number of aspects of MQ usage that don't fit tidily into | 787 There are a number of aspects of MQ usage that don't fit tidily into |
788 sections of their own, but that are good to know. Here they are, in | 788 sections of their own, but that are good to know. Here they are, in |
789 one place. | 789 one place. |
790 | 790 |
791 \begin{itemize} | 791 \begin{itemize} |
792 \item Normally, when you \hgcmd{qpop} a patch and \hgcmd{qpush} it | 792 \item Normally, when you \hgxcmd{mq}{qpop} a patch and \hgxcmd{mq}{qpush} it |
793 again, the changeset that represents the patch after the pop/push | 793 again, the changeset that represents the patch after the pop/push |
794 will have a \emph{different identity} than the changeset that | 794 will have a \emph{different identity} than the changeset that |
795 represented the hash beforehand. See | 795 represented the hash beforehand. See |
796 section~\ref{sec:mqref:cmd:qpush} for information as to why this is. | 796 section~\ref{sec:mqref:cmd:qpush} for information as to why this is. |
797 \item It's not a good idea to \hgcmd{merge} changes from another | 797 \item It's not a good idea to \hgcmd{merge} changes from another |
809 repository knows nothing about the management or presence of patches. | 809 repository knows nothing about the management or presence of patches. |
810 | 810 |
811 This presents the interesting possibility of managing the contents of | 811 This presents the interesting possibility of managing the contents of |
812 the patch directory as a Mercurial repository in its own right. This | 812 the patch directory as a Mercurial repository in its own right. This |
813 can be a useful way to work. For example, you can work on a patch for | 813 can be a useful way to work. For example, you can work on a patch for |
814 a while, \hgcmd{qrefresh} it, then \hgcmd{commit} the current state of | 814 a while, \hgxcmd{mq}{qrefresh} it, then \hgcmd{commit} the current state of |
815 the patch. This lets you ``roll back'' to that version of the patch | 815 the patch. This lets you ``roll back'' to that version of the patch |
816 later on. | 816 later on. |
817 | 817 |
818 You can then share different versions of the same patch stack among | 818 You can then share different versions of the same patch stack among |
819 multiple underlying repositories. I use this when I am developing a | 819 multiple underlying repositories. I use this when I am developing a |
831 | 831 |
832 \subsection{MQ support for patch repositories} | 832 \subsection{MQ support for patch repositories} |
833 | 833 |
834 MQ helps you to work with the \sdirname{.hg/patches} directory as a | 834 MQ helps you to work with the \sdirname{.hg/patches} directory as a |
835 repository; when you prepare a repository for working with patches | 835 repository; when you prepare a repository for working with patches |
836 using \hgcmd{qinit}, you can pass the \hgopt{qinit}{-c} option to | 836 using \hgxcmd{mq}{qinit}, you can pass the \hgopt{qinit}{-c} option to |
837 create the \sdirname{.hg/patches} directory as a Mercurial repository. | 837 create the \sdirname{.hg/patches} directory as a Mercurial repository. |
838 | 838 |
839 \begin{note} | 839 \begin{note} |
840 If you forget to use the \hgopt{qinit}{-c} option, you can simply go | 840 If you forget to use the \hgopt{qinit}{-c} option, you can simply go |
841 into the \sdirname{.hg/patches} directory at any time and run | 841 into the \sdirname{.hg/patches} directory at any time and run |
849 | 849 |
850 As a convenience, if MQ notices that the \dirname{.hg/patches} | 850 As a convenience, if MQ notices that the \dirname{.hg/patches} |
851 directory is a repository, it will automatically \hgcmd{add} every | 851 directory is a repository, it will automatically \hgcmd{add} every |
852 patch that you create and import. | 852 patch that you create and import. |
853 | 853 |
854 Finally, MQ provides a shortcut command, \hgcmd{qcommit}, that runs | 854 Finally, MQ provides a shortcut command, \hgxcmd{mq}{qcommit}, that runs |
855 \hgcmd{commit} in the \sdirname{.hg/patches} directory. This saves | 855 \hgcmd{commit} in the \sdirname{.hg/patches} directory. This saves |
856 some cumbersome typing. | 856 some cumbersome typing. |
857 | 857 |
858 \subsection{A few things to watch out for} | 858 \subsection{A few things to watch out for} |
859 | 859 |
909 | 909 |
910 Give your patches descriptive names. A good name for a patch might be | 910 Give your patches descriptive names. A good name for a patch might be |
911 \filename{rework-device-alloc.patch}, because it will immediately give | 911 \filename{rework-device-alloc.patch}, because it will immediately give |
912 you a hint what the purpose of the patch is. Long names shouldn't be | 912 you a hint what the purpose of the patch is. Long names shouldn't be |
913 a problem; you won't be typing the names often, but you \emph{will} be | 913 a problem; you won't be typing the names often, but you \emph{will} be |
914 running commands like \hgcmd{qapplied} and \hgcmd{qtop} over and over. | 914 running commands like \hgxcmd{mq}{qapplied} and \hgxcmd{mq}{qtop} over and over. |
915 Good naming becomes especially important when you have a number of | 915 Good naming becomes especially important when you have a number of |
916 patches to work with, or if you are juggling a number of different | 916 patches to work with, or if you are juggling a number of different |
917 tasks and your patches only get a fraction of your attention. | 917 tasks and your patches only get a fraction of your attention. |
918 | 918 |
919 Be aware of what patch you're working on. Use the \hgcmd{qtop} | 919 Be aware of what patch you're working on. Use the \hgxcmd{mq}{qtop} |
920 command and skim over the text of your patches frequently---for | 920 command and skim over the text of your patches frequently---for |
921 example, using \hgcmdargs{tip}{\hgopt{tip}{-p}})---to be sure of where | 921 example, using \hgcmdargs{tip}{\hgopt{tip}{-p}})---to be sure of where |
922 you stand. I have several times worked on and \hgcmd{qrefresh}ed a | 922 you stand. I have several times worked on and \hgxcmd{mq}{qrefresh}ed a |
923 patch other than the one I intended, and it's often tricky to migrate | 923 patch other than the one I intended, and it's often tricky to migrate |
924 changes into the right patch after making them in the wrong one. | 924 changes into the right patch after making them in the wrong one. |
925 | 925 |
926 For this reason, it is very much worth investing a little time to | 926 For this reason, it is very much worth investing a little time to |
927 learn how to use some of the third-party tools I described in | 927 learn how to use some of the third-party tools I described in |
958 \interaction{mq.tarball.repush} | 958 \interaction{mq.tarball.repush} |
959 | 959 |
960 \subsection{Combining entire patches} | 960 \subsection{Combining entire patches} |
961 \label{sec:mq:combine} | 961 \label{sec:mq:combine} |
962 | 962 |
963 MQ provides a command, \hgcmd{qfold} that lets you combine entire | 963 MQ provides a command, \hgxcmd{mq}{qfold} that lets you combine entire |
964 patches. This ``folds'' the patches you name, in the order you name | 964 patches. This ``folds'' the patches you name, in the order you name |
965 them, into the topmost applied patch, and concatenates their | 965 them, into the topmost applied patch, and concatenates their |
966 descriptions onto the end of its description. The patches that you | 966 descriptions onto the end of its description. The patches that you |
967 fold must be unapplied before you fold them. | 967 fold must be unapplied before you fold them. |
968 | 968 |
969 The order in which you fold patches matters. If your topmost applied | 969 The order in which you fold patches matters. If your topmost applied |
970 patch is \texttt{foo}, and you \hgcmd{qfold} \texttt{bar} and | 970 patch is \texttt{foo}, and you \hgxcmd{mq}{qfold} \texttt{bar} and |
971 \texttt{quux} into it, you will end up with a patch that has the same | 971 \texttt{quux} into it, you will end up with a patch that has the same |
972 effect as if you applied first \texttt{foo}, then \texttt{bar}, | 972 effect as if you applied first \texttt{foo}, then \texttt{bar}, |
973 followed by \texttt{quux}. | 973 followed by \texttt{quux}. |
974 | 974 |
975 \subsection{Merging part of one patch into another} | 975 \subsection{Merging part of one patch into another} |
981 \command{filterdiff}'s \cmdopt{filterdiff}{-i} and | 981 \command{filterdiff}'s \cmdopt{filterdiff}{-i} and |
982 \cmdopt{filterdiff}{-x} options to choose the modifications to snip | 982 \cmdopt{filterdiff}{-x} options to choose the modifications to snip |
983 out of one patch, concatenating its output onto the end of the patch | 983 out of one patch, concatenating its output onto the end of the patch |
984 you want to merge into. You usually won't need to modify the patch | 984 you want to merge into. You usually won't need to modify the patch |
985 you've merged the changes from. Instead, MQ will report some rejected | 985 you've merged the changes from. Instead, MQ will report some rejected |
986 hunks when you \hgcmd{qpush} it (from the hunks you moved into the | 986 hunks when you \hgxcmd{mq}{qpush} it (from the hunks you moved into the |
987 other patch), and you can simply \hgcmd{qrefresh} the patch to drop | 987 other patch), and you can simply \hgxcmd{mq}{qrefresh} the patch to drop |
988 the duplicate hunks. | 988 the duplicate hunks. |
989 | 989 |
990 If you have a patch that has multiple hunks modifying a file, and you | 990 If you have a patch that has multiple hunks modifying a file, and you |
991 only want to move a few of those hunks, the job becomes more messy, | 991 only want to move a few of those hunks, the job becomes more messy, |
992 but you can still partly automate it. Use \cmdargs{lsdiff}{-nvv} to | 992 but you can still partly automate it. Use \cmdargs{lsdiff}{-nvv} to |