[PATCH 4 of 5] diff: improve detection of binary in record extension

Guillermo Pérez bisho at fb.com
Wed Nov 21 11:28:16 CST 2012


# HG changeset patch
# User Guillermo Pérez <bisho at fb.com>
# Date 1352619148 28800
# Node ID a03561228cb1d473a018f05a35b4c88f04db2c45
# Parent  aaa7c6adde0e3e42944cb8b5c0b55a6d9a086c95
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