Mercurial > public > mercurial-scm > hg
comparison mercurial/subrepo.py @ 46663:a4c19a162615
sshpeer: enable+fix warning about sshpeers not being closed explicitly
I recommend looking at this with a diff that ignores indentation.
The test changes are because localrepo.close() updates some cache,
which appears happens earlier now on rollbacks or strips or something.
The http changes are because httppeer.close() prints stats with
--verbose.
Differential Revision: https://phab.mercurial-scm.org/D9999
author | Valentin Gatien-Baron <valentin.gatienbaron@gmail.com> |
---|---|
date | Mon, 15 Feb 2021 14:48:36 -0500 |
parents | 59fa3890d40a |
children | e2f7b2695ba1 |
comparison
equal
deleted
inserted
replaced
46662:db8037e38085 | 46663:a4c19a162615 |
---|---|
714 if parentrepo.shared() and hg.islocal(srcurl): | 714 if parentrepo.shared() and hg.islocal(srcurl): |
715 self.ui.status( | 715 self.ui.status( |
716 _(b'sharing subrepo %s from %s\n') | 716 _(b'sharing subrepo %s from %s\n') |
717 % (subrelpath(self), srcurl) | 717 % (subrelpath(self), srcurl) |
718 ) | 718 ) |
719 shared = hg.share( | 719 peer = getpeer() |
720 self._repo._subparent.baseui, | 720 try: |
721 getpeer(), | 721 shared = hg.share( |
722 self._repo.root, | 722 self._repo._subparent.baseui, |
723 update=False, | 723 peer, |
724 bookmarks=False, | 724 self._repo.root, |
725 ) | 725 update=False, |
726 bookmarks=False, | |
727 ) | |
728 finally: | |
729 peer.close() | |
726 self._repo = shared.local() | 730 self._repo = shared.local() |
727 else: | 731 else: |
728 # TODO: find a common place for this and this code in the | 732 # TODO: find a common place for this and this code in the |
729 # share.py wrap of the clone command. | 733 # share.py wrap of the clone command. |
730 if parentrepo.shared(): | 734 if parentrepo.shared(): |
741 | 745 |
742 self.ui.status( | 746 self.ui.status( |
743 _(b'cloning subrepo %s from %s\n') | 747 _(b'cloning subrepo %s from %s\n') |
744 % (subrelpath(self), util.hidepassword(srcurl)) | 748 % (subrelpath(self), util.hidepassword(srcurl)) |
745 ) | 749 ) |
746 other, cloned = hg.clone( | 750 peer = getpeer() |
747 self._repo._subparent.baseui, | 751 try: |
748 {}, | 752 other, cloned = hg.clone( |
749 getpeer(), | 753 self._repo._subparent.baseui, |
750 self._repo.root, | 754 {}, |
751 update=False, | 755 peer, |
752 shareopts=shareopts, | 756 self._repo.root, |
753 ) | 757 update=False, |
758 shareopts=shareopts, | |
759 ) | |
760 finally: | |
761 peer.close() | |
754 self._repo = cloned.local() | 762 self._repo = cloned.local() |
755 self._initrepo(parentrepo, source, create=True) | 763 self._initrepo(parentrepo, source, create=True) |
756 self._cachestorehash(srcurl) | 764 self._cachestorehash(srcurl) |
757 else: | 765 else: |
758 self.ui.status( | 766 self.ui.status( |
759 _(b'pulling subrepo %s from %s\n') | 767 _(b'pulling subrepo %s from %s\n') |
760 % (subrelpath(self), util.hidepassword(srcurl)) | 768 % (subrelpath(self), util.hidepassword(srcurl)) |
761 ) | 769 ) |
762 cleansub = self.storeclean(srcurl) | 770 cleansub = self.storeclean(srcurl) |
763 exchange.pull(self._repo, getpeer()) | 771 peer = getpeer() |
772 try: | |
773 exchange.pull(self._repo, peer) | |
774 finally: | |
775 peer.close() | |
764 if cleansub: | 776 if cleansub: |
765 # keep the repo clean after pull | 777 # keep the repo clean after pull |
766 self._cachestorehash(srcurl) | 778 self._cachestorehash(srcurl) |
767 return False | 779 return False |
768 | 780 |
843 self.ui.status( | 855 self.ui.status( |
844 _(b'pushing subrepo %s to %s\n') | 856 _(b'pushing subrepo %s to %s\n') |
845 % (subrelpath(self), util.hidepassword(dsturl)) | 857 % (subrelpath(self), util.hidepassword(dsturl)) |
846 ) | 858 ) |
847 other = hg.peer(self._repo, {b'ssh': ssh}, dsturl) | 859 other = hg.peer(self._repo, {b'ssh': ssh}, dsturl) |
848 res = exchange.push(self._repo, other, force, newbranch=newbranch) | 860 try: |
861 res = exchange.push(self._repo, other, force, newbranch=newbranch) | |
862 finally: | |
863 other.close() | |
849 | 864 |
850 # the repo is now clean | 865 # the repo is now clean |
851 self._cachestorehash(dsturl) | 866 self._cachestorehash(dsturl) |
852 return res.cgresult | 867 return res.cgresult |
853 | 868 |