Differences between revisions 54 and 55
Revision 54 as of 2012-07-20 18:22:05
Size: 7586
Editor: KCURA-CORP
Comment: Added mq push and pull hooks for Windows users
Revision 55 as of 2012-07-20 19:11:14
Size: 6780
Editor: KCURA-CORP
Comment: Hook example posted does not work, my apologies (the mq hooks are behaving differently then other hooks?)
Deletions are marked like this. Additions are marked like this.
Line 51: Line 51:
}}}

Looking to do this on Windows? Windows users can leverage the Powershell:
First make sure that you execution policy is set to {{{Unrestricted}}}. To do this, run the Powershell elevated (as Admin) and enter the following:

{{{PS> Set-Executionpolicy -ExecutionPolicy Unrestricted}}}

If you are not sure on what this does, please see {{{PS> Get-Help about_execution_policies}}}

Now, edit your .hg/hgrc (or Mercurial.ini if you want these hooks applied to all of your repositories)
{{{
[hooks]
# Prevent "hg pull" if MQ patches are applied.
prechangegroup.mq-no-pull = powershell $(hg qtop > $($null); if ($?) { return 1 } else {return 0};)
# Prevent "hg push" if MQ patches are applied.
preoutgoing.mq-no-push = powershell $(hg qtop > $($null); if ($?) { return 1 } else {return 0};)

Mercurial Queues Extension

This extension is currently being distributed along with Mercurial.

Author: Chris Mason

1. Introduction

In a distributed development model, changesets are traditionally immutable. Once a commit is done, it lives in the project history forever. This can make it difficult to develop a set of individual changes for submission upstream to a project maintainer. As the code matures over time, the development repository gathers a number of merges and changesets. This history is important for the individual developer, but can be very difficult to review when sent upstream.

Andrew Morton originally developed a set of scripts for maintaining kernel patches outside of any SCM tool. Others extended these into a suite called quilt. The basic idea behind quilt is to maintain patches instead of maintaining source files. Patches can be added, removed or reordered, and they can be refreshed as you fix bugs or update to a new base revision. quilt is very powerful, but it is not integrated with the underlying SCM tools. This makes it difficult to visualize your changes.

The patch queue extension integrates quilt functionality into Mercurial. Changes are maintained as patches which are committed into Mercurial. Commits can be removed or reordered, and the underlying patch can be refreshed based on changes made in the working directory. The patch directory can also be placed under revision control, so you can have a separate history of changes made to your patches.

2. Configuration

Enable the extension by adding following lines to your configuration file (.hgrc or Mercurial.ini):

[extensions]
mq =

3. Using Mercurial Queues

After the extension is properly installed, hg help will include the mq commands. These all start with q, and try to mimic commands under quilt. The patch queue lives in a directory named .hg/patches. .hg/patches/series lists the patches in the order they will be applied. You can change the patch order simply by moving them around in the series file. Make sure to only change entries in the series file for patches that are not currently applied.

4. Merging patches with new upstream revisions

MqMerge describes this in detail.

5. Tutorial

Find out more about mq in MqTutorial.

6. Hook Examples

You will often not want to push or pull changes from a repository which has patches applied to it. To prevent yourself from doing this accidentally, you can add these hooks to your repository .hg/hgrc.

Mercurial 0.9.2 and above won't allow pushing without --force anyway -- ThomasArendsenHein 2007-01-05 08:36:33

[hooks]
# Prevent "hg pull" if MQ patches are applied.
prechangegroup.mq-no-pull = ! hg qtop > /dev/null 2>&1
# Prevent "hg push" if MQ patches are applied.
preoutgoing.mq-no-push = ! hg qtop > /dev/null 2>&1

7. Command Examples

cd some_existing_hg_repository

# setup the patch queue directory (Deprecated in 1.5)
hg qinit

# create a new patch named firstpatch
hg qnew firstpatch

# edit some files
vi filename

# update the patch to contain your changes
hg qrefresh

# vi .hg/patches/firstpatch to see the result
# print the current patch to the screen
hg qdiff

# make some more changes
vi filename

# see the differences not yet stored in the patch
hg diff

# update the patch
hg qrefresh

# create another patch
hg qnew secondpatch

# Make more changes, and update the new patch
vi filename
hg qrefresh

# Look at the patches you have applied
# Look at all the patches in the queue
hg qapplied
hg qseries

# remove the top patch
hg qpop

# apply the patch again
hg qpush

# remove all patches
hg qpop -a

# apply all patches
hg qpush -a

8. Tips

8.1. Email all applied patches

hg email qbase:qtip

8.2. Convert all applied patches into permanent changesets

hg qfinish -a

8.3. Output all applied patches as a single patch

hg diff -r qparent:qtip

8.4. Force all patches to always be in git format

Add this to your .hgrc

[diff]
git=1

8.5. Prevent qrefresh from updating timestamps

If you're keeping your patch queue under revision control, it can be quite annoying when every qrefresh updates the timestamps in your patch. To prevent this you can add this to your .hgrc

[diff]
nodates=1

8.6. How to add a qstatus command

Add this to your .hgrc (see AliasExtension):

[alias]
qstatus = status --rev -2:.

Other useful aliases might be "status --rev qparent:." or "status --rev qparent:qtip"

8.7. How to update the commit message on a patch

If you want to change a one-line message, simply run:

hg qrefresh -m "New Message"

To edit a multiline message, run:

hg qrefresh -e

This will use $EDITOR to edit the commit message.

8.8. Publishing patches

If you're tweaking a patch queue over time, it can get tedious to continually update a published repository with the latest changes. Hooks can make the process pretty automatic. You should have two repositories, one being the base repository and one being a repository of your patches, such as hg qinit -c would create.

In the patch repository, which should be in the root of your main repository, in .hg/patches, set up some changegroup hooks:

[hooks]
# check out the latest version of the patches
changegroup.1update = hg update
# pop the old version from the base repo
changegroup.2pop = hg -R ../.. qpop -a
# push the versions that were just checked out
changegroup.3push = hg -R ../.. qpush -a

If you're feeling really fancy, you could also publish the patch repository itself with another hook:

changegroup.publish = hg push ../../../patches/foo

The overlay patch queue is published this way at http://hg.kublai.com/mercurial/overlay

9. Strip

The strip command is also part of the mq extension, although it does not explicitly use the patch queue.

10. See also


CategoryBundledExtension

日本語

MqExtension (last edited 2018-01-22 15:10:28 by MarioCastelánCastro)