[PATCH 1 of 2] mq: refactor mq.patchheader

Jozef Hatala jh-mercurial at skrt.org
Sun Feb 28 02:39:16 CST 2010


# HG changeset patch
# User Steve Losh <steve at stevelosh.com>
# Date 1265763661 18000
# Node ID 75b027298f0588e698d6099f8588c1296e586f9d
# Parent  989b2a5eaaba8e151aa9ae4757f9224577947f2f
mq: refactor mq.patchheader

This patch refactors the patchheader class in mq.py to be more understandable
and more robust when working with plain- and hg-style patch headers.

Some of the tests have also been updated to reflect the new, more consistent
ordering of the header fields.

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -38,6 +38,16 @@
 preserving existing git patches upon qrefresh. If set to 'yes' or
 'no', mq will override the [diff] section and always generate git or
 regular patches, possibly losing data in the second case.
+
+By default, mq will automatically use hg-style patch headers when creating
+new patches. This behavior can be changed with::
+
+  [mq]
+  plain = true
+
+If set to 'true', mq will use plain headers with only "Date" and "From"
+fields. For existing patches with headers the header format will always be
+preserved.
 '''
 
 from mercurial.i18n import _
@@ -45,7 +55,7 @@
 from mercurial.lock import release
 from mercurial import commands, cmdutil, hg, patch, util
 from mercurial import repair, extensions, url, error
-import os, sys, re, errno
+import os, sys, re, errno, itertools
 
 commands.norepo += " qclone"
 
@@ -68,182 +78,137 @@
         return self.rev + ':' + self.name
 
 class patchheader(object):
-    def __init__(self, pf, plainmode=False):
-        def eatdiff(lines):
-            while lines:
-                l = lines[-1]
-                if (l.startswith("diff -") or
-                    l.startswith("Index:") or
-                    l.startswith("===========")):
-                    del lines[-1]
-                else:
-                    break
-        def eatempty(lines):
-            while lines:
-                l = lines[-1]
-                if re.match('\s*$', l):
-                    del lines[-1]
-                else:
-                    break
+    def __init__(self, pf=None, plain=False):
+        self.user = None
+        self.parent = None
+        self.date = None
+        self.format = plain and 'plain' or 'hg'
+        self.message = []
+        self._extrahgfields = []
 
-        message = []
-        comments = []
-        user = None
-        date = None
-        parent = None
-        format = None
-        subject = None
-        diffstart = 0
+        if pf:
+            self.parsepatch(pf)
 
-        for line in file(pf):
-            line = line.rstrip()
-            if line.startswith('diff --git'):
-                diffstart = 2
+    def parsepatch(self, pf):
+        """Parse a patch file and initialize this object with the header data.
+
+        If the format of the header can be determined the format attribute
+        will also be set.
+        """
+        def notdiffline(s):
+            return not (s.startswith("diff -") or
+                        s.startswith("Index:") or
+                        s.startswith("==========="))
+        pf = file(pf)
+        rawh = ''.join((itertools.takewhile(notdiffline, pf))).strip().splitlines()
+
+        try:
+            pf.next()
+            self.haspatch = True
+        except StopIteration:
+            self.haspatch = False
+
+        if not rawh:
+            # Nothing (or only whitespace) came before the diff.
+            return
+
+        if util.any(s.startswith('# HG changeset patch') for s in rawh):
+            # There's an hg-style patch somewhere, but there may be some text
+            # before it. It might be from an email.
+            # Eat the preceeding text and just parse the patch header.
+            while not rawh.pop(0).startswith('# HG changeset patch'):
+                pass
+            self.format = 'hg'
+            self._parsehgheader(rawh)
+        elif rawh[0].startswith('Date: ') or rawh[0].startswith('From: '):
+            self.format = 'plain'
+            self._parseplainheader(rawh)
+        else:
+            # No special headers come before the diff, but *something* did.
+            self.message = rawh
+
+    def _parsehgheader(self, rawh):
+        while rawh:
+            if rawh[0].startswith('# HG changeset patch'):
+                rawh.pop(0)
+            elif rawh[0].startswith('# User '):
+                self.user = rawh.pop(0).split(' ', 2)[-1]
+            elif rawh[0].startswith('# Date '):
+                self.date = rawh.pop(0).split(' ', 2)[-1]
+            elif rawh[0].startswith('# Parent '):
+                self.parent = rawh.pop(0).split(' ', 2)[-1]
+            elif rawh[0].startswith('# '):
+                # Stash the other hg patch header fields (like Node ID and
+                # Branch that export generates) away so they don't go in the
+                # commit message.
+                self._extrahgfields.append(rawh.pop(0))
+            else:
                 break
-            if diffstart:
-                if line.startswith('+++ '):
-                    diffstart = 2
+        message = '\n'.join(rawh).strip()
+        if message:
+            self.message = message.splitlines()
+
+    def _parseplainheader(self, rawh):
+        while rawh:
+            if rawh[0].startswith('Date: '):
+                self.date = rawh.pop(0).split(' ', 1)[-1]
+            elif rawh[0].startswith('From: '):
+                self.user = rawh.pop(0).split(' ', 1)[-1]
+            else:
                 break
-            if line.startswith("--- "):
-                diffstart = 1
-                continue
-            elif format == "hgpatch":
-                # parse values when importing the result of an hg export
-                if line.startswith("# User "):
-                    user = line[7:]
-                elif line.startswith("# Date "):
-                    date = line[7:]
-                elif line.startswith("# Parent "):
-                    parent = line[9:]
-                elif not line.startswith("# ") and line:
-                    message.append(line)
-                    format = None
-            elif line == '# HG changeset patch':
-                message = []
-                format = "hgpatch"
-            elif (format != "tagdone" and (line.startswith("Subject: ") or
-                                           line.startswith("subject: "))):
-                subject = line[9:]
-                format = "tag"
-            elif (format != "tagdone" and (line.startswith("From: ") or
-                                           line.startswith("from: "))):
-                user = line[6:]
-                format = "tag"
-            elif (format != "tagdone" and (line.startswith("Date: ") or
-                                           line.startswith("date: "))):
-                date = line[6:]
-                format = "tag"
-            elif format == "tag" and line == "":
-                # when looking for tags (subject: from: etc) they
-                # end once you find a blank line in the source
-                format = "tagdone"
-            elif message or line:
-                message.append(line)
-            comments.append(line)
+        message = '\n'.join(rawh).strip()
+        if message:
+            self.message = message.splitlines()
 
-        eatdiff(message)
-        eatdiff(comments)
-        eatempty(message)
-        eatempty(comments)
+    def _plainstr(self):
+        """Return a string of this header rendered as a plain-style header."""
+        hs = ''
+        if self.user:
+            hs += 'From: %s\n' % self.user
+        if self.date:
+            hs += 'Date: %s\n' % self.date
+        if self.message:
+            if hs:
+                hs += '\n'
+            hs += '%s\n' % '\n'.join(self.message).rstrip()
+        if hs:
+            hs += '\n'
+        return hs
 
-        # make sure message isn't empty
-        if format and format.startswith("tag") and subject:
-            message.insert(0, "")
-            message.insert(0, subject)
-
-        self.message = message
-        self.comments = comments
-        self.user = user
-        self.date = date
-        self.parent = parent
-        self.haspatch = diffstart > 1
-        self.plainmode = plainmode
-
-    def setuser(self, user):
-        if not self.updateheader(['From: ', '# User '], user):
-            try:
-                patchheaderat = self.comments.index('# HG changeset patch')
-                self.comments.insert(patchheaderat + 1, '# User ' + user)
-            except ValueError:
-                if self.plainmode or self._hasheader(['Date: ']):
-                    self.comments = ['From: ' + user] + self.comments
-                else:
-                    tmp = ['# HG changeset patch', '# User ' + user, '']
-                    self.comments = tmp + self.comments
-        self.user = user
-
-    def setdate(self, date):
-        if not self.updateheader(['Date: ', '# Date '], date):
-            try:
-                patchheaderat = self.comments.index('# HG changeset patch')
-                self.comments.insert(patchheaderat + 1, '# Date ' + date)
-            except ValueError:
-                if self.plainmode or self._hasheader(['From: ']):
-                    self.comments = ['Date: ' + date] + self.comments
-                else:
-                    tmp = ['# HG changeset patch', '# Date ' + date, '']
-                    self.comments = tmp + self.comments
-        self.date = date
-
-    def setparent(self, parent):
-        if not self.updateheader(['# Parent '], parent):
-            try:
-                patchheaderat = self.comments.index('# HG changeset patch')
-                self.comments.insert(patchheaderat + 1, '# Parent ' + parent)
-            except ValueError:
-                pass
-        self.parent = parent
-
-    def setmessage(self, message):
-        if self.comments:
-            self._delmsg()
-        self.message = [message]
-        self.comments += self.message
-
-    def updateheader(self, prefixes, new):
-        '''Update all references to a field in the patch header.
-        Return whether the field is present.'''
-        res = False
-        for prefix in prefixes:
-            for i in xrange(len(self.comments)):
-                if self.comments[i].startswith(prefix):
-                    self.comments[i] = prefix + new
-                    res = True
-                    break
-        return res
-
-    def _hasheader(self, prefixes):
-        '''Check if a header starts with any of the given prefixes.'''
-        for prefix in prefixes:
-            for comment in self.comments:
-                if comment.startswith(prefix):
-                    return True
-        return False
+    def _hgstr(self):
+        """Return a string of this header rendered as an hg-style header."""
+        hs = '# HG changeset patch\n'
+        if self.user:
+            hs += '# User %s\n' % self.user
+        if self.date:
+            hs += '# Date %s\n' % self.date
+        if self.parent:
+            hs += '# Parent %s\n' % self.parent
+        if self._extrahgfields:
+            hs += '\n'.join(self._extrahgfields) + '\n'
+        if self.message:
+            hs += '\n%s\n' % '\n'.join(self.message).rstrip()
+        hs += '\n'
+        return hs
 
     def __str__(self):
-        if not self.comments:
-            return ''
-        return '\n'.join(self.comments) + '\n\n'
+        """Return a string of this header in the appropriate format.
 
-    def _delmsg(self):
-        '''Remove existing message, keeping the rest of the comments fields.
-        If comments contains 'subject: ', message will prepend
-        the field and a blank line.'''
-        if self.message:
-            subj = 'subject: ' + self.message[0].lower()
-            for i in xrange(len(self.comments)):
-                if subj == self.comments[i].lower():
-                    del self.comments[i]
-                    self.message = self.message[2:]
-                    break
-        ci = 0
-        for mi in self.message:
-            while mi != self.comments[ci]:
-                ci += 1
-            del self.comments[ci]
+        For existing patches, the header format is preserved. For new patches
+        the format is determined by the mq.plain configuration option.
+
+        The format can also be set explicitly by setting the format
+        attribute of a patchheader object to 'plain' or 'hg'.
+        """
+        if self.format == 'plain':
+            return self._plainstr()
+        else:
+            return self._hgstr()
+
 
 class queue(object):
     def __init__(self, ui, path, patchdir=None):
+        self.plainmode = ui.configbool('mq', 'plain', False)
         self.basepath = path
         self.path = patchdir or os.path.join(path, "patches")
         self.opener = util.opener(self.path)
@@ -263,7 +228,6 @@
             self.gitmode = gitmode and 'yes' or 'no'
         except error.ConfigError:
             self.gitmode = ui.config('mq', 'git', 'auto').lower()
-        self.plainmode = ui.configbool('mq', 'plain', False)
 
     @util.propertycache
     def applied(self):
@@ -528,7 +492,7 @@
         if n is None:
             raise util.Abort(_("repo commit failed"))
         try:
-            ph = patchheader(mergeq.join(patch), self.plainmode)
+            ph = patchheader(mergeq.join(patch), plain=self.plainmode)
         except:
             raise util.Abort(_("unable to read %s") % patch)
 
@@ -658,7 +622,7 @@
             pf = os.path.join(patchdir, patchname)
 
             try:
-                ph = patchheader(self.join(patchname), self.plainmode)
+                ph = patchheader(self.join(patchname), plain=self.plainmode)
             except:
                 self.ui.warn(_("unable to read %s\n") % patchname)
                 err = 1
@@ -850,21 +814,6 @@
             # if patch file write fails, abort early
             p = self.opener(patchfn, "w")
             try:
-                if self.plainmode:
-                    if user:
-                        p.write("From: " + user + "\n")
-                        if not date:
-                            p.write("\n")
-                    if date:
-                        p.write("Date: %d %d\n\n" % date)
-                else:
-                    p.write("# HG changeset patch\n")
-                    p.write("# Parent "
-                            + hex(repo[None].parents()[0].node()) + "\n")
-                    if user:
-                        p.write("# User " + user + "\n")
-                    if date:
-                        p.write("# Date %s %s\n\n" % date)
                 if hasattr(msg, '__call__'):
                     msg = msg()
                 commitmsg = msg and msg or ("[mq]: %s" % patchfn)
@@ -877,9 +826,17 @@
                     self.parse_series()
                     self.series_dirty = 1
                     self.applied_dirty = 1
+
+                    ph = patchheader(plain=self.plainmode)
+                    if user:
+                        ph.user = user
+                    if date:
+                        ph.date = '%d %d' % date
                     if msg:
-                        msg = msg + "\n\n"
-                        p.write(msg)
+                        ph.message = msg.splitlines()
+                    ph.parent = hex(repo[None].parents()[0].node())
+                    p.write(str(ph))
+
                     if commitfiles:
                         parent = self.qparents(repo, n)
                         chunks = patch.diff(repo, node1=parent, node2=n,
@@ -1228,7 +1185,7 @@
         newuser = opts.get('user')
         newdate = opts.get('date')
         if newdate:
-            newdate = '%d %d' % util.parsedate(newdate)
+            newdate = util.parsedate(newdate)
         wlock = repo.wlock()
 
         try:
@@ -1240,22 +1197,22 @@
 
             cparents = repo.changelog.parents(top)
             patchparent = self.qparents(repo, top)
-            ph = patchheader(self.join(patchfn), self.plainmode)
             diffopts = self.diffopts({'git': opts.get('git')}, patchfn)
+            ph = patchheader(self.join(patchfn), plain=self.plainmode)
+            if newuser:
+                ph.user = newuser
+            if newdate:
+                ph.date = '%d %d' % newdate
             if msg:
-                ph.setmessage(msg)
-            if newuser:
-                ph.setuser(newuser)
-            if newdate:
-                ph.setdate(newdate)
-            ph.setparent(hex(patchparent))
+                ph.message = msg.splitlines()
+            ph.parent = hex(patchparent)
 
             # only commit new patch when write is complete
             patchf = self.opener(patchfn, 'w', atomictemp=True)
 
-            comments = str(ph)
-            if comments:
-                patchf.write(comments)
+            header = str(ph)
+            if header:
+                patchf.write(header)
 
             # update the dirstate in place, strip off the qtip commit
             # and then commit.
@@ -1433,7 +1390,7 @@
                 summary=False):
         def displayname(pfx, patchname):
             if summary:
-                ph = patchheader(self.join(patchname), self.plainmode)
+                ph = patchheader(self.join(patchname))
                 msg = ph.message and ph.message[0] or ''
                 if self.ui.interactive():
                     width = util.termwidth() - len(pfx) - len(patchname) - 2
@@ -2047,7 +2004,7 @@
         if message:
             raise util.Abort(_('option "-e" incompatible with "-m" or "-l"'))
         patch = q.applied[-1].name
-        ph = patchheader(q.join(patch), q.plainmode)
+        ph = patchheader(q.join(patch))
         message = ui.edit('\n'.join(ph.message), ph.user or ui.username())
     setupheaderopts(ui, opts)
     ret = q.refresh(repo, pats, msg=message, **opts)
@@ -2109,7 +2066,7 @@
 
     for p in patches:
         if not message:
-            ph = patchheader(q.join(p), q.plainmode)
+            ph = patchheader(q.join(p))
             if ph.message:
                 messages.append(ph.message)
         pf = q.join(p)
@@ -2119,7 +2076,7 @@
         patch.updatedir(ui, repo, files)
 
     if not message:
-        ph = patchheader(q.join(parent), q.plainmode)
+        ph = patchheader(q.join(parent))
         message, user = ph.message, ph.user
         for msg in messages:
             message.append('* * *')
diff --git a/tests/test-mq-eol.out b/tests/test-mq-eol.out
--- a/tests/test-mq-eol.out
+++ b/tests/test-mq-eol.out
@@ -21,6 +21,9 @@
 % force LF
 applying eol.diff
 now at: eol.diff
+# HG changeset patch<LF>
+# Parent 0d0bf99a8b7a3842c6f8ef09e34f69156c4bd9d0<LF>
+<LF>
 test message<LF>
 <LF>
 diff -r 0d0bf99a8b7a a<LF>
diff --git a/tests/test-mq-git b/tests/test-mq-git
--- a/tests/test-mq-git
+++ b/tests/test-mq-git
@@ -7,6 +7,8 @@
 echo "mq=" >> $HGRCPATH
 echo "[diff]" >> $HGRCPATH
 echo "nodates=1" >> $HGRCPATH
+echo "[mq]" >> $HGRCPATH
+echo "plain=true" >> $HGRCPATH
 
 hg init repo-auto
 cd repo-auto
diff --git a/tests/test-mq-git.out b/tests/test-mq-git.out
--- a/tests/test-mq-git.out
+++ b/tests/test-mq-git.out
@@ -1,7 +1,5 @@
 % git=auto: regular patch creation
-# HG changeset patch
-# Parent 0000000000000000000000000000000000000000
-# Date 0 0
+Date: 0 0
 
 diff -r 000000000000 -r ef8dafc9fa4c a
 --- /dev/null
@@ -9,17 +7,13 @@
 @@ -0,0 +1,1 @@
 +a
 % git=auto: git patch creation with copy
-# HG changeset patch
-# Parent ef8dafc9fa4caff80f6e243eb0171bcd60c455b4
-# Date 0 0
+Date: 0 0
 
 diff --git a/a b/b
 copy from a
 copy to b
 % git=auto: git patch when using --git
-# HG changeset patch
-# Parent 99586d5f048c399e20f81cee41fbb3809c0e735d
-# Date 0 0
+Date: 0 0
 
 diff --git a/regular b/regular
 new file mode 100644
@@ -28,9 +22,7 @@
 @@ -0,0 +1,1 @@
 +regular
 % git=auto: regular patch after qrefresh without --git
-# HG changeset patch
-# Parent 99586d5f048c399e20f81cee41fbb3809c0e735d
-# Date 0 0
+Date: 0 0
 
 diff -r 99586d5f048c regular
 --- /dev/null
@@ -38,9 +30,7 @@
 @@ -0,0 +1,1 @@
 +regular
 % git=keep: git patch with --git
-# HG changeset patch
-# Parent 0000000000000000000000000000000000000000
-# Date 0 0
+Date: 0 0
 
 diff --git a/a b/a
 new file mode 100644
@@ -49,9 +39,7 @@
 @@ -0,0 +1,1 @@
 +a
 % git=keep: git patch after qrefresh without --git
-# HG changeset patch
-# Parent 0000000000000000000000000000000000000000
-# Date 0 0
+Date: 0 0
 
 diff --git a/a b/a
 new file mode 100644
@@ -61,9 +49,7 @@
 +a
 +a
 % git=yes: git patch
-# HG changeset patch
-# Parent 0000000000000000000000000000000000000000
-# Date 0 0
+Date: 0 0
 
 diff --git a/a b/a
 new file mode 100644
@@ -72,9 +58,7 @@
 @@ -0,0 +1,1 @@
 +a
 % git=yes: git patch after qrefresh
-# HG changeset patch
-# Parent 0000000000000000000000000000000000000000
-# Date 0 0
+Date: 0 0
 
 diff --git a/a b/a
 new file mode 100644
@@ -84,9 +68,7 @@
 +a
 +a
 % git=no: regular patch with copy
-# HG changeset patch
-# Parent ef8dafc9fa4caff80f6e243eb0171bcd60c455b4
-# Date 0 0
+Date: 0 0
 
 diff -r ef8dafc9fa4c -r a70404f79ba3 b
 --- /dev/null
@@ -94,9 +76,7 @@
 @@ -0,0 +1,1 @@
 +a
 % git=no: regular patch after qrefresh with copy
-# HG changeset patch
-# Parent ef8dafc9fa4caff80f6e243eb0171bcd60c455b4
-# Date 0 0
+Date: 0 0
 
 diff -r ef8dafc9fa4c b
 --- /dev/null
diff --git a/tests/test-mq-header-date.out b/tests/test-mq-header-date.out
--- a/tests/test-mq-header-date.out
+++ b/tests/test-mq-header-date.out
@@ -114,6 +114,7 @@
 0: [mq]: 1.patch - test
 ==== qref -d
 Date: 9 0
+
 Four
 
 diff -r ... 4
@@ -137,8 +138,8 @@
 ==== hg qref
 adding 5
 # HG changeset patch
+# Date 10 0
 # Parent 
-# Date 10 0
 
 diff -r ... 5
 --- /dev/null
@@ -150,8 +151,8 @@
 0: [mq]: 1.patch - test - 4.00
 ==== hg qref -d
 # HG changeset patch
+# Date 11 0
 # Parent 
-# Date 11 0
 
 diff -r ... 5
 --- /dev/null
@@ -212,8 +213,8 @@
 1: Three (again) - test
 0: [mq]: 1.patch - test
 ==== qref -d
+From: jane
 Date: 12 0
-From: jane
 
 diff -r ... 6
 --- /dev/null
@@ -265,8 +266,8 @@
 1: Three (again) - test
 0: [mq]: 1.patch - test
 ==== qref -u -d
+From: john
 Date: 14 0
-From: john
 
 diff -r ... 8
 --- /dev/null
@@ -295,8 +296,9 @@
 1: Three (again) - test
 0: [mq]: 1.patch - test
 ==== qref -u -d
+From: john
 Date: 15 0
-From: john
+
 Nine
 
 diff -r ... 9
@@ -330,15 +332,15 @@
 ==== init
 ==== qnew -d
 # HG changeset patch
+# Date 3 0
 # Parent 
-# Date 3 0
 
 0: [mq]: 1.patch - test - 3.00
 ==== qref
 adding 1
 # HG changeset patch
+# Date 3 0
 # Parent 
-# Date 3 0
 
 diff -r ... 1
 --- /dev/null
@@ -348,8 +350,8 @@
 0: [mq]: 1.patch - test - 3.00
 ==== qref -d
 # HG changeset patch
+# Date 4 0
 # Parent 
-# Date 4 0
 
 diff -r ... 1
 --- /dev/null
@@ -385,8 +387,8 @@
 now at: 1.patch
 ==== qnew -d -m
 # HG changeset patch
+# Date 6 0
 # Parent 
-# Date 6 0
 
 Three
 
@@ -395,8 +397,8 @@
 ==== qref
 adding 3
 # HG changeset patch
+# Date 6 0
 # Parent 
-# Date 6 0
 
 Three
 
@@ -409,8 +411,8 @@
 0: [mq]: 1.patch - test - 4.00
 ==== qref -m
 # HG changeset patch
+# Date 6 0
 # Parent 
-# Date 6 0
 
 Drei
 
@@ -423,8 +425,8 @@
 0: [mq]: 1.patch - test - 4.00
 ==== qref -d
 # HG changeset patch
+# Date 7 0
 # Parent 
-# Date 7 0
 
 Drei
 
@@ -437,8 +439,8 @@
 0: [mq]: 1.patch - test - 4.00
 ==== qref -d -m
 # HG changeset patch
+# Date 8 0
 # Parent 
-# Date 8 0
 
 Three (again)
 
@@ -453,6 +455,7 @@
 adding 4
 # HG changeset patch
 # Parent 
+
 Four
 
 diff -r ... 4
@@ -467,6 +470,7 @@
 # HG changeset patch
 # Date 9 0
 # Parent 
+
 Four
 
 diff -r ... 4
@@ -490,8 +494,8 @@
 ==== hg qref
 adding 5
 # HG changeset patch
+# Date 10 0
 # Parent 
-# Date 10 0
 
 diff -r ... 5
 --- /dev/null
@@ -503,8 +507,8 @@
 0: [mq]: 1.patch - test - 4.00
 ==== hg qref -d
 # HG changeset patch
+# Date 11 0
 # Parent 
-# Date 11 0
 
 diff -r ... 5
 --- /dev/null
@@ -554,8 +558,8 @@
 ==== qnew -u
 adding 6
 # HG changeset patch
+# User jane
 # Parent 
-# User jane
 
 diff -r ... 6
 --- /dev/null
@@ -568,9 +572,9 @@
 0: [mq]: 1.patch - test
 ==== qref -d
 # HG changeset patch
+# User jane
 # Date 12 0
 # Parent 
-# User jane
 
 diff -r ... 6
 --- /dev/null
@@ -586,8 +590,8 @@
 ==== qnew -d
 adding 7
 # HG changeset patch
+# Date 13 0
 # Parent 
-# Date 13 0
 
 diff -r ... 7
 --- /dev/null
@@ -601,8 +605,8 @@
 ==== qref -u
 # HG changeset patch
 # User john
+# Date 13 0
 # Parent 
-# Date 13 0
 
 diff -r ... 7
 --- /dev/null
@@ -630,8 +634,8 @@
 0: [mq]: 1.patch - test
 ==== qref -u -d
 # HG changeset patch
+# User john
 # Date 14 0
-# User john
 # Parent 
 
 diff -r ... 8
@@ -650,6 +654,7 @@
 adding 9
 # HG changeset patch
 # Parent 
+
 Nine
 
 diff -r ... 9
@@ -664,9 +669,10 @@
 0: [mq]: 1.patch - test
 ==== qref -u -d
 # HG changeset patch
+# User john
 # Date 15 0
-# User john
 # Parent 
+
 Nine
 
 diff -r ... 9
diff --git a/tests/test-mq-header-from.out b/tests/test-mq-header-from.out
--- a/tests/test-mq-header-from.out
+++ b/tests/test-mq-header-from.out
@@ -118,6 +118,7 @@
 0: [mq]: 1.patch - mary
 ==== qref -u
 From: jane
+
 Four
 
 diff -r ... 4of
@@ -143,8 +144,8 @@
 ==== hg qref
 adding 5
 # HG changeset patch
+# User johndoe
 # Parent 
-# User johndoe
 
 diff -r ... 5
 --- /dev/null
@@ -158,8 +159,8 @@
 0: [mq]: 1.patch - mary
 ==== hg qref -U
 # HG changeset patch
+# User test
 # Parent 
-# User test
 
 diff -r ... 5
 --- /dev/null
@@ -173,8 +174,8 @@
 0: [mq]: 1.patch - mary
 ==== hg qref -u
 # HG changeset patch
+# User johndeere
 # Parent 
-# User johndeere
 
 diff -r ... 5
 --- /dev/null
@@ -266,14 +267,15 @@
 ==== init
 ==== qnew -U
 # HG changeset patch
+# User test
 # Parent 
-# User test
+
 0: [mq]: 1.patch - test
 ==== qref
 adding 1
 # HG changeset patch
+# User test
 # Parent 
-# User test
 
 diff -r ... 1
 --- /dev/null
@@ -283,8 +285,8 @@
 0: [mq]: 1.patch - test
 ==== qref -u
 # HG changeset patch
+# User mary
 # Parent 
-# User mary
 
 diff -r ... 1
 --- /dev/null
@@ -318,8 +320,9 @@
 0: [mq]: 1.patch - mary
 ==== qnew -U -m
 # HG changeset patch
+# User test
 # Parent 
-# User test
+
 Three
 
 2: Three - test
@@ -328,8 +331,9 @@
 ==== qref
 adding 3
 # HG changeset patch
+# User test
 # Parent 
-# User test
+
 Three
 
 diff -r ... 3
@@ -342,8 +346,9 @@
 0: [mq]: 1.patch - mary
 ==== qref -m
 # HG changeset patch
+# User test
 # Parent 
-# User test
+
 Drei
 
 diff -r ... 3
@@ -356,8 +361,9 @@
 0: [mq]: 1.patch - mary
 ==== qref -u
 # HG changeset patch
+# User mary
 # Parent 
-# User mary
+
 Drei
 
 diff -r ... 3
@@ -370,8 +376,9 @@
 0: [mq]: 1.patch - mary
 ==== qref -u -m
 # HG changeset patch
+# User maria
 # Parent 
-# User maria
+
 Three (again)
 
 diff -r ... 3
@@ -386,6 +393,7 @@
 adding 4of
 # HG changeset patch
 # Parent 
+
 Four
 
 diff -r ... 4of
@@ -401,6 +409,7 @@
 # HG changeset patch
 # User jane
 # Parent 
+
 Four
 
 diff -r ... 4of
@@ -426,8 +435,8 @@
 ==== hg qref
 adding 5
 # HG changeset patch
+# User johndoe
 # Parent 
-# User johndoe
 
 diff -r ... 5
 --- /dev/null
@@ -441,8 +450,8 @@
 0: [mq]: 1.patch - mary
 ==== hg qref -U
 # HG changeset patch
+# User test
 # Parent 
-# User test
 
 diff -r ... 5
 --- /dev/null
@@ -456,8 +465,8 @@
 0: [mq]: 1.patch - mary
 ==== hg qref -u
 # HG changeset patch
+# User johndeere
 # Parent 
-# User johndeere
 
 diff -r ... 5
 --- /dev/null
@@ -548,14 +557,15 @@
 ==== init
 ==== qnew -U
 # HG changeset patch
+# User test
 # Parent 
-# User test
+
 0: [mq]: 1.patch - test
 ==== qref
 adding 1
 # HG changeset patch
+# User test
 # Parent 
-# User test
 
 diff -r ... 1
 --- /dev/null
@@ -565,8 +575,8 @@
 0: [mq]: 1.patch - test
 ==== qref -u
 # HG changeset patch
+# User mary
 # Parent 
-# User mary
 
 diff -r ... 1
 --- /dev/null
@@ -600,8 +610,9 @@
 0: [mq]: 1.patch - mary
 ==== qnew -U -m
 # HG changeset patch
+# User test
 # Parent 
-# User test
+
 Three
 
 2: Three - test
@@ -610,8 +621,9 @@
 ==== qref
 adding 3
 # HG changeset patch
+# User test
 # Parent 
-# User test
+
 Three
 
 diff -r ... 3
@@ -624,8 +636,9 @@
 0: [mq]: 1.patch - mary
 ==== qref -m
 # HG changeset patch
+# User test
 # Parent 
-# User test
+
 Drei
 
 diff -r ... 3
@@ -638,8 +651,9 @@
 0: [mq]: 1.patch - mary
 ==== qref -u
 # HG changeset patch
+# User mary
 # Parent 
-# User mary
+
 Drei
 
 diff -r ... 3
@@ -652,8 +666,9 @@
 0: [mq]: 1.patch - mary
 ==== qref -u -m
 # HG changeset patch
+# User maria
 # Parent 
-# User maria
+
 Three (again)
 
 diff -r ... 3
@@ -668,6 +683,7 @@
 adding 4of
 # HG changeset patch
 # Parent 
+
 Four
 
 diff -r ... 4of
@@ -683,6 +699,7 @@
 # HG changeset patch
 # User jane
 # Parent 
+
 Four
 
 diff -r ... 4of
@@ -708,8 +725,8 @@
 ==== hg qref
 adding 5
 # HG changeset patch
+# User johndoe
 # Parent 
-# User johndoe
 
 diff -r ... 5
 --- /dev/null
@@ -723,8 +740,8 @@
 0: [mq]: 1.patch - mary
 ==== hg qref -U
 # HG changeset patch
+# User test
 # Parent 
-# User test
 
 diff -r ... 5
 --- /dev/null
@@ -738,8 +755,8 @@
 0: [mq]: 1.patch - mary
 ==== hg qref -u
 # HG changeset patch
+# User johndeere
 # Parent 
-# User johndeere
 
 diff -r ... 5
 --- /dev/null
diff --git a/tests/test-mq-merge b/tests/test-mq-merge
--- a/tests/test-mq-merge
+++ b/tests/test-mq-merge
@@ -18,6 +18,7 @@
 echo "mq =" >> $HGRCPATH
 echo "[mq]" >> $HGRCPATH
 echo "git = keep" >> $HGRCPATH
+echo "plain = true" >> $HGRCPATH
 
 # Commit two dummy files in "init" changeset
 hg init t
diff --git a/tests/test-mq-merge.out b/tests/test-mq-merge.out
--- a/tests/test-mq-merge.out
+++ b/tests/test-mq-merge.out
@@ -34,9 +34,6 @@
 applying patcha2
 now at: patcha2
 % check patcha is still a git patch
-# HG changeset patch
-# Parent d3873e73d99ef67873dac33fbcc66268d5d2b6f4
-
 diff --git a/a b/a
 --- a/a
 +++ b/a
diff --git a/tests/test-mq-qnew.out b/tests/test-mq-qnew.out
--- a/tests/test-mq-qnew.out
+++ b/tests/test-mq-qnew.out
@@ -63,6 +63,7 @@
 % qnew -m
 # HG changeset patch
 # Parent 
+
 foo bar
 
 % qnew twice
@@ -77,6 +78,7 @@
 M d/b
 # HG changeset patch
 # Parent 
+
 diff --git a/d/b b/d/b
 --- a/d/b
 +++ b/d/b
@@ -85,8 +87,9 @@
 +b
 % qnew -u with no username configured
 # HG changeset patch
+# User blue
 # Parent 
-# User blue
+
 % fail when trying to import a merge
 adding a
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
diff --git a/tests/test-mq-qpush-fail b/tests/test-mq-qpush-fail
--- a/tests/test-mq-qpush-fail
+++ b/tests/test-mq-qpush-fail
@@ -4,6 +4,8 @@
 
 echo "[extensions]" >> $HGRCPATH
 echo "mq=" >> $HGRCPATH
+echo "[mq]" >> $HGRCPATH
+echo "plain=true" >> $HGRCPATH
 
 hg init repo
 cd repo
diff --git a/tests/test-mq-qrefresh.out b/tests/test-mq-qrefresh.out
--- a/tests/test-mq-qrefresh.out
+++ b/tests/test-mq-qrefresh.out
@@ -33,6 +33,7 @@
 % patch file contents
 # HG changeset patch
 # Parent 
+
 mqbase
 
 diff -r b55ecdccb5cf 1/base
@@ -77,6 +78,7 @@
 % patch file contents
 # HG changeset patch
 # Parent 
+
 mqbase
 
 diff -r b55ecdccb5cf 1/base
@@ -115,6 +117,7 @@
 % patch file contents
 # HG changeset patch
 # Parent 
+
 mqbase
 
 diff -r b55ecdccb5cf 1/base
@@ -153,6 +156,7 @@
 % patch file contents
 # HG changeset patch
 # Parent 
+
 mqbase
 
 diff -r b55ecdccb5cf 1/base
@@ -191,6 +195,7 @@
 % -- patch file content
 # HG changeset patch
 # Parent 
+
 mqbase
 
 diff -r b55ecdccb5cf 1/base
diff --git a/tests/test-mq.out b/tests/test-mq.out
--- a/tests/test-mq.out
+++ b/tests/test-mq.out
@@ -33,6 +33,16 @@
 will override the [diff] section and always generate git or regular patches,
 possibly losing data in the second case.
 
+By default, mq will automatically use hg-style patch headers when creating new
+patches. This behavior can be changed with:
+
+  [mq]
+  plain = true
+
+If set to 'true', mq will use plain headers with only "Date" and "From"
+fields. For existing patches with headers the header format will always be
+preserved.
+
 list of commands:
 
  qapplied     print the patches already applied




More information about the Mercurial-devel mailing list