[PATCH] win32text: use util.binary to detect \0

Christian Ebert blacktrash at gmx.net
Thu Mar 13 04:47:21 CDT 2008


Hi,

I saw that clevertest() contained an unused argument; and then
thought using util.binary might be a bit quicker. I do not use
windows however, so someone in the know should check. It passes
test-win32text though.

c


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1205401366 -3600
# Node ID 7f4257b5cbfc186c9870916f22264543e3292bd8
# Parent  a375ffc2aa1bfce70b44dcdd3073c29ada3f55bf
win32text: use util.binary to detect \0

diff --git a/hgext/win32text.py b/hgext/win32text.py
--- a/hgext/win32text.py
+++ b/hgext/win32text.py
@@ -22,6 +22,7 @@
 # [hooks]
 # pretxnchangegroup.crlf = python:hgext.win32text.forbidcrlf
 
+from mercurial import util
 from mercurial.i18n import gettext as _
 from mercurial.node import bin, short
 import re
@@ -46,19 +47,15 @@
 def dumbencode(s, cmd):
     return s.replace('\r\n', '\n')
 
-def clevertest(s, cmd):
-    if '\0' in s: return False
-    return True
-
 def cleverdecode(s, cmd, **kwargs):
-    if clevertest(s, cmd):
-        return dumbdecode(s, cmd, **kwargs)
-    return s
+    if util.binary(s):
+        return s
+    return dumbdecode(s, cmd, **kwargs)
 
 def cleverencode(s, cmd):
-    if clevertest(s, cmd):
-        return dumbencode(s, cmd)
-    return s
+    if util.binary(s):
+        return s
+    return dumbencode(s, cmd)
 
 _filters = {
     'dumbdecode:': dumbdecode,
@@ -75,7 +72,7 @@
             if f not in c:
                 continue
             data = c[f].data()
-            if '\0' not in data and '\r\n' in data:
+            if not util.binary(data) and '\r\n' in data:
                 if not halt:
                     ui.warn(_('Attempt to commit or push text file(s) '
                               'using CRLF line endings\n'))



More information about the Mercurial-devel mailing list