D4801: storageutil: extract filelog.cmp() to a standalone function

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Wed Oct 3 15:05:34 UTC 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG422beffd71ba: storageutil: extract filelog.cmp() to a standalone function (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4801?vs=11484&id=11615

REVISION DETAIL
  https://phab.mercurial-scm.org/D4801

AFFECTED FILES
  mercurial/filelog.py
  mercurial/utils/storageutil.py

CHANGE DETAILS

diff --git a/mercurial/utils/storageutil.py b/mercurial/utils/storageutil.py
--- a/mercurial/utils/storageutil.py
+++ b/mercurial/utils/storageutil.py
@@ -108,6 +108,32 @@
 
     return False
 
+def filerevisiondifferent(store, node, filedata):
+    """Determines whether file data is equivalent to a stored node."""
+
+    if filedata.startswith(b'\x01\n'):
+        revisiontext = b'\x01\n\x01\n' + filedata
+    else:
+        revisiontext = filedata
+
+    p1, p2 = store.parents(node)
+
+    computednode = hashrevisionsha1(revisiontext, p1, p2)
+
+    if computednode == node:
+        return False
+
+    # Censored files compare against the empty file.
+    if store.iscensored(store.rev(node)):
+        return filedata != b''
+
+    # Renaming a file produces a different hash, even if the data
+    # remains unchanged. Check if that's the case.
+    if store.renamed(node):
+        return store.read(node) != filedata
+
+    return True
+
 def iterrevs(storelen, start=0, stop=None):
     """Iterate over revision numbers in a store."""
     step = 1
diff --git a/mercurial/filelog.py b/mercurial/filelog.py
--- a/mercurial/filelog.py
+++ b/mercurial/filelog.py
@@ -135,26 +135,7 @@
 
         returns True if text is different than what is stored.
         """
-
-        t = text
-        if text.startswith('\1\n'):
-            t = '\1\n\1\n' + text
-
-        samehashes = not self._revlog.cmp(node, t)
-        if samehashes:
-            return False
-
-        # censored files compare against the empty file
-        if self.iscensored(self.rev(node)):
-            return text != ''
-
-        # renaming a file produces a different hash, even if the data
-        # remains unchanged. Check if it's the case (slow):
-        if self.renamed(node):
-            t2 = self.read(node)
-            return t2 != text
-
-        return True
+        return storageutil.filerevisiondifferent(self, node, text)
 
     def verifyintegrity(self, state):
         return self._revlog.verifyintegrity(state)



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list