[PATCH 7 of 8 RFC] context: add isbinary function
Laurens Holst
laurens.nospam at grauw.nl
Wed Dec 21 13:45:57 CST 2011
# HG changeset patch
# User Laurens Holst <laurens.hg at grauw.nl>
# Date 1324488015 -3600
# Node ID f6232f3261c0843c78c4283974bf05b5ebff6016
# Parent d9641cafc0a939c15b2dec11c8412cea74a90482
context: add isbinary function
There is a little bit of code duplication here, and I think this can nicely live
on the file context.
diff -r d9641cafc0a9 -r f6232f3261c0 mercurial/context.py
--- a/mercurial/context.py Wed Dec 21 18:16:12 2011 +0100
+++ b/mercurial/context.py Wed Dec 21 18:20:15 2011 +0100
@@ -370,6 +370,12 @@
def size(self):
return self._filelog.size(self._filerev)
+ def isbinary(self):
+ try:
+ return util.binary(self.data())
+ except IOError:
+ return False
+
def cmp(self, fctx):
"""compare with other file context
diff -r d9641cafc0a9 -r f6232f3261c0 mercurial/filemerge.py
--- a/mercurial/filemerge.py Wed Dec 21 18:16:12 2011 +0100
+++ b/mercurial/filemerge.py Wed Dec 21 18:20:15 2011 +0100
@@ -142,18 +142,12 @@
f.close()
return name
- def isbin(ctx):
- try:
- return util.binary(ctx.data())
- except IOError:
- return False
-
if not fco.cmp(fcd): # files identical?
return None
ui = repo.ui
fd = fcd.path()
- binary = isbin(fcd) or isbin(fco) or isbin(fca)
+ binary = fcd.isbinary() or fco.isbinary() or fca.isbinary()
symlink = 'l' in fcd.flags() + fco.flags()
tool, toolpath = _picktool(repo, ui, fd, binary, symlink)
ui.debug("picked tool '%s' for %s (binary %s symlink %s)\n" %
diff -r d9641cafc0a9 -r f6232f3261c0 mercurial/merge.py
--- a/mercurial/merge.py Wed Dec 21 18:16:12 2011 +0100
+++ b/mercurial/merge.py Wed Dec 21 18:20:15 2011 +0100
@@ -638,12 +638,6 @@
he is ready for it.
"""
- def isbin(ctx):
- try:
- return util.binary(ctx.data())
- except IOError:
- return False
-
for a in action:
f, m = a[:2]
if m == "pr" or m == "pg" or ((m == "e" or m == "g") and a[2] == "pf") \
@@ -670,7 +664,7 @@
if not fca:
fca = repo.filectx(f, fileid=nullrev)
- binary = isbin(fcl) or isbin(fco) or isbin(fca)
+ binary = fcl.isbinary() or fco.isbinary() or fca.isbinary()
symlink = 'l' in fcl.flags() + fco.flags()
if binary or symlink:
More information about the Mercurial-devel
mailing list