[PATCH] export: add %m to file format string (first line of the commit message)
Andrzej Bieniek
andyhelp at googlemail.com
Sat Jul 30 05:19:07 CDT 2011
# HG changeset patch
# User Andrzej Bieniek <andyhelp at gmail.com>
# Date 1312020525 -3600
# Node ID 9545ff3672a5a3d738216819547686a293c6c475
# Parent b4c06b97dfe0cae28497bc3ab85c075a173de8e6
export: add %m to file format string (first line of the commit message)
$ hg commit -m "Initial commit"
$ hg export -o %m.patch tip #It creates Initial_commit.patch file.
diff -r b4c06b97dfe0 -r 9545ff3672a5 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py Mon Jul 25 22:19:28 2011 +0300
+++ b/mercurial/cmdutil.py Sat Jul 30 11:08:45 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('[^\w]', '_', str(desc))
}
expander = {
'%': lambda: '%',
@@ -154,7 +155,7 @@
raise util.Abort(_("invalid format spec '%%%s' in output filename") %
inst.args[0])
-def makefileobj(repo, pat, node=None, total=None,
+def makefileobj(repo, pat, node=None, desc=None, total=None,
seqno=None, revwidth=None, mode='wb', pathname=None):
writable = mode not in ('r', 'rb')
@@ -181,7 +182,7 @@
return pat
if hasattr(pat, 'read') and 'r' in mode:
return pat
- return open(makefilename(repo, pat, node, total, seqno, revwidth,
+ return open(makefilename(repo, pat, node, desc, total, seqno, revwidth,
pathname),
mode)
@@ -516,8 +517,10 @@
shouldclose = False
if not fp:
- fp = makefileobj(repo, template, node, total=total, seqno=seqno,
- revwidth=revwidth, mode='ab')
+ desc_lines = ctx.description().rstrip().split('\n')
+ desc = desc_lines[0] #Commit always has a first line.
+ fp = makefileobj(repo, template, node, desc=desc, total=total,
+ seqno=seqno, revwidth=revwidth, mode='ab')
if fp != template:
shouldclose = True
if fp != sys.stdout and hasattr(fp, 'name'):
diff -r b4c06b97dfe0 -r 9545ff3672a5 mercurial/commands.py
--- a/mercurial/commands.py Mon Jul 25 22:19:28 2011 +0300
+++ b/mercurial/commands.py Sat Jul 30 11:08:45 2011 +0100
@@ -2228,6 +2228,7 @@
:``%R``: changeset revision number
:``%b``: basename of the exporting repository
:``%h``: short-form changeset hash (12 hexadecimal digits)
+ :``%m``: first line of the commit message (only alphanumeric characters)
:``%n``: zero-padded sequence number, starting at 1
:``%r``: zero-padded changeset revision number
diff -r b4c06b97dfe0 -r 9545ff3672a5 tests/test-export.t
--- a/tests/test-export.t Mon Jul 25 22:19:28 2011 +0300
+++ b/tests/test-export.t Sat Jul 30 11:08:45 2011 +0100
@@ -7,7 +7,7 @@
> hg ci -m "foo-$i"
> done
- $ for out in "%nof%N" "%%%H" "%b-%R" "%h" "%r"; do
+ $ for out in "%nof%N" "%%%H" "%b-%R" "%h" "%r" "%m"; do
> echo
> echo "# foo-$out.patch"
> hg export -v -o "foo-$out.patch" 2:tip
@@ -77,6 +77,19 @@
foo-09.patch
foo-10.patch
foo-11.patch
+
+ # foo-%m.patch
+ exporting patches:
+ foo-foo_2.patch
+ foo-foo_3.patch
+ foo-foo_4.patch
+ foo-foo_5.patch
+ foo-foo_6.patch
+ foo-foo_7.patch
+ foo-foo_8.patch
+ foo-foo_9.patch
+ foo-foo_10.patch
+ foo-foo_11.patch
Exporting 4 changesets to a file:
@@ -108,3 +121,11 @@
foo-9
+foo-10
+Checking if only alphanumeric characters are used in the file name (%m option):
+
+ $ echo "line" >> foo
+ $ hg commit -m " !\"#$%&(,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_\`abcdefghijklmnopqrstuvwxyz{|}~"
+ $ hg export -v -o %m.patch tip
+ exporting patch:
+ ____________0123456789_______ABCDEFGHIJKLMNOPQRSTUVWXYZ______abcdefghijklmnopqrstuvwxyz____.patch
+
More information about the Mercurial-devel
mailing list