Patchwork [1,of,2,STABLE] subrepo: use sharepath if available when locating the source repo

mail settings
Submitter Matt Harbison
Date Jan. 30, 2013, 3:26 a.m.
Message ID <8032309101bf203cbef6.1359516418@Envy>
Download mbox | patch
Permalink /patch/760/
State Accepted
Commit f254ab6207aedf3445e5497b3d5fdb0268ce1eb1
Headers show


Matt Harbison - Jan. 30, 2013, 3:26 a.m.
# HG changeset patch
# User Matt Harbison <>
# Date 1354067787 18000
# Branch stable
# Node ID 8032309101bf203cbef6ae46abdf81be86c9fd8b
# Parent  692cbda1eb50fe30c70792cb1e9380b28769467c
subrepo: use sharepath if available when locating the source repo

This is an alternative fix for issue3518, enabling sharing of repositories with
subrepos, without unconditionally setting the default path in the resulting
repo's hgrc file.  Better test coverage is added here, but won't prove this code
is working until fd903f89e42b is backed out.

The problem with the original fix is, if a default path is not available to be
copied over from the share source, the default path on the resulting repo is set
to the source location.  Since that's where the actual repository is stored, the
path is essentially self-referential, so push, pull, incoming and outgoing
effectively operate on itself.  While incoming and outgoing make it look like
nothing was changed, push currently hangs (see issue3657).  In this case where
there is not a real default path, these operations should abort with
"default(-push) not found", like the source repo would.  Note this problem with
the original fix affected repos without subrepos too.


diff --git a/mercurial/ b/mercurial/
--- a/mercurial/
+++ b/mercurial/
@@ -264,6 +264,9 @@ 
             return repo.ui.config('paths', 'default-push')
         if repo.ui.config('paths', 'default'):
             return repo.ui.config('paths', 'default')
+        if repo.sharedpath != repo.path:
+            # chop off the .hg component to get the default path form
+            return os.path.dirname(repo.sharedpath)
     if abort:
         raise util.Abort(_("default path for subrepository not found"))
diff --git a/tests/test-subrepo.t b/tests/test-subrepo.t
--- a/tests/test-subrepo.t
+++ b/tests/test-subrepo.t
@@ -725,6 +725,19 @@ 
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ test -f ../shared/subrepo-1/.hg/sharedpath
+  $ hg -R ../shared in
+  comparing with $TESTTMP/subrepo-status (glob)
+  searching for changes
+  no changes found
+  [1]
+  $ hg -R ../shared/subrepo-2 showconfig paths
+  paths.default=$TESTTMP/subrepo-status/subrepo-2
+  $ hg -R ../shared/subrepo-1 sum --remote
+  parent: -1:000000000000 tip (empty repository)
+  branch: default
+  commit: (clean)
+  update: (current)
+  remote: (synced)
 Check hg update --clean
   $ cd $TESTTMP/t