[PATCH] Don't lie that "binary file has changed"

tailgunner at smtp.ru tailgunner at smtp.ru
Tue Feb 13 16:19:49 CST 2007


Without -a option to "hg diff", mdiff.unidiff reported that "Binary
file foo has changed" without even trying to compare things. Now it
computes MD5 of old and new files, compares them and makes the conclusion.


diff -r 0a593b528bd7 -r 01855c47da37 mercurial/mdiff.py
--- a/mercurial/mdiff.py	Wed Feb 14 01:05:09 2007 +0300
+++ b/mercurial/mdiff.py	Wed Feb 14 01:05:09 2007 +0300
@@ -57,7 +57,15 @@ def unidiff(a, ad, b, bd, fn, r=None, op
     epoch = util.datestr((0, 0))
 
     if not opts.text and (util.binary(a) or util.binary(b)):
-        l = ['Binary file %s has changed\n' % fn]
+        def h(v):
+            # md5 is used instead of sha1 because md5 is supposedly faster
+            import md5
+            if v == None: v = ""
+            return md5.new(v).hexdigest()
+        if h(a) != h(b):
+            l = ['Binary file %s has changed\n' % fn]
+        else:
+            l = ""
     elif not a:
         b = splitnewlines(b)
         if a is None:



More information about the Mercurial-devel mailing list