Mercurial > hg
comparison mercurial/hg.py @ 37640:ce8828217369
hg: use command executor for wire protocol commands
As part of this, I realized that some uses of lookup in a loop
could be converted to use a batch request. But I didn't change
behavior and left in a todo to track potentially changing this.
Differential Revision: https://phab.mercurial-scm.org/D3291
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 13 Apr 2018 11:17:45 -0700 |
parents | ce566e0f73d0 |
children | 0664be4f0c1f |
comparison
equal
deleted
inserted
replaced
37639:0e50dda7e9c1 | 37640:ce8828217369 |
---|---|
79 if not peer.capable('branchmap'): | 79 if not peer.capable('branchmap'): |
80 if branches: | 80 if branches: |
81 raise error.Abort(_("remote branch lookup not supported")) | 81 raise error.Abort(_("remote branch lookup not supported")) |
82 revs.append(hashbranch) | 82 revs.append(hashbranch) |
83 return revs, revs[0] | 83 return revs, revs[0] |
84 branchmap = peer.branchmap() | 84 |
85 with peer.commandexecutor() as e: | |
86 branchmap = e.callcommand('branchmap', {}).result() | |
85 | 87 |
86 def primary(branch): | 88 def primary(branch): |
87 if branch == '.': | 89 if branch == '.': |
88 if not lrepo: | 90 if not lrepo: |
89 raise error.Abort(_("dirstate branch not accessible")) | 91 raise error.Abort(_("dirstate branch not accessible")) |
419 if rev: | 421 if rev: |
420 if not srcpeer.capable('lookup'): | 422 if not srcpeer.capable('lookup'): |
421 raise error.Abort(_("src repository does not support " | 423 raise error.Abort(_("src repository does not support " |
422 "revision lookup and so doesn't " | 424 "revision lookup and so doesn't " |
423 "support clone by revision")) | 425 "support clone by revision")) |
424 revs = [srcpeer.lookup(r) for r in rev] | 426 |
427 # TODO this is batchable. | |
428 remoterevs = [] | |
429 for r in rev: | |
430 with srcpeer.commandexecutor() as e: | |
431 remoterevs.append(e.callcommand('lookup', { | |
432 'key': r, | |
433 }).result()) | |
434 revs = remoterevs | |
425 | 435 |
426 # Obtain a lock before checking for or cloning the pooled repo otherwise | 436 # Obtain a lock before checking for or cloning the pooled repo otherwise |
427 # 2 clients may race creating or populating it. | 437 # 2 clients may race creating or populating it. |
428 pooldir = os.path.dirname(sharepath) | 438 pooldir = os.path.dirname(sharepath) |
429 # lock class requires the directory to exist. | 439 # lock class requires the directory to exist. |
565 # Resolve the name from the initial changeset in the remote | 575 # Resolve the name from the initial changeset in the remote |
566 # repository. This returns nullid when the remote is empty. It | 576 # repository. This returns nullid when the remote is empty. It |
567 # raises RepoLookupError if revision 0 is filtered or otherwise | 577 # raises RepoLookupError if revision 0 is filtered or otherwise |
568 # not available. If we fail to resolve, sharing is not enabled. | 578 # not available. If we fail to resolve, sharing is not enabled. |
569 try: | 579 try: |
570 rootnode = srcpeer.lookup('0') | 580 with srcpeer.commandexecutor() as e: |
581 rootnode = e.callcommand('lookup', { | |
582 'key': '0', | |
583 }).result() | |
584 | |
571 if rootnode != node.nullid: | 585 if rootnode != node.nullid: |
572 sharepath = os.path.join(sharepool, node.hex(rootnode)) | 586 sharepath = os.path.join(sharepool, node.hex(rootnode)) |
573 else: | 587 else: |
574 ui.status(_('(not using pooled storage: ' | 588 ui.status(_('(not using pooled storage: ' |
575 'remote appears to be empty)\n')) | 589 'remote appears to be empty)\n')) |
661 if revs: | 675 if revs: |
662 if not srcpeer.capable('lookup'): | 676 if not srcpeer.capable('lookup'): |
663 raise error.Abort(_("src repository does not support " | 677 raise error.Abort(_("src repository does not support " |
664 "revision lookup and so doesn't " | 678 "revision lookup and so doesn't " |
665 "support clone by revision")) | 679 "support clone by revision")) |
666 revs = [srcpeer.lookup(r) for r in revs] | 680 |
681 # TODO this is batchable. | |
682 remoterevs = [] | |
683 for rev in revs: | |
684 with srcpeer.commandexecutor() as e: | |
685 remoterevs.append(e.callcommand('lookup', { | |
686 'key': rev, | |
687 }).result()) | |
688 revs = remoterevs | |
689 | |
667 checkout = revs[0] | 690 checkout = revs[0] |
668 else: | 691 else: |
669 revs = None | 692 revs = None |
670 local = destpeer.local() | 693 local = destpeer.local() |
671 if local: | 694 if local: |
703 if ui.configbool('experimental', 'remotenames'): | 726 if ui.configbool('experimental', 'remotenames'): |
704 logexchange.pullremotenames(destrepo, srcpeer) | 727 logexchange.pullremotenames(destrepo, srcpeer) |
705 | 728 |
706 if update: | 729 if update: |
707 if update is not True: | 730 if update is not True: |
708 checkout = srcpeer.lookup(update) | 731 with srcpeer.commandexecutor() as e: |
732 checkout = e.callcommand('lookup', { | |
733 'key': update, | |
734 }).result() | |
735 | |
709 uprev = None | 736 uprev = None |
710 status = None | 737 status = None |
711 if checkout is not None: | 738 if checkout is not None: |
712 if checkout in destrepo: | 739 if checkout in destrepo: |
713 uprev = checkout | 740 uprev = checkout |