squash: Make commit message editing more convenient
authorKarl Wiberg <kha@treskal.com>
Mon, 24 Aug 2009 08:28:33 +0000 (10:28 +0200)
committerKarl Wiberg <kha@treskal.com>
Mon, 24 Aug 2009 08:28:33 +0000 (10:28 +0200)
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>
stgit/commands/squash.py
stgit/utils.py

index d0be466..96b8da2 100644 (file)
@@ -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
index 1fa96c2..5c0e159 100644 (file)
@@ -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):