[PATCH 11 of 12] diff: improve detection of binary in record extension

Guillermo Pérez bisho at fb.com
Thu Nov 15 17:23:41 CST 2012


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