Patchwork D10378: urlutil: add a `get_pull_paths` to perform the pull destination logic

login
register
mail settings
Submitter phabricator
Date April 13, 2021, 12:19 p.m.
Message ID <differential-rev-PHID-DREV-u4zzpahi4e37p3qd2xiw-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48696/
State Superseded
Headers show

Comments

phabricator - April 13, 2021, 12:19 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  As is this changeset does not change anything. However having an official empty
  point will help unifying the logic and encapsulate the details and update the
  logic to support path definition pointing to multiple other path.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10378

AFFECTED FILES
  mercurial/commands.py
  mercurial/utils/urlutil.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/utils/urlutil.py b/mercurial/utils/urlutil.py
--- a/mercurial/utils/urlutil.py
+++ b/mercurial/utils/urlutil.py
@@ -453,6 +453,15 @@ 
         yield ui.getpath(dest, default=(b'default-push', b'default'))
 
 
+def get_pull_paths(repo, ui, sources, default_branches=()):
+    """yields all the `(path, branch)` selected as pull source by `sources`"""
+    if not sources:
+        sources = [b'default']
+    for source in sources:
+        url = ui.expandpath(source)
+        yield parseurl(url, default_branches)
+
+
 def parseurl(path, branches=None):
     '''parse url#branch, returning (url, (branch, branches))'''
     u = url(path)
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5386,12 +5386,8 @@ 
         hint = _(b'use hg pull followed by hg update DEST')
         raise error.InputError(msg, hint=hint)
 
-    if not sources:
-        sources = [b'default']
-    for source in sources:
-        source, branches = urlutil.parseurl(
-            ui.expandpath(source), opts.get(b'branch')
-        )
+    sources = urlutil.get_pull_paths(repo, ui, sources, opts.get(b'branch'))
+    for source, branches in sources:
         ui.status(_(b'pulling from %s\n') % urlutil.hidepassword(source))
         ui.flush()
         other = hg.peer(repo, opts, source)