filectx: allow custom comparators

We're going to introduce other sorts of filectxes very soon, and we'd like the
cmp method to function properly (i.e. commutatively) for them. The only way to
make that happen is for this cmp method to call into that specialized one if
that defines a custom comparator.
This commit is contained in:
Siddharth Agarwal 2015-11-13 22:37:51 -08:00
parent c7aefbc8d6
commit 6a83f7850c

View File

@ -747,11 +747,15 @@ class basefilectx(object):
def islink(self): def islink(self):
return 'l' in self.flags() return 'l' in self.flags()
_customcmp = False
def cmp(self, fctx): def cmp(self, fctx):
"""compare with other file context """compare with other file context
returns True if different than fctx. returns True if different than fctx.
""" """
if fctx._customcmp:
return fctx.cmp(self)
if (fctx._filerev is None if (fctx._filerev is None
and (self._repo._encodefilterpats and (self._repo._encodefilterpats
# if file data starts with '\1\n', empty metadata block is # if file data starts with '\1\n', empty metadata block is