[PATCH 7 of 8] diff: Improve detection of binary in record extension

Guillermo Pérez bisho at fb.com
Tue Nov 13 16:25:40 CST 2012


# HG changeset patch
# User Guillermo Pérez <bisho at fb.com>
# Date 1352619148 28800
# Node ID ad263d9793fa9d8d437b99a39699585b163da127
# Parent  66b03c1194b664fee9ddd51d6cead74292a6500d
diff: Improve detection of binary in record extension

In the next patch we will introduce the index header not only
for binary diffs, but for all changesets so we need to improve
how record extension detects binary, previously just based
on the presence of that header.

diff --git a/hgext/record.py b/hgext/record.py
--- a/hgext/record.py
+++ b/hgext/record.py
@@ -85,22 +85,29 @@
     """
     diffgit_re = re.compile('diff --git a/(.*) b/(.*)$')
     diff_re = re.compile('diff -r .* (.*)$')
-    allhunks_re = re.compile('(?:index|new file|deleted file) ')
+    allhunks_re = re.compile('(?:index [0-9a-fA-F]{40}\.\.|'
+                             'new file |deleted file )')
     pretty_re = re.compile('(?:new file|deleted file) ')
-    special_re = re.compile('(?:index|new|deleted|copy|rename) ')
+    special_re = re.compile('(?:index [0-9a-f]{40}\.\.|new |'
+                            'deleted |copy |rename )')
 
     def __init__(self, header):
         self.header = header
         self.hunks = []
 
     def binary(self):
-        return util.any(h.startswith('index ') for h in self.header)
+        return util.any(h.startswith('index ') and len(h) >= 88
+                for h in self.header)
 
     def pretty(self, fp):
         for h in self.header:
             if h.startswith('index '):
-                fp.write(_('this modifies a binary file (all or nothing)\n'))
-                break
+                if len(h) >= 88:
+                    fp.write(_('this modifies a binary file '
+                               '(all or nothing)\n'))
+                    break
+                else:
+                    continue
             if self.pretty_re.match(h):
                 fp.write(h)
                 if self.binary():


More information about the Mercurial-devel mailing list