equal
deleted
inserted
replaced
8 from __future__ import absolute_import |
8 from __future__ import absolute_import |
9 |
9 |
10 import hashlib |
10 import hashlib |
11 import re |
11 import re |
12 |
12 |
|
13 from ..i18n import _ |
13 from ..node import ( |
14 from ..node import ( |
|
15 bin, |
14 nullid, |
16 nullid, |
15 ) |
17 ) |
16 from .. import ( |
18 from .. import ( |
|
19 error, |
17 pycompat, |
20 pycompat, |
18 ) |
21 ) |
19 |
22 |
20 _nullhash = hashlib.sha1(nullid) |
23 _nullhash = hashlib.sha1(nullid) |
21 |
24 |
97 stop = storelen |
100 stop = storelen |
98 else: |
101 else: |
99 stop = storelen |
102 stop = storelen |
100 |
103 |
101 return pycompat.xrange(start, stop, step) |
104 return pycompat.xrange(start, stop, step) |
|
105 |
|
106 def fileidlookup(store, fileid, identifier): |
|
107 """Resolve the file node for a value. |
|
108 |
|
109 ``store`` is an object implementing the ``ifileindex`` interface. |
|
110 |
|
111 ``fileid`` can be: |
|
112 |
|
113 * A 20 byte binary node. |
|
114 * An integer revision number |
|
115 * A 40 byte hex node. |
|
116 * A bytes that can be parsed as an integer representing a revision number. |
|
117 |
|
118 ``identifier`` is used to populate ``error.LookupError`` with an identifier |
|
119 for the store. |
|
120 |
|
121 Raises ``error.LookupError`` on failure. |
|
122 """ |
|
123 if isinstance(fileid, int): |
|
124 return store.node(fileid) |
|
125 |
|
126 if len(fileid) == 20: |
|
127 try: |
|
128 store.rev(fileid) |
|
129 return fileid |
|
130 except error.LookupError: |
|
131 pass |
|
132 |
|
133 if len(fileid) == 40: |
|
134 try: |
|
135 rawnode = bin(fileid) |
|
136 store.rev(rawnode) |
|
137 return rawnode |
|
138 except TypeError: |
|
139 pass |
|
140 |
|
141 try: |
|
142 rev = int(fileid) |
|
143 |
|
144 if b'%d' % rev != fileid: |
|
145 raise ValueError |
|
146 |
|
147 try: |
|
148 return store.node(rev) |
|
149 except (IndexError, TypeError): |
|
150 pass |
|
151 except (ValueError, OverflowError): |
|
152 pass |
|
153 |
|
154 raise error.LookupError(fileid, identifier, _('no match found')) |