changeset 51485:fc317bd5b637 stable

fold-or-prune-me: update proposal This does the same things but with a narrower wrapping.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 02 May 2024 08:46:58 +0200
parents 3e0f86f09f26
children 6c39edd1d348
files mercurial/hg.py
diffstat 1 files changed, 44 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hg.py	Sun Mar 31 17:57:46 2024 -0300
+++ b/mercurial/hg.py	Thu May 02 08:46:58 2024 +0200
@@ -1420,44 +1420,58 @@
     )
 
 
+_no_subtoppath = object()
+
+
 def _outgoing(ui, repo, dests, opts, subpath=None):
     out = set()
     others = []
     for path in urlutil.get_push_paths(repo, ui, dests):
         dest = path.loc
-        repo._subtoppath = dest
-        if subpath is not None:
-            subpath = urlutil.url(subpath)
-            if subpath.isabs():
-                dest = bytes(subpath)
-            else:
-                p = urlutil.url(dest)
-                if p.islocal():
-                    normpath = os.path.normpath
+        prev_subtopath = getattr(repo, "_subtoppath", _no_subtoppath)
+        try:
+            repo._subtoppath = dest
+            if subpath is not None:
+                subpath = urlutil.url(subpath)
+                if subpath.isabs():
+                    dest = bytes(subpath)
                 else:
-                    normpath = posixpath.normpath
-                p.path = normpath(b'%s/%s' % (p.path, subpath))
-                dest = bytes(p)
-        branches = path.branch, opts.get(b'branch') or []
+                    p = urlutil.url(dest)
+                    if p.islocal():
+                        normpath = os.path.normpath
+                    else:
+                        normpath = posixpath.normpath
+                    p.path = normpath(b'%s/%s' % (p.path, subpath))
+                    dest = bytes(p)
+            branches = path.branch, opts.get(b'branch') or []
 
-        ui.status(_(b'comparing with %s\n') % urlutil.hidepassword(dest))
-        revs, checkout = addbranchrevs(repo, repo, branches, opts.get(b'rev'))
-        if revs:
-            revs = [repo[rev].node() for rev in logcmdutil.revrange(repo, revs)]
+            ui.status(_(b'comparing with %s\n') % urlutil.hidepassword(dest))
+            revs, checkout = addbranchrevs(
+                repo, repo, branches, opts.get(b'rev')
+            )
+            if revs:
+                revs = [
+                    repo[rev].node() for rev in logcmdutil.revrange(repo, revs)
+                ]
 
-        other = peer(repo, opts, dest)
-        try:
-            outgoing = discovery.findcommonoutgoing(
-                repo, other, revs, force=opts.get(b'force')
-            )
-            o = outgoing.missing
-            out.update(o)
-            if not o:
-                scmutil.nochangesfound(repo.ui, repo, outgoing.excluded)
-            others.append(other)
-        except:  # re-raises
-            other.close()
-            raise
+            other = peer(repo, opts, dest)
+            try:
+                outgoing = discovery.findcommonoutgoing(
+                    repo, other, revs, force=opts.get(b'force')
+                )
+                o = outgoing.missing
+                out.update(o)
+                if not o:
+                    scmutil.nochangesfound(repo.ui, repo, outgoing.excluded)
+                others.append(other)
+            except:  # re-raises
+                other.close()
+                raise
+        finally:
+            if prev_subtopath is _no_subtoppath:
+                del repo._subtoppath
+            else:
+                repo._subtoppath = prev_subtopath
     # make sure this is ordered by revision number
     outgoing_revs = list(out)
     cl = repo.changelog
@@ -1529,7 +1543,6 @@
     finally:
         for oth in others:
             oth.close()
-        del repo._subtoppath
 
 
 def verify(repo, level=None):