[PATCH] record: teach parsepatch() about non-git style headers

Steve Borho steve at borho.org
Wed Dec 8 22:16:54 CST 2010


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1291868058 21600
# Branch stable
# Node ID 8d7e37cae5f4b147a48da35753e3f8fd5e1896b1
# Parent  6e79a3bb8c790549fbd916d5f89f2ac25a2cbb34
record: teach parsepatch() about non-git style headers

These changes are not useful to record itself, since it is hard coded
to always generate git style diffs.  But it makes parsepatch() more
generally useful for parsing normal patch files.

diff -r 6e79a3bb8c79 -r 8d7e37cae5f4 hgext/record.py
--- a/hgext/record.py	Tue Dec 07 20:03:04 2010 +1100
+++ b/hgext/record.py	Wed Dec 08 22:14:18 2010 -0600
@@ -42,7 +42,7 @@
         line = lr.readline()
         if not line:
             break
-        if line.startswith('diff --git a/'):
+        if line.startswith('diff --git a/') or line.startswith('diff -r '):
             def notheader(line):
                 s = line.split(None, 1)
                 return not s or s[0] not in ('---', 'diff')
@@ -70,7 +70,8 @@
 
     XXX shoudn't we move this to mercurial/patch.py ?
     """
-    diff_re = re.compile('diff --git a/(.*) b/(.*)$')
+    diffgit_re = re.compile('diff --git a/(.*) b/(.*)$')
+    diff_re = re.compile('diff -r .* (.*)$')
     allhunks_re = re.compile('(?:index|new file|deleted file) ')
     pretty_re = re.compile('(?:new file|deleted file) ')
     special_re = re.compile('(?:index|new|deleted|copy|rename) ')
@@ -110,10 +111,14 @@
                 return True
 
     def files(self):
-        fromfile, tofile = self.diff_re.match(self.header[0]).groups()
-        if fromfile == tofile:
-            return [fromfile]
-        return [fromfile, tofile]
+        match = self.diffgit_re.match(self.header[0])
+        if match:
+            fromfile, tofile = match.groups()
+            if fromfile == tofile:
+                return [fromfile]
+            return [fromfile, tofile]
+        else:
+            return self.diff_re.match(self.header[0]).groups()
 
     def filename(self):
         return self.files()[-1]


More information about the Mercurial-devel mailing list