# HG changeset patch # User tailgunner@smtp.ru # Date 2007-02-17 11:54:56 # Node ID 544838cc1158b14b3475f85e596556633c398845 # Parent 6fa7a2d0fc2e268ea3378afb0bdd314dd6b70aa4 Don't lie that "binary file has changed" 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 --git a/mercurial/mdiff.py b/mercurial/mdiff.py --- a/mercurial/mdiff.py +++ b/mercurial/mdiff.py @@ -7,7 +7,7 @@ from demandload import demandload import bdiff, mpatch -demandload(globals(), "re struct util") +demandload(globals(), "re struct util md5") def splitnewlines(text): '''like str.splitlines, but only split on newlines.''' @@ -59,6 +59,11 @@ 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)): + def h(v): + # md5 is used instead of sha1 because md5 is supposedly faster + return md5.new(v).digest() + if a and b and len(a) == len(b) and h(a) == h(b): + return "" l = ['Binary file %s has changed\n' % fn] elif not a: b = splitnewlines(b)