[PATCH 2 of 2] patchbomb: place diffstat after commit message
Andreas Freimuth
andreas.freimuth at united-bits.de
Sun Aug 15 22:53:42 UTC 2010
# HG changeset patch
# User Andreas Freimuth <andreas.freimuth at united-bits.de>
# Date 1281706238 -7200
# Node ID 2f3bab41de3bd0b7b2e0272dab8494104eeb2cf2
# Parent 55d7f9da99c76b28e1edd0da712b717a64810c46
patchbomb: place diffstat after commit message
seperate commit message and diff stat with
one line containing '---'
---
hgext/patchbomb.py | 40 ++++++++++++++++++++++------------------
tests/test-patchbomb.t | 26 +++++++++-----------------
2 files changed, 31 insertions(+), 35 deletions(-)
diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -99,7 +99,7 @@ def prompt(ui, prompt, default=None, res
def cdiffstat(ui, summary, patchlines):
s = patch.diffstat(patchlines)
if summary:
- ui.write(summary, '\n')
+ ui.write(summary, '\n\n')
ui.write(s, '\n')
ans = prompt(ui, _('does the diffstat above look okay?'), 'y')
if not ans.lower().startswith('y'):
@@ -112,41 +112,45 @@ def introneeded(opts, number):
def makepatch(ui, repo, patch, opts, _charsets, idx, total, patchname=None):
- desc = []
node = None
body = ''
+ diffstart = None
+ descstart = None
- for line in patch:
+ for n, line in enumerate(patch):
if line.startswith('#'):
if line.startswith('# Node ID'):
node = line.split()[-1]
continue
if line.startswith('diff -r') or line.startswith('diff --git'):
+ diffstart = n
break
- desc.append(line)
+ if not descstart:
+ descstart = n
+
+ desc = patch[descstart:diffstart - 1]
if not patchname and not node:
raise ValueError
+ if not opts.get('inline'):
+ if opts.get('plain') or opts.get('attach'):
+ body = '\n'.join(desc[1:]).strip()
+ else:
+ body = '\n'.join(patch[:diffstart - 1]).strip()
+
if opts.get('attach'):
- body = ('\n'.join(desc[1:]).strip() or
- 'Patch subject is complete summary.')
- body += '\n\n\n'
+ if not body:
+ body = 'Patch subject is complete summary.\n'
- if opts.get('plain'):
- while patch and patch[0].startswith('# '):
- patch.pop(0)
- if patch:
- patch.pop(0)
- while patch and not patch[0].strip():
- patch.pop(0)
+ body += '\n'
if opts.get('diffstat'):
- body += cdiffstat(ui, '\n'.join(desc), patch) + '\n\n'
+ body += '---\n' + cdiffstat(ui, '\n'.join(desc), patch)
if opts.get('attach') or opts.get('inline'):
msg = email.MIMEMultipart.MIMEMultipart()
- if body:
+ if body.strip():
msg.attach(mail.mimeencode(ui, body, _charsets, opts.get('test')))
p = mail.mimetextpatch('\n'.join(patch), 'x-patch', opts.get('test'))
binnode = bin(node)
@@ -167,7 +171,7 @@ def makepatch(ui, repo, patch, opts, _ch
p['Content-Disposition'] = disposition + '; filename=' + patchname
msg.attach(p)
else:
- body += '\n'.join(patch)
+ body += '\n' + '\n'.join(patch[diffstart:])
msg = mail.mimetextpatch(body, display=opts.get('test'))
flag = ' '.join(opts.get('flag'))
@@ -353,7 +357,7 @@ def patchbomb(ui, repo, *revs, **opts):
body = ''
if opts.get('diffstat'):
- d = cdiffstat(ui, _('Final summary:\n'), jumbo)
+ d = cdiffstat(ui, _('Final summary:'), jumbo)
if d:
body = '\n' + d
diff --git a/tests/test-patchbomb.t b/tests/test-patchbomb.t
--- a/tests/test-patchbomb.t
+++ b/tests/test-patchbomb.t
@@ -351,16 +351,15 @@ test diffstat for single patch:
To: foo
Cc: bar
- c | 1 +
- 1 files changed, 1 insertions(+), 0 deletions(-)
-
-
# HG changeset patch
# User test
# Date 3 0
# Node ID ff2c9fa2018b15fa74b33363bda9527323e2a99f
# Parent 97d72e5f12c7e84f85064aa72e5a297142c36ed9
c
+ ---
+ c | 1 +
+ 1 files changed, 1 insertions(+), 0 deletions(-)
diff -r 97d72e5f12c7 -r ff2c9fa2018b c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -426,16 +425,15 @@ test diffstat for multiple patches:
To: foo
Cc: bar
- a | 1 +
- 1 files changed, 1 insertions(+), 0 deletions(-)
-
-
# HG changeset patch
# User test
# Date 1 0
# Node ID 8580ff50825a50c8f716709acdf8de0deddcd6ab
# Parent 0000000000000000000000000000000000000000
a
+ ---
+ a | 1 +
+ 1 files changed, 1 insertions(+), 0 deletions(-)
diff -r 000000000000 -r 8580ff50825a a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -458,16 +456,15 @@ test diffstat for multiple patches:
To: foo
Cc: bar
- b | 1 +
- 1 files changed, 1 insertions(+), 0 deletions(-)
-
-
# HG changeset patch
# User test
# Date 2 0
# Node ID 97d72e5f12c7e84f85064aa72e5a297142c36ed9
# Parent 8580ff50825a50c8f716709acdf8de0deddcd6ab
b
+ ---
+ b | 1 +
+ 1 files changed, 1 insertions(+), 0 deletions(-)
diff -r 8580ff50825a -r 97d72e5f12c7 b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -739,7 +736,6 @@ test attach for single patch:
Patch subject is complete summary.
-
--===
Content-Type: text/x-patch; charset="us-ascii"
MIME-Version: 1.0
@@ -787,7 +783,6 @@ test attach for single patch (quoted-pri
Patch subject is complete summary.
-
--===
Content-Type: text/x-patch; charset="us-ascii"
MIME-Version: 1.0
@@ -869,7 +864,6 @@ test attach for multiple patches:
Patch subject is complete summary.
-
--===
Content-Type: text/x-patch; charset="us-ascii"
MIME-Version: 1.0
@@ -912,7 +906,6 @@ test attach for multiple patches:
Patch subject is complete summary.
-
--===
Content-Type: text/x-patch; charset="us-ascii"
MIME-Version: 1.0
@@ -956,7 +949,6 @@ test attach for multiple patches:
Patch subject is complete summary.
-
--===
Content-Type: text/x-patch; charset="us-ascii"
MIME-Version: 1.0
More information about the Mercurial-devel
mailing list