From patchwork Tue Jul 9 21:54:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [11,of,14,RFC] memfilectx: add cmp method From: Sean Farley X-Patchwork-Id: 1819 Message-Id: <1fa8870e0ae8dc5f23f5.1373406882@laptop.local> To: mercurial-devel@selenic.com Date: Tue, 09 Jul 2013 16:54:42 -0500 # HG changeset patch # User Sean Farley # Date 1373323864 18000 # Mon Jul 08 17:51:04 2013 -0500 # Node ID 1fa8870e0ae8dc5f23f5326470c5fbc93f63a95b # Parent 15c72f9d02eada7a9811034da42628f30bfd073a memfilectx: add cmp method This is directly copied from the filectx with the only change being to call the "self.data() != fctx.data()" directly instead of going through the filelog. Is there a better way to do this compare? diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -1380,5 +1380,20 @@ return 'x' in self._flags def islink(self): return 'l' in self._flags def renamed(self): return self._copied + + def cmp(self, fctx): + """compare with other file context or workingfile context + + returns True if different than fctx. + """ + if (fctx._filerev is None + and (self._repo._encodefilterpats + # if file data starts with '\1\n', empty metadata block is + # prepended, which adds 4 bytes to filelog.size(). + or self.size() - 4 == fctx.size()) + or self.size() == fctx.size()): + return self.data() != fctx.data() + + return True