comparison 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
comparison
equal deleted inserted replaced
40005:1d97a332c6d9 40006:422beffd71ba
106 if meta and b'copy' in meta and b'copyrev' in meta: 106 if meta and b'copy' in meta and b'copyrev' in meta:
107 return meta[b'copy'], bin(meta[b'copyrev']) 107 return meta[b'copy'], bin(meta[b'copyrev'])
108 108
109 return False 109 return False
110 110
111 def filerevisiondifferent(store, node, filedata):
112 """Determines whether file data is equivalent to a stored node."""
113
114 if filedata.startswith(b'\x01\n'):
115 revisiontext = b'\x01\n\x01\n' + filedata
116 else:
117 revisiontext = filedata
118
119 p1, p2 = store.parents(node)
120
121 computednode = hashrevisionsha1(revisiontext, p1, p2)
122
123 if computednode == node:
124 return False
125
126 # Censored files compare against the empty file.
127 if store.iscensored(store.rev(node)):
128 return filedata != b''
129
130 # Renaming a file produces a different hash, even if the data
131 # remains unchanged. Check if that's the case.
132 if store.renamed(node):
133 return store.read(node) != filedata
134
135 return True
136
111 def iterrevs(storelen, start=0, stop=None): 137 def iterrevs(storelen, start=0, stop=None):
112 """Iterate over revision numbers in a store.""" 138 """Iterate over revision numbers in a store."""
113 step = 1 139 step = 1
114 140
115 if stop is not None: 141 if stop is not None: