mq: some improvements to header rewriting (closes #690)
authorBrendan Cully <brendan@kublai.com>
Thu, 23 Aug 2007 13:59:52 -0700
changeset 5235 988ed47d9d65
parent 5234 b772c0b9f0bd
child 5236 335696e2a58f
child 5239 8860f29447c1
mq: some improvements to header rewriting (closes #690) Tested with qrefresh -m against the mm series.
hgext/mq.py
--- a/hgext/mq.py	Thu Aug 23 12:24:54 2007 -0700
+++ b/hgext/mq.py	Thu Aug 23 13:59:52 2007 -0700
@@ -926,17 +926,24 @@
                     break
 
             msg = opts.get('msg', '').rstrip()
+            if msg and comments:
+                # Remove existing message, keeping the rest of the comments
+                # fields.
+                # If comments contains 'subject: ', message will prepend
+                # the field and a blank line.
+                if message:
+                    subj = 'subject: ' + message[0].lower()
+                    for i in xrange(len(comments)):
+                        if subj == comments[i].lower():
+                            del comments[i]
+                            message = message[2:]
+                            break
+                ci = 0
+                for mi in xrange(len(message)):
+                    while message[mi] != comments[ci]:
+                        ci += 1
+                    del comments[ci]
             if msg:
-                if comments:
-                    # Remove existing message.
-                    ci = 0
-                    subj = None
-                    for mi in xrange(len(message)):
-                        if comments[ci].lower().startswith('subject: '):
-                            subj = comments[ci][9:]
-                        while message[mi] != comments[ci] and message[mi] != subj:
-                            ci += 1
-                        del comments[ci]
                 comments.append(msg)
 
             patchf.seek(0)