Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/utils/storageutil.py @ 40008: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 |
comparison
equal
deleted
inserted
replaced
40007:422beffd71ba | 40008:1470183068b8 |
---|---|
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): | 111 def filedataequivalent(store, node, filedata): |
112 """Determines whether file data is equivalent to a stored node.""" | 112 """Determines whether file data is equivalent to a stored node. |
113 | |
114 Returns True if the passed file data would hash to the same value | |
115 as a stored revision and False otherwise. | |
116 | |
117 When a stored revision is censored, filedata must be empty to have | |
118 equivalence. | |
119 | |
120 When a stored revision has copy metadata, it is ignored as part | |
121 of the compare. | |
122 """ | |
113 | 123 |
114 if filedata.startswith(b'\x01\n'): | 124 if filedata.startswith(b'\x01\n'): |
115 revisiontext = b'\x01\n\x01\n' + filedata | 125 revisiontext = b'\x01\n\x01\n' + filedata |
116 else: | 126 else: |
117 revisiontext = filedata | 127 revisiontext = filedata |
119 p1, p2 = store.parents(node) | 129 p1, p2 = store.parents(node) |
120 | 130 |
121 computednode = hashrevisionsha1(revisiontext, p1, p2) | 131 computednode = hashrevisionsha1(revisiontext, p1, p2) |
122 | 132 |
123 if computednode == node: | 133 if computednode == node: |
124 return False | 134 return True |
125 | 135 |
126 # Censored files compare against the empty file. | 136 # Censored files compare against the empty file. |
127 if store.iscensored(store.rev(node)): | 137 if store.iscensored(store.rev(node)): |
128 return filedata != b'' | 138 return filedata == b'' |
129 | 139 |
130 # Renaming a file produces a different hash, even if the data | 140 # Renaming a file produces a different hash, even if the data |
131 # remains unchanged. Check if that's the case. | 141 # remains unchanged. Check if that's the case. |
132 if store.renamed(node): | 142 if store.renamed(node): |
133 return store.read(node) != filedata | 143 return store.read(node) == filedata |
134 | 144 |
135 return True | 145 return False |
136 | 146 |
137 def iterrevs(storelen, start=0, stop=None): | 147 def iterrevs(storelen, start=0, stop=None): |
138 """Iterate over revision numbers in a store.""" | 148 """Iterate over revision numbers in a store.""" |
139 step = 1 | 149 step = 1 |
140 | 150 |