filelog: add hash-based comparisons
authorMatt Mackall <mpm@selenic.com>
Mon, 14 Aug 2006 15:07:00 -0500
changeset 2887 05257fd28591
parent 2886 bee4b7abcb01
child 2888 3848488244fc
child 2914 cd7bbb19b96e
filelog: add hash-based comparisons For status, rather than reconstruct full file versions from revlog for comparison, compare hashes.
mercurial/filelog.py
mercurial/localrepo.py
--- a/mercurial/filelog.py	Mon Aug 14 14:42:15 2006 -0500
+++ b/mercurial/filelog.py	Mon Aug 14 15:07:00 2006 -0500
@@ -65,6 +65,27 @@
             return (m["copy"], bin(m["copyrev"]))
         return False
 
+    def cmp(self, node, text):
+        """compare text with a given file revision"""
+
+        # for renames, we have to go the slow way
+        if self.renamed(node):
+            t2 = self.read(node)
+            return t2 == text
+
+        p1, p2 = self.parents(node)
+        h = hash(text, p1, p2)
+
+        return h != node
+
+    def makenode(self, node, text):
+        """calculate a file nodeid for text, descended or possibly
+        unchanged from node"""
+
+        if self.cmp(node, text):
+            return hash(text, node, nullid)
+        return node
+
     def annotate(self, node):
 
         def decorate(text, rev):
--- a/mercurial/localrepo.py	Mon Aug 14 14:42:15 2006 -0500
+++ b/mercurial/localrepo.py	Mon Aug 14 15:07:00 2006 -0500
@@ -668,8 +668,7 @@
 
         def fcmp(fn, mf):
             t1 = self.wread(fn)
-            t2 = self.file(fn).read(mf.get(fn, nullid))
-            return cmp(t1, t2)
+            return self.file(fn).cmp(mf.get(fn, nullid), t1)
 
         def mfmatches(node):
             change = self.changelog.read(node)