changeset 18510:f254ab6207ae stable

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.
author Matt Harbison <matt_harbison@yahoo.com>
date Tue, 27 Nov 2012 20:56:27 -0500
parents 21daee53c101
children 798ab869b2ee
files mercurial/subrepo.py tests/test-subrepo.t
diffstat 2 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/subrepo.py	Tue Jan 22 14:33:17 2013 +0100
+++ b/mercurial/subrepo.py	Tue Nov 27 20:56:27 2012 -0500
@@ -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"))
 
--- a/tests/test-subrepo.t	Tue Jan 22 14:33:17 2013 +0100
+++ b/tests/test-subrepo.t	Tue Nov 27 20:56:27 2012 -0500
@@ -725,6 +725,19 @@
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ test -f ../shared/subrepo-1/.hg/sharedpath
   [1]
+  $ 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