comparison mercurial/filelog.py @ 40006:422beffd71ba

storageutil: extract filelog.cmp() to a standalone function As part of implementing an alternate storage backend, I found myself reimplementing this code. With a little massaging, we can extract filelog.cmp() to a standalone function. As part of this, the call to revlog.cmp() was inlined (it is just a 2-line function). I also tweaked some variable names to improve readability. I'll further tweak names in a subsequent commit. Differential Revision: https://phab.mercurial-scm.org/D4801
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 28 Sep 2018 11:47:53 -0700
parents 1d97a332c6d9
children 1470183068b8
comparison
equal deleted inserted replaced
40005:1d97a332c6d9 40006:422beffd71ba
133 def cmp(self, node, text): 133 def cmp(self, node, text):
134 """compare text with a given file revision 134 """compare text with a given file revision
135 135
136 returns True if text is different than what is stored. 136 returns True if text is different than what is stored.
137 """ 137 """
138 138 return storageutil.filerevisiondifferent(self, node, text)
139 t = text
140 if text.startswith('\1\n'):
141 t = '\1\n\1\n' + text
142
143 samehashes = not self._revlog.cmp(node, t)
144 if samehashes:
145 return False
146
147 # censored files compare against the empty file
148 if self.iscensored(self.rev(node)):
149 return text != ''
150
151 # renaming a file produces a different hash, even if the data
152 # remains unchanged. Check if it's the case (slow):
153 if self.renamed(node):
154 t2 = self.read(node)
155 return t2 != text
156
157 return True
158 139
159 def verifyintegrity(self, state): 140 def verifyintegrity(self, state):
160 return self._revlog.verifyintegrity(state) 141 return self._revlog.verifyintegrity(state)
161 142
162 def storageinfo(self, exclusivefiles=False, sharedfiles=False, 143 def storageinfo(self, exclusivefiles=False, sharedfiles=False,