changeset 23666:965788d9ae09

localrepo: introduce shared method to check if a repository is shared Up until now we compared the "path" and "sharedpath" repository properties to check if a repository is shared. This was relying an implementation detail of shared repositories. In order to make it possible to change the way shared repositories are implemented, we encapsulate this check into its own localrepo method, called shared. This new method returns None if the repository is shared, and something else (for now a string describing the short of share) otherwise. The reason why I did not call this method "isshared" and made it return a boolean is that I plan to introduce a new type of shared repository soon. # NOTES: This is the first patch in a series whose purpose is to add support for creating "full repository shares", which are repositories that share everything with the repository source except their current revision, branch and bookmark. This series is RFC because I am not very sure of some of the solutions I took. Comments are welcome!
author Angel Ezquerra <angel.ezquerra@gmail.com>
date Sun, 21 Dec 2014 00:19:10 +0100
parents a90499a6ad8d
children f8df993516d0
files hgext/share.py mercurial/localrepo.py mercurial/subrepo.py
diffstat 3 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/share.py	Tue Dec 23 16:16:26 2014 -0800
+++ b/hgext/share.py	Sun Dec 21 00:19:10 2014 +0100
@@ -46,7 +46,7 @@
     Copy the store data to the repo and remove the sharedpath data.
     """
 
-    if repo.sharedpath == repo.path:
+    if not repo.shared():
         raise util.Abort(_("this is not a shared repo"))
 
     destlock = lock = None
--- a/mercurial/localrepo.py	Tue Dec 23 16:16:26 2014 -0800
+++ b/mercurial/localrepo.py	Sun Dec 21 00:19:10 2014 +0100
@@ -758,6 +758,12 @@
         # if publishing we can't copy if there is filtered content
         return not self.filtered('visible').changelog.filteredrevs
 
+    def shared(self):
+        '''the type of shared repository (None if not shared)'''
+        if self.sharedpath != self.path:
+            return 'store'
+        return None
+
     def join(self, f, *insidef):
         return os.path.join(self.path, f, *insidef)
 
--- a/mercurial/subrepo.py	Tue Dec 23 16:16:26 2014 -0800
+++ b/mercurial/subrepo.py	Sun Dec 21 00:19:10 2014 +0100
@@ -302,7 +302,7 @@
             return repo.ui.config('paths', 'default-push')
         if repo.ui.config('paths', 'default'):
             return repo.ui.config('paths', 'default')
-        if repo.sharedpath != repo.path:
+        if repo.shared():
             # chop off the .hg component to get the default path form
             return os.path.dirname(repo.sharedpath)
     if abort: