[PATCH]Make hg diff go nice on binary files
Fuming Wang
fumingw at yahoo.com
Thu Jul 14 14:29:02 UTC 2005
Hi,
I am using mercurial to trach text and binary files,
the diff command on binary files will go nuts. The
following patch will make diff just report "binary
file has changed" for binary files. idea of testing
binary file is copied from gnu diff.
Cheers,
Fuming Wang
fumingw yahoo com
-----------------------------------------
--- mercurial-snapshot\mercurial\mdiff.py Sun Jul 10
14:00:04 2005
+++ e:\mercurial-0708\mercurial\mdiff.py Thu Jul 14
21:54:20 2005
@@ -12,7 +12,9 @@
if not a and not b: return ""
- if a == None:
+ if is_binary(a) or is_binary(b):
+ l = ['binary file has changed\n']
+ elif a == None:
b = b.splitlines(1)
l1 = "--- %s\t%s\n" % ("/dev/null", ad)
l2 = "+++ %s\t%s\n" % ("b/" + fn, bd)
@@ -114,6 +116,11 @@
def patch(a, bin):
return patches(a, [bin])
+
+def is_binary(a):
+ check_length = min(200, len(a))
+ return '\0' in a[:check_length]
+
textdiff = bdiff.bdiff
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the Mercurial
mailing list