changeset 40007:1470183068b8

storageutil: invert logic of file data comparison IMO things make more sense when the function is explicitly a test for file data equivalence. Not bothering with API since the function was introduced by the previous commit. Differential Revision: https://phab.mercurial-scm.org/D4802
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 28 Sep 2018 11:51:17 -0700
parents 422beffd71ba
children 842ffcf1d42f
files mercurial/filelog.py mercurial/utils/storageutil.py
diffstat 2 files changed, 17 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/filelog.py	Fri Sep 28 11:47:53 2018 -0700
+++ b/mercurial/filelog.py	Fri Sep 28 11:51:17 2018 -0700
@@ -135,7 +135,7 @@
 
         returns True if text is different than what is stored.
         """
-        return storageutil.filerevisiondifferent(self, node, text)
+        return not storageutil.filedataequivalent(self, node, text)
 
     def verifyintegrity(self, state):
         return self._revlog.verifyintegrity(state)
--- a/mercurial/utils/storageutil.py	Fri Sep 28 11:47:53 2018 -0700
+++ b/mercurial/utils/storageutil.py	Fri Sep 28 11:51:17 2018 -0700
@@ -108,8 +108,18 @@
 
     return False
 
-def filerevisiondifferent(store, node, filedata):
-    """Determines whether file data is equivalent to a stored node."""
+def filedataequivalent(store, node, filedata):
+    """Determines whether file data is equivalent to a stored node.
+
+    Returns True if the passed file data would hash to the same value
+    as a stored revision and False otherwise.
+
+    When a stored revision is censored, filedata must be empty to have
+    equivalence.
+
+    When a stored revision has copy metadata, it is ignored as part
+    of the compare.
+    """
 
     if filedata.startswith(b'\x01\n'):
         revisiontext = b'\x01\n\x01\n' + filedata
@@ -121,18 +131,18 @@
     computednode = hashrevisionsha1(revisiontext, p1, p2)
 
     if computednode == node:
-        return False
+        return True
 
     # Censored files compare against the empty file.
     if store.iscensored(store.rev(node)):
-        return filedata != b''
+        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 store.read(node) == filedata
 
-    return True
+    return False
 
 def iterrevs(storelen, start=0, stop=None):
     """Iterate over revision numbers in a store."""