diff --git a/hgext/keyword.py b/hgext/keyword.py --- a/hgext/keyword.py +++ b/hgext/keyword.py @@ -100,11 +100,6 @@ def utcdate(date): '''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 @@ class kwtemplater(object): 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 @@ class kwtemplater(object): 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 @@ class kwtemplater(object): 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 @@ class kwtemplater(object): '''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 diff --git a/hgext/win32text.py b/hgext/win32text.py --- a/hgext/win32text.py +++ b/hgext/win32text.py @@ -64,27 +64,23 @@ def macdumbdecode(s, cmd, **kwargs): 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 @@ def forbidnewline(ui, repo, hooktype, no 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') %