[PATCH] Let util.binary check entire data for \0 (issue1066, issue1079)

Christian Ebert blacktrash at gmx.net
Tue Apr 8 18:06:06 CDT 2008


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1207695920 -7200
# Node ID ca917da38fd0e6af7db62841732fa071efa7b75b
# Parent  315548fcc76bf82917143277b9f51484b9e36046
Let util.binary check entire data for \0 (issue1066, issue1079)

In case argument is None, handle it via Exception.

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -243,10 +243,11 @@
     return pipefilter(s, cmd)
 
 def binary(s):
-    """return true if a string is binary data using diff's heuristic"""
-    if s and '\0' in s[:4096]:
-        return True
-    return False
+    """return true if a string is binary data"""
+    try:
+        return '\0' in s
+    except TypeError:
+        return False
 
 def unique(g):
     """return the uniq elements of iterable g"""


More information about the Mercurial-devel mailing list