From 4c47af784eb3357a403360e871c6e15a6ca70b39 Mon Sep 17 00:00:00 2001 Message-Id: <4c47af784eb3357a403360e871c6e15a6ca70b39.1718787745.git.mdw@distorted.org.uk> From: Mark Wooding Date: Mon, 24 Aug 2009 10:28:33 +0200 Subject: [PATCH] squash: Make commit message editing more convenient Organization: Straylight/Edgeware From: Karl Wiberg 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 --- stgit/commands/squash.py | 11 +++++++---- stgit/utils.py | 10 ++++++++++ 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): -- [mdw]