Patchwork D10401: urlutil: add a `get_clone_path` function

login
register
mail settings
Submitter phabricator
Date April 14, 2021, 11:37 p.m.
Message ID <differential-rev-PHID-DREV-ovabxnxwygmceqwj4zri-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48718/
State Superseded
Headers show

Comments

phabricator - April 14, 2021, 11:37 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  We add a new function with a semantic focussed on `clone` operation (so without
  an existing repository). I am not certain the return type is the best, but this
  is what we need for now. Once all caller are migrated we might start thinking
  about that the API should be. For now that will do.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/hg.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
@@ -471,6 +471,13 @@ 
         yield parseurl(url, default_branches)
 
 
+def get_clone_path(ui, source, default_branches=()):
+    """return the `(origsource, path, branch)` selected as clone source"""
+    url = ui.expandpath(source)
+    path, branch = parseurl(url, default_branches)
+    return url, path, branch
+
+
 def parseurl(path, branches=None):
     '''parse url#branch, returning (url, (branch, branches))'''
     u = url(path)
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -672,8 +672,8 @@ 
     """
 
     if isinstance(source, bytes):
-        origsource = ui.expandpath(source)
-        source, branches = urlutil.parseurl(origsource, branch)
+        src = urlutil.get_clone_path(ui, source, branch)
+        origsource, source, branches = src
         srcpeer = peer(ui, peeropts, source)
     else:
         srcpeer = source.peer()  # in case we were called with a localrepo