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

Alexis S. L. Carvalho alexis at cecm.usp.br
Thu Feb 15 11:19:12 UTC 2007


Thus spake tailgunner at smtp.ru:
> 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.

Do you have an example of when unidiff is called for two identical
(binary) files?

> 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 = ""

Comparing a and b directly would probably be even faster :)

Alexis



More information about the Mercurial-devel mailing list