Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/revlogutils/nodemap.py @ 46114:59fa3890d40a
node: import symbols explicitly
There is no point in lazy importing mercurial.node, it is used all over
the place anyway. So consistently import the used symbols directly.
Fix one file using symbols indirectly via mercurial.revlog.
Differential Revision: https://phab.mercurial-scm.org/D9480
author | Joerg Sonnenberger <joerg@bec.de> |
---|---|
date | Tue, 01 Dec 2020 21:54:46 +0100 |
parents | 8ff2d8359d0f |
children | 8e7ce6555ea7 |
comparison
equal
deleted
inserted
replaced
46113:d6afa9c149c3 | 46114:59fa3890d40a |
---|---|
12 import os | 12 import os |
13 import re | 13 import re |
14 import struct | 14 import struct |
15 | 15 |
16 from ..i18n import _ | 16 from ..i18n import _ |
17 from ..node import hex | |
17 | 18 |
18 from .. import ( | 19 from .. import ( |
19 error, | 20 error, |
20 node as nodemod, | |
21 util, | 21 util, |
22 ) | 22 ) |
23 | 23 |
24 | 24 |
25 class NodeMap(dict): | 25 class NodeMap(dict): |
276 | 276 |
277 def _make_uid(): | 277 def _make_uid(): |
278 """return a new unique identifier. | 278 """return a new unique identifier. |
279 | 279 |
280 The identifier is random and composed of ascii characters.""" | 280 The identifier is random and composed of ascii characters.""" |
281 return nodemod.hex(os.urandom(ID_SIZE)) | 281 return hex(os.urandom(ID_SIZE)) |
282 | 282 |
283 | 283 |
284 class NodeMapDocket(object): | 284 class NodeMapDocket(object): |
285 """metadata associated with persistent nodemap data | 285 """metadata associated with persistent nodemap data |
286 | 286 |
459 Each block is a dictionary with keys in `[0, 15]`. Values are either | 459 Each block is a dictionary with keys in `[0, 15]`. Values are either |
460 another block or a revision number. | 460 another block or a revision number. |
461 """ | 461 """ |
462 root = Block() | 462 root = Block() |
463 for rev in range(len(index)): | 463 for rev in range(len(index)): |
464 hex = nodemod.hex(index[rev][7]) | 464 current_hex = hex(index[rev][7]) |
465 _insert_into_block(index, 0, root, rev, hex) | 465 _insert_into_block(index, 0, root, rev, current_hex) |
466 return root | 466 return root |
467 | 467 |
468 | 468 |
469 def _update_trie(index, root, last_rev): | 469 def _update_trie(index, root, last_rev): |
470 """consume""" | 470 """consume""" |
471 changed = 0 | 471 changed = 0 |
472 for rev in range(last_rev + 1, len(index)): | 472 for rev in range(last_rev + 1, len(index)): |
473 hex = nodemod.hex(index[rev][7]) | 473 current_hex = hex(index[rev][7]) |
474 changed += _insert_into_block(index, 0, root, rev, hex) | 474 changed += _insert_into_block(index, 0, root, rev, current_hex) |
475 return changed, root | 475 return changed, root |
476 | 476 |
477 | 477 |
478 def _insert_into_block(index, level, block, current_rev, current_hex): | 478 def _insert_into_block(index, level, block, current_rev, current_hex): |
479 """insert a new revision in a block | 479 """insert a new revision in a block |
498 index, level + 1, entry, current_rev, current_hex | 498 index, level + 1, entry, current_rev, current_hex |
499 ) | 499 ) |
500 else: | 500 else: |
501 # collision with a previously unique prefix, inserting new | 501 # collision with a previously unique prefix, inserting new |
502 # vertices to fit both entry. | 502 # vertices to fit both entry. |
503 other_hex = nodemod.hex(index[entry][7]) | 503 other_hex = hex(index[entry][7]) |
504 other_rev = entry | 504 other_rev = entry |
505 new = Block() | 505 new = Block() |
506 block[hex_digit] = new | 506 block[hex_digit] = new |
507 _insert_into_block(index, level + 1, new, other_rev, other_hex) | 507 _insert_into_block(index, level + 1, new, other_rev, other_hex) |
508 _insert_into_block(index, level + 1, new, current_rev, current_hex) | 508 _insert_into_block(index, level + 1, new, current_rev, current_hex) |
602 msg = b" revision missing from nodemap: %d\n" % r | 602 msg = b" revision missing from nodemap: %d\n" % r |
603 ui.write_err(msg) | 603 ui.write_err(msg) |
604 ret = 1 | 604 ret = 1 |
605 else: | 605 else: |
606 all_revs.remove(r) | 606 all_revs.remove(r) |
607 nm_rev = _find_node(root, nodemod.hex(index[r][7])) | 607 nm_rev = _find_node(root, hex(index[r][7])) |
608 if nm_rev is None: | 608 if nm_rev is None: |
609 msg = b" revision node does not match any entries: %d\n" % r | 609 msg = b" revision node does not match any entries: %d\n" % r |
610 ui.write_err(msg) | 610 ui.write_err(msg) |
611 ret = 1 | 611 ret = 1 |
612 elif nm_rev != r: | 612 elif nm_rev != r: |