changeset 30820:1779dde4c9ef

hg: set default path correctly when doing a clone+share (issue5378) Before, if performing a clone+share from a repo that was itself using shared storage, the share code would copy paths.default from the underlying repo being shared, not from the source given by the user. This patch teaches hg.clonewithshare to resolve paths.default and pass it to share so it can be written to the hgrc accordingly.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 02 Oct 2016 22:34:40 -0700
parents 3e3f2201bbdf
children d24e03da24b5
files mercurial/hg.py tests/test-clone.t
diffstat 2 files changed, 13 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -195,7 +195,7 @@
         return ''
     return os.path.basename(os.path.normpath(path))
 
-def share(ui, source, dest=None, update=True, bookmarks=True):
+def share(ui, source, dest=None, update=True, bookmarks=True, defaultpath=None):
     '''create a shared repository'''
 
     if not islocal(source):
@@ -240,10 +240,10 @@
     destvfs.write('sharedpath', sharedpath)
 
     r = repository(ui, destwvfs.base)
-    postshare(srcrepo, r, bookmarks=bookmarks)
+    postshare(srcrepo, r, bookmarks=bookmarks, defaultpath=defaultpath)
     _postshareupdate(r, update, checkout=checkout)
 
-def postshare(sourcerepo, destrepo, bookmarks=True):
+def postshare(sourcerepo, destrepo, bookmarks=True, defaultpath=None):
     """Called after a new shared repo is created.
 
     The new repo only has a requirements file and pointer to the source.
@@ -252,7 +252,7 @@
     Extensions can wrap this function and write additional entries to
     destrepo/.hg/shared to indicate additional pieces of data to be shared.
     """
-    default = sourcerepo.ui.config('paths', 'default')
+    default = defaultpath or sourcerepo.ui.config('paths', 'default')
     if default:
         fp = destrepo.vfs("hgrc", "w", text=True)
         fp.write("[paths]\n")
@@ -374,8 +374,15 @@
             clone(ui, peeropts, source, dest=sharepath, pull=True,
                   rev=rev, update=False, stream=stream)
 
+    # Resolve the value to put in [paths] section for the source.
+    if islocal(source):
+        defaultpath = os.path.abspath(util.urllocalpath(source))
+    else:
+        defaultpath = source
+
     sharerepo = repository(ui, path=sharepath)
-    share(ui, sharerepo, dest=dest, update=False, bookmarks=False)
+    share(ui, sharerepo, dest=dest, update=False, bookmarks=False,
+          defaultpath=defaultpath)
 
     # We need to perform a pull against the dest repo to fetch bookmarks
     # and other non-store data that isn't shared by default. In the case of
--- a/tests/test-clone.t
+++ b/tests/test-clone.t
@@ -829,7 +829,7 @@
 Default path should be source, not share.
 
   $ hg -R share-dest1b config paths.default
-  $TESTTMP/source1a (glob)
+  $TESTTMP/source1b (glob)
 
 Checked out revision should be head of default branch