aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl Wiberg <kha@treskal.com>2009-08-24 10:28:33 +0200
committerKarl Wiberg <kha@treskal.com>2009-08-24 10:28:33 +0200
commit4c47af784eb3357a403360e871c6e15a6ca70b39 (patch)
tree43498294c7824864da7d16c51a8e6e34c9f38681
parentd34d6e351e9708f4a5ce519e508abbc418285b5e (diff)
downloadstgit-4c47af784eb3357a403360e871c6e15a6ca70b39.tar.gz
squash: Make commit message editing more convenient
Very often, the commit message you want when squashing is the message of the first patch. So instead of simply concatenating the messages of all the patches, put a comment delimiter after the first one, and ignore everything after the delimiter when reading the message back in. If the user wants to use any part of the commented-out messages, she can move text around however she wants, including deleting the comment delimiter. Signed-off-by: Karl Wiberg <kha@treskal.com>
-rw-r--r--stgit/commands/squash.py11
-rw-r--r--stgit/utils.py10
2 files changed, 17 insertions, 4 deletions
diff --git a/stgit/commands/squash.py b/stgit/commands/squash.py
index d0be466..96b8da2 100644
--- a/stgit/commands/squash.py
+++ b/stgit/commands/squash.py
@@ -68,14 +68,17 @@ def _squash_patches(trans, patches, msg, save_template):
return None
cd = cd.set_tree(tree)
if msg == None:
- msg = '\n\n'.join('%s\n\n%s' % (pn.ljust(70, '-'),
- trans.patches[pn].data.message)
- for pn in patches)
+ msg = utils.append_comment(
+ trans.patches[patches[0]].data.message,
+ '\n\n'.join('%s\n\n%s' % (pn.ljust(70, '-'),
+ trans.patches[pn].data.message)
+ for pn in patches[1:]))
if save_template:
save_template(msg)
raise SaveTemplateDone()
else:
- msg = utils.edit_string(msg, '.stgit-squash.txt').strip()
+ msg = utils.edit_string(msg, '.stgit-squash.txt')
+ msg = utils.strip_comment(msg).strip()
cd = cd.set_message(msg)
return cd
diff --git a/stgit/utils.py b/stgit/utils.py
index 1fa96c2..5c0e159 100644
--- a/stgit/utils.py
+++ b/stgit/utils.py
@@ -200,6 +200,16 @@ def edit_string(s, filename):
os.remove(filename)
return s
+def append_comment(s, comment, separator = '---'):
+ return ('%s\n\n%s\nEverything following the line with "%s" will be'
+ ' ignored\n\n%s' % (s, separator, separator, comment))
+
+def strip_comment(s, separator = '---'):
+ try:
+ return s[:s.index('\n%s\n' % separator)]
+ except ValueError:
+ return s
+
def find_patch_name(patchname, unacceptable):
"""Find a patch name which is acceptable."""
if unacceptable(patchname):