comparison mercurial/utils/storageutil.py @ 40005:1d97a332c6d9

storageutil: extract copy metadata retrieval out of filelog As part of implementing an alternate storage backend, I found myself reinventing this wheel. Let's create a utility function for doing the work. Differential Revision: https://phab.mercurial-scm.org/D4800
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 28 Sep 2018 11:37:49 -0700
parents fa3dc85a747e
children 422beffd71ba
comparison
equal deleted inserted replaced
40004:fa3dc85a747e 40005:1d97a332c6d9
87 return text 87 return text
88 88
89 offset = text.index(b'\x01\n', 2) 89 offset = text.index(b'\x01\n', 2)
90 return text[offset + 2:] 90 return text[offset + 2:]
91 91
92 def filerevisioncopied(store, node):
93 """Resolve file revision copy metadata.
94
95 Returns ``False`` if the file has no copy metadata. Otherwise a
96 2-tuple of the source filename and node.
97 """
98 if store.parents(node)[0] != nullid:
99 return False
100
101 meta = parsemeta(store.revision(node))[0]
102
103 # copy and copyrev occur in pairs. In rare cases due to old bugs,
104 # one can occur without the other. So ensure both are present to flag
105 # as a copy.
106 if meta and b'copy' in meta and b'copyrev' in meta:
107 return meta[b'copy'], bin(meta[b'copyrev'])
108
109 return False
110
92 def iterrevs(storelen, start=0, stop=None): 111 def iterrevs(storelen, start=0, stop=None):
93 """Iterate over revision numbers in a store.""" 112 """Iterate over revision numbers in a store."""
94 step = 1 113 step = 1
95 114
96 if stop is not None: 115 if stop is not None: