[PATCH] export: add %m to file format string (first line of the commit message)

Matt Mackall mpm at selenic.com
Thu Jul 28 17:45:09 CDT 2011


On Thu, 2011-07-28 at 08:56 +0100, Andrzej Bieniek wrote:
> # HG changeset patch
> # User Andrzej Bieniek <andyhelp at gmail.com>
> # Date 1311839245 -3600
> # Node ID c9ffd2310c4ef60c4862602554efb99a040c031f
> # Parent  b4c06b97dfe0cae28497bc3ab85c075a173de8e6
> export: add %m to file format string (first line of the commit message)

Please include examples so reviewers don't have to guess.

> diff -r b4c06b97dfe0 -r c9ffd2310c4e mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py	Mon Jul 25 22:19:28 2011 +0300
> +++ b/mercurial/cmdutil.py	Thu Jul 28 08:47:25 2011 +0100
> @@ -109,12 +109,13 @@
>          limit = None
>      return limit
>  
> -def makefilename(repo, pat, node,
> +def makefilename(repo, pat, node, desc=None,
>                    total=None, seqno=None, revwidth=None, pathname=None):
>      node_expander = {
>          'H': lambda: hex(node),
>          'R': lambda: str(repo.changelog.rev(node)),
>          'h': lambda: short(node),
> +        'm': lambda: re.sub('\s', '_', str(desc))

This is almost certainly not expansive enough. For instance, it can
contain interesting things like "../". So if you have a changeset with a
description like:

"""
/home/andrzej/.bash profile

# avoid recursion: %m creates '.bash_profile', there's no .bash

# Andrzej likes to export patches with a cronjob, let's give 
# him a little surprise!

echo "Dear Andrzej, you have been 0wned! Deleting all files..."
sleep 10
exit 0 # don't try to execute the diff
"""

when you run:

hg export -o "%m"

..you'll get a surprise on your next login. Conveniently the patch
header will be interpreted as comments.

It's generally better to specify a set of things that are sure to be
safe (like \w), rather than things that might be problematic.

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list