comparison mercurial/context.py @ 26977:bd19561b98d9

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.
author Siddharth Agarwal <sid0@fb.com>
date Fri, 13 Nov 2015 22:37:51 -0800
parents 5ba0a99ff27f
children 9b9d4bcc915e
comparison
equal deleted inserted replaced
26976:c48fee950ce4 26977:bd19561b98d9
745 def isexec(self): 745 def isexec(self):
746 return 'x' in self.flags() 746 return 'x' in self.flags()
747 def islink(self): 747 def islink(self):
748 return 'l' in self.flags() 748 return 'l' in self.flags()
749 749
750 _customcmp = False
750 def cmp(self, fctx): 751 def cmp(self, fctx):
751 """compare with other file context 752 """compare with other file context
752 753
753 returns True if different than fctx. 754 returns True if different than fctx.
754 """ 755 """
756 if fctx._customcmp:
757 return fctx.cmp(self)
758
755 if (fctx._filerev is None 759 if (fctx._filerev is None
756 and (self._repo._encodefilterpats 760 and (self._repo._encodefilterpats
757 # if file data starts with '\1\n', empty metadata block is 761 # if file data starts with '\1\n', empty metadata block is
758 # prepended, which adds 4 bytes to filelog.size(). 762 # prepended, which adds 4 bytes to filelog.size().
759 or self.size() - 4 == fctx.size()) 763 or self.size() - 4 == fctx.size())