Mercurial > hg-stable
changeset 4103:544838cc1158
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.
author | tailgunner@smtp.ru |
---|---|
date | Sat, 17 Feb 2007 09:54:56 -0200 |
parents | 6fa7a2d0fc2e |
children | 0934fef871f3 |
files | mercurial/mdiff.py |
diffstat | 1 files changed, 6 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/mdiff.py Fri Feb 16 05:10:43 2007 -0200 +++ b/mercurial/mdiff.py Sat Feb 17 09:54:56 2007 -0200 @@ -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 @@ 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)