Patchwork hg: set default path correctly when doing a clone+share (issue5378)

login
register
mail settings
Submitter Gregory Szorc
Date Oct. 3, 2016, 5:39 a.m.
Message ID <5333771304e905cecc8b.1475473142@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/16823/
State Accepted
Headers show

Comments

Gregory Szorc - Oct. 3, 2016, 5:39 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1475472880 25200
#      Sun Oct 02 22:34:40 2016 -0700
# Node ID 5333771304e905cecc8b35c4c137d407fc49eb92
# Parent  cd7276f7ea8308df2c5d8874d335d73247d0f357
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.
Yuya Nishihara - Oct. 3, 2016, 1:47 p.m.
On Sun, 02 Oct 2016 22:39:02 -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1475472880 25200
> #      Sun Oct 02 22:34:40 2016 -0700
> # Node ID 5333771304e905cecc8b35c4c137d407fc49eb92
> # Parent  cd7276f7ea8308df2c5d8874d335d73247d0f357
> hg: set default path correctly when doing a clone+share (issue5378)

Nice, queued, thanks.

Patch

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -190,17 +190,17 @@  def defaultdest(source):
     >>> defaultdest('http://example.org/foo/')
     'foo'
     '''
     path = util.url(source).path
     if not path:
         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):
         raise error.Abort(_('can only share local repositories'))
 
     if not dest:
         dest = defaultdest(source)
     else:
@@ -235,29 +235,29 @@  def share(ui, source, dest=None, update=
         if inst.errno != errno.ENOENT:
             raise
 
     requirements += 'shared\n'
     destvfs.write('requires', requirements)
     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.
     This function configures additional shared data.
 
     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")
         fp.write("default = %s\n" % default)
         fp.close()
 
     with destrepo.wlock():
         if bookmarks:
@@ -369,18 +369,25 @@  def clonewithshare(ui, peeropts, sharepa
         else:
             ui.status(_('(sharing from new pooled repository %s)\n') % basename)
             # Always use pull mode because hardlinks in share mode don't work
             # well. Never update because working copies aren't necessary in
             # share mode.
             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
     # non-existing shared repo, this means we pull from the remote twice. This
     # is a bit weird. But at the time it was implemented, there wasn't an easy
     # way to pull just non-changegroup data.
     destrepo = repository(ui, path=dest)
     exchange.pull(destrepo, srcpeer, heads=revs)
diff --git a/tests/test-clone.t b/tests/test-clone.t
--- a/tests/test-clone.t
+++ b/tests/test-clone.t
@@ -824,17 +824,17 @@  We only get bookmarks from the remote, n
 
   $ hg -R share-dest1b bookmarks
      head1                     3:4a8dc1ab4c13
      head2                     4:99f71071f117
 
 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
 
   $ hg -R share-dest1b log -r .
   changeset:   4:99f71071f117
   bookmark:    head2
   parent:      0:b5f04eac9d8f
   user:        test