Get rid of reimplementations of util.binary
authorBryan O'Sullivan <bos@serpentine.com>
Wed, 09 Apr 2008 15:49:20 -0700
changeset 6508 4b2c266bf059
parent 6507 9699864de219
child 6509 5279848424e7
Get rid of reimplementations of util.binary
hgext/keyword.py
hgext/win32text.py
--- a/hgext/keyword.py	Tue Apr 08 13:19:36 2008 +0200
+++ b/hgext/keyword.py	Wed Apr 09 15:49:20 2008 -0700
@@ -100,11 +100,6 @@
     '''Returns hgdate in cvs-like UTC format.'''
     return time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(date[0]))
 
-def textsafe(s):
-    '''Safe version of util.binary with reversed logic.
-    Note: argument may not be None, which is allowed for util.binary.'''
-    return '\0' not in s
-
 # make keyword tools accessible
 kwtools = {'templater': None, 'hgcmd': '', 'inc': [], 'exc': ['.hg*']}
 
@@ -163,7 +158,7 @@
 
     def expand(self, path, node, data):
         '''Returns data with keywords expanded.'''
-        if not self.restrict and self.matcher(path) and textsafe(data):
+        if not self.restrict and self.matcher(path) and not util.binary(data):
             changenode = self.getnode(path, node)
             return self.substitute(data, path, changenode, self.re_kw.sub)
         return data
@@ -191,7 +186,7 @@
             for f in candidates:
                 fp = self.repo.file(f)
                 data = fp.read(mf[f])
-                if not textsafe(data):
+                if util.binary(data):
                     continue
                 if expand:
                     changenode = node or self.getnode(f, mf[f])
@@ -211,7 +206,7 @@
 
     def shrink(self, fname, text):
         '''Returns text with all keyword substitutions removed.'''
-        if self.matcher(fname) and textsafe(text):
+        if self.matcher(fname) and not util.binary(text):
             return self.shrinktext(text)
         return text
 
@@ -219,7 +214,7 @@
         '''Returns lines with keyword substitutions removed.'''
         if self.matcher(fname):
             text = ''.join(lines)
-            if textsafe(text):
+            if not util.binary(text):
                 return self.shrinktext(text).splitlines(True)
         return lines
 
--- a/hgext/win32text.py	Tue Apr 08 13:19:36 2008 +0200
+++ b/hgext/win32text.py	Wed Apr 09 15:49:20 2008 -0700
@@ -64,27 +64,23 @@
 def macdumbencode(s, cmd):
     return s.replace('\r', '\n')
 
-def clevertest(s, cmd):
-    if '\0' in s: return False
-    return True
-
 def cleverdecode(s, cmd, **kwargs):
-    if clevertest(s, cmd):
+    if not util.binary(s):
         return dumbdecode(s, cmd, **kwargs)
     return s
 
 def cleverencode(s, cmd):
-    if clevertest(s, cmd):
+    if not util.binary(s):
         return dumbencode(s, cmd)
     return s
 
 def macdecode(s, cmd, **kwargs):
-    if clevertest(s, cmd):
+    if not util.binary(s):
         return macdumbdecode(s, cmd, **kwargs)
     return s
 
 def macencode(s, cmd):
-    if clevertest(s, cmd):
+    if not util.binary(s):
         return macdumbencode(s, cmd)
     return s
 
@@ -107,7 +103,7 @@
             if f not in c:
                 continue
             data = c[f].data()
-            if '\0' not in data and newline in data:
+            if not util.binary(data) and newline in data:
                 if not halt:
                     ui.warn(_('Attempt to commit or push text file(s) '
                               'using %s line endings\n') %