Mercurial > public > mercurial-scm > hg
diff mercurial/utils/storageutil.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 |
line wrap: on
line diff
--- a/mercurial/utils/storageutil.py Fri Sep 28 11:37:49 2018 -0700 +++ b/mercurial/utils/storageutil.py Fri Sep 28 11:47:53 2018 -0700 @@ -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