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.
hg-reviewers |
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.
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/filelog.py (2 lines) | |||
M | mercurial/utils/storageutil.py (22 lines) |
# XXX if self.read(node).startswith("\1\n"), this returns (size+4) | # XXX if self.read(node).startswith("\1\n"), this returns (size+4) | ||||
return self._revlog.size(rev) | return self._revlog.size(rev) | ||||
def cmp(self, node, text): | def cmp(self, node, text): | ||||
"""compare text with a given file revision | """compare text with a given file revision | ||||
returns True if text is different than what is stored. | 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): | def verifyintegrity(self, state): | ||||
return self._revlog.verifyintegrity(state) | return self._revlog.verifyintegrity(state) | ||||
def storageinfo(self, exclusivefiles=False, sharedfiles=False, | def storageinfo(self, exclusivefiles=False, sharedfiles=False, | ||||
revisionscount=False, trackedsize=False, | revisionscount=False, trackedsize=False, | ||||
storedsize=False): | storedsize=False): | ||||
return self._revlog.storageinfo( | return self._revlog.storageinfo( |
# copy and copyrev occur in pairs. In rare cases due to old bugs, | # copy and copyrev occur in pairs. In rare cases due to old bugs, | ||||
# one can occur without the other. So ensure both are present to flag | # one can occur without the other. So ensure both are present to flag | ||||
# as a copy. | # as a copy. | ||||
if meta and b'copy' in meta and b'copyrev' in meta: | if meta and b'copy' in meta and b'copyrev' in meta: | ||||
return meta[b'copy'], bin(meta[b'copyrev']) | return meta[b'copy'], bin(meta[b'copyrev']) | ||||
return False | return False | ||||
def filerevisiondifferent(store, node, filedata): | def filedataequivalent(store, node, filedata): | ||||
"""Determines whether file data is equivalent to a stored node.""" | """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'): | if filedata.startswith(b'\x01\n'): | ||||
revisiontext = b'\x01\n\x01\n' + filedata | revisiontext = b'\x01\n\x01\n' + filedata | ||||
else: | else: | ||||
revisiontext = filedata | revisiontext = filedata | ||||
p1, p2 = store.parents(node) | p1, p2 = store.parents(node) | ||||
computednode = hashrevisionsha1(revisiontext, p1, p2) | computednode = hashrevisionsha1(revisiontext, p1, p2) | ||||
if computednode == node: | if computednode == node: | ||||
return False | return True | ||||
# Censored files compare against the empty file. | # Censored files compare against the empty file. | ||||
if store.iscensored(store.rev(node)): | if store.iscensored(store.rev(node)): | ||||
return filedata != b'' | return filedata == b'' | ||||
# Renaming a file produces a different hash, even if the data | # Renaming a file produces a different hash, even if the data | ||||
# remains unchanged. Check if that's the case. | # remains unchanged. Check if that's the case. | ||||
if store.renamed(node): | 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): | def iterrevs(storelen, start=0, stop=None): | ||||
"""Iterate over revision numbers in a store.""" | """Iterate over revision numbers in a store.""" | ||||
step = 1 | step = 1 | ||||
if stop is not None: | if stop is not None: | ||||
if start > stop: | if start > stop: | ||||
step = -1 | step = -1 |