Appendix B
Mercurial Queues reference

B.1 MQ command reference

For an overview of the commands provided by MQ, use the command hg help mq”.

B.1.1 hg qapplied”—print applied patches

The hg qapplied” command prints the current stack of applied patches. Patches are printed in oldest-to-newest order, so the last patch in the list is the “top” patch.

B.1.2 hg qcommit”—commit changes in the queue repository

The hg qcommit” command commits any outstanding changes in the .hg/patches repository. This command only works if the .hg/patches directory is a repository, i.e. you created the directory using hg qinit -c” or ran hg init” in the directory after running hg qinit”.

This command is shorthand for hg commit --cwd .hg/patches”.

B.1.3 hg qdelete”—delete a patch from the series file

The hg qdelete” command removes the entry for a patch from the series file in the .hg/patches directory. It does not pop the patch if the patch is already applied. By default, it does not delete the patch file; use the -f option to do that.

Options:

B.1.4 hg qdiff”—print a diff of the topmost applied patch

The hg qdiff” command prints a diff of the topmost applied patch. It is equivalent to hg diff -r-2:-1”.

B.1.5 hg qfold”—merge (“fold”) several patches into one

The hg qfold” command merges multiple patches into the topmost applied patch, so that the topmost applied patch makes the union of all of the changes in the patches in question.

The patches to fold must not be applied; hg qfold” will exit with an error if any is. The order in which patches are folded is significant; hg qfold a b” means “apply the current topmost patch, followed by a, followed by b”.

The comments from the folded patches are appended to the comments of the destination patch, with each block of comments separated by three asterisk (“”) characters. Use the -e option to edit the commit message for the combined patch/changeset after the folding has completed.

Options:

B.1.6 hg qheader”—display the header/description of a patch

The hg qheader” command prints the header, or description, of a patch. By default, it prints the header of the topmost applied patch. Given an argument, it prints the header of the named patch.

B.1.7 hg qimport”—import a third-party patch into the queue

The hg qimport” command adds an entry for an external patch to the series file, and copies the patch into the .hg/patches directory. It adds the entry immediately after the topmost applied patch, but does not push the patch.

If the .hg/patches directory is a repository, hg qimport” automatically does an hg add” of the imported patch.

B.1.8 hg qinit”—prepare a repository to work with MQ

The hg qinit” command prepares a repository to work with MQ. It creates a directory called .hg/patches.

Options:

When the .hg/patches directory is a repository, the hg qimport” and hg qnew” commands automatically hg add” new patches.

B.1.9 hg qnew”—create a new patch

The hg qnew” command creates a new patch. It takes one mandatory argument, the name to use for the patch file. The newly created patch is created empty by default. It is added to the series file after the current topmost applied patch, and is immediately pushed on top of that patch.

If hg qnew” finds modified files in the working directory, it will refuse to create a new patch unless the -f option is used (see below). This behaviour allows you to hg qrefresh” your topmost applied patch before you apply a new patch on top of it.

Options:

B.1.10 hg qnext”—print the name of the next patch

The hg qnext” command prints the name name of the next patch in the series file after the topmost applied patch. This patch will become the topmost applied patch if you run hg qpush”.

B.1.11 hg qpop”—pop patches off the stack

The hg qpop” command removes applied patches from the top of the stack of applied patches. By default, it removes only one patch.

This command removes the changesets that represent the popped patches from the repository, and updates the working directory to undo the effects of the patches.

This command takes an optional argument, which it uses as the name or index of the patch to pop to. If given a name, it will pop patches until the named patch is the topmost applied patch. If given a number, hg qpop” treats the number as an index into the entries in the series file, counting from zero (empty lines and lines containing only comments do not count). It pops patches until the patch identified by the given index is the topmost applied patch.

The hg qpop” command does not read or write patches or the series file. It is thus safe to hg qpop” a patch that you have removed from the series file, or a patch that you have renamed or deleted entirely. In the latter two cases, use the name of the patch as it was when you applied it.

By default, the hg qpop” command will not pop any patches if the working directory has been modified. You can override this behaviour using the -f option, which reverts all modifications in the working directory.

Options:

The hg qpop” command removes one line from the end of the status file for each patch that it pops.

B.1.12 hg qprev”—print the name of the previous patch

The hg qprev” command prints the name of the patch in the series file that comes before the topmost applied patch. This will become the topmost applied patch if you run hg qpop”.

B.1.13 hg qpush”—push patches onto the stack

The hg qpush” command adds patches onto the applied stack. By default, it adds only one patch.

This command creates a new changeset to represent each applied patch, and updates the working directory to apply the effects of the patches.

The default data used when creating a changeset are as follows:

If a patch contains a Mercurial patch header (XXX add link), the information in the patch header overrides these defaults.

Options:

The hg qpush” command reads, but does not modify, the series file. It appends one line to the hg status” file for each patch that it pushes.

B.1.14 hg qrefresh”—update the topmost applied patch

The hg qrefresh” command updates the topmost applied patch. It modifies the patch, removes the old changeset that represented the patch, and creates a new changeset to represent the modified patch.

The hg qrefresh” command looks for the following modifications:

Even if hg qrefresh” detects no changes, it still recreates the changeset that represents the patch. This causes the identity of the changeset to differ from the previous changeset that identified the patch.

Options:

B.1.15 hg qrename”—rename a patch

The hg qrename” command renames a patch, and changes the entry for the patch in the series file.

With a single argument, hg qrename” renames the topmost applied patch. With two arguments, it renames its first argument to its second.

B.1.16 hg qrestore”—restore saved queue state

XXX No idea what this does.

B.1.17 hg qsave”—save current queue state

XXX Likewise.

B.1.18 hg qseries”—print the entire patch series

The hg qseries” command prints the entire patch series from the series file. It prints only patch names, not empty lines or comments. It prints in order from first to be applied to last.

B.1.19 hg qtop”—print the name of the current patch

The hg qtop” prints the name of the topmost currently applied patch.

B.1.20 hg qunapplied”—print patches not yet applied

The hg qunapplied” command prints the names of patches from the series file that are not yet applied. It prints them in order from the next patch that will be pushed to the last.

B.1.21 hg strip”—remove a revision and descendants

The hg strip” command removes a revision, and all of its descendants, from the repository. It undoes the effects of the removed revisions from the repository, and updates the working directory to the first parent of the removed revision.

The hg strip” command saves a backup of the removed changesets in a bundle, so that they can be reapplied if removed in error.

Options:

B.2 MQ file reference

B.2.1 The series file

The series file contains a list of the names of all patches that MQ can apply. It is represented as a list of names, with one name saved per line. Leading and trailing white space in each line are ignored.

Lines may contain comments. A comment begins with the “#” character, and extends to the end of the line. Empty lines, and lines that contain only comments, are ignored.

You will often need to edit the series file by hand, hence the support for comments and empty lines noted above. For example, you can comment out a patch temporarily, and hg qpush” will skip over that patch when applying patches. You can also change the order in which patches are applied by reordering their entries in the series file.

Placing the series file under revision control is also supported; it is a good idea to place all of the patches that it refers to under revision control, as well. If you create a patch directory using the -c option to hg qinit”, this will be done for you automatically.

B.2.2 The status file

The status file contains the names and changeset hashes of all patches that MQ currently has applied. Unlike the series file, this file is not intended for editing. You should not place this file under revision control, or modify it in any way. It is used by MQ strictly for internal book-keeping.