changeset 11702:eb07fbc21e9c

filectx: use cmp(self, fctx) instead of cmp(self, text) This allows more flexibility in implementation, and in particular, lets the context decide if revision text has to be loaded or not.
author Nicolas Dumazet <nicdumz.commits@gmail.com>
date Tue, 27 Jul 2010 23:40:46 +0900
parents 84fb29f5e0d2
children 55a2af02e45c
files mercurial/context.py mercurial/filemerge.py mercurial/localrepo.py mercurial/merge.py
diffstat 4 files changed, 12 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/context.py	Wed Jul 28 11:07:20 2010 +0200
+++ b/mercurial/context.py	Tue Jul 27 23:40:46 2010 +0900
@@ -352,12 +352,12 @@
     def size(self):
         return self._filelog.size(self._filerev)
 
-    def cmp(self, text):
-        """compare text with stored file revision
+    def cmp(self, fctx):
+        """compare with other file context
 
-        returns True if text is different than what is stored.
+        returns True if different than fctx.
         """
-        return self._filelog.cmp(self._filenode, text)
+        return self._filelog.cmp(self._filenode, fctx.data())
 
     def renamed(self):
         """check if file was actually renamed in this changeset revision
@@ -935,12 +935,12 @@
                 raise
             return (t, tz)
 
-    def cmp(self, text):
-        """compare text with disk content
+    def cmp(self, fctx):
+        """compare with other file context
 
-        returns True if text is different than what is on disk.
+        returns True if different than fctx.
         """
-        return self._repo.wread(self._path) != text
+        return self._repo.wread(self._path) != fctx.data()
 
 class memctx(object):
     """Use memctx to perform in-memory commits via localrepo.commitctx().
--- a/mercurial/filemerge.py	Wed Jul 28 11:07:20 2010 +0200
+++ b/mercurial/filemerge.py	Tue Jul 27 23:40:46 2010 +0900
@@ -135,7 +135,7 @@
         except IOError:
             return False
 
-    if not fco.cmp(fcd.data()): # files identical?
+    if not fco.cmp(fcd): # files identical?
         return None
 
     if fca == fco: # backwards, use working dir parent as ancestor
--- a/mercurial/localrepo.py	Wed Jul 28 11:07:20 2010 +0200
+++ b/mercurial/localrepo.py	Tue Jul 27 23:40:46 2010 +0900
@@ -1062,7 +1062,7 @@
                 # do a full compare of any files that might have changed
                 for f in sorted(cmp):
                     if (f not in ctx1 or ctx2.flags(f) != ctx1.flags(f)
-                        or ctx1[f].cmp(ctx2[f].data())):
+                        or ctx1[f].cmp(ctx2[f])):
                         modified.append(f)
                     else:
                         fixup.append(f)
@@ -1106,7 +1106,7 @@
                 if fn in mf1:
                     if (mf1.flags(fn) != mf2.flags(fn) or
                         (mf1[fn] != mf2[fn] and
-                         (mf2[fn] or ctx1[fn].cmp(ctx2[fn].data())))):
+                         (mf2[fn] or ctx1[fn].cmp(ctx2[fn])))):
                         modified.append(fn)
                     elif listclean:
                         clean.append(fn)
--- a/mercurial/merge.py	Wed Jul 28 11:07:20 2010 +0200
+++ b/mercurial/merge.py	Tue Jul 27 23:40:46 2010 +0900
@@ -73,7 +73,7 @@
 def _checkunknown(wctx, mctx):
     "check for collisions between unknown files and files in mctx"
     for f in wctx.unknown():
-        if f in mctx and mctx[f].cmp(wctx[f].data()):
+        if f in mctx and mctx[f].cmp(wctx[f]):
             raise util.Abort(_("untracked file in working directory differs"
                                " from file in requested revision: '%s'") % f)