diff mercurial/subrepo.py @ 34879:7d51a7792f52

subrepo: implement 'unshare' for Mercurial subrepos I think there's a slight hole here in that a subrepo could be shared, removed from .hgsub, and then it's not part of context.substate (so not iterated over). But the push command has the same hole IIRC, and I think removing a subrepo is an edge case. The import hack is a copy/paste of subrepo.subrepo().
author Matt Harbison <matt_harbison@yahoo.com>
date Tue, 17 Oct 2017 22:55:33 -0400
parents 68e0bcb90357
children 071cbeba4212
line wrap: on
line diff
--- a/mercurial/subrepo.py	Tue Oct 17 21:48:56 2017 -0400
+++ b/mercurial/subrepo.py	Tue Oct 17 22:55:33 2017 -0400
@@ -621,6 +621,11 @@
     def shortid(self, revid):
         return revid
 
+    def unshare(self):
+        '''
+        convert this repository from shared to normal storage.
+        '''
+
     def verify(self):
         '''verify the integrity of the repository.  Return 0 on success or
         warning, 1 on any error.
@@ -1083,6 +1088,24 @@
     def shortid(self, revid):
         return revid[:12]
 
+    @annotatesubrepoerror
+    def unshare(self):
+        # subrepo inherently violates our import layering rules
+        # because it wants to make repo objects from deep inside the stack
+        # so we manually delay the circular imports to not break
+        # scripts that don't use our demand-loading
+        global hg
+        from . import hg as h
+        hg = h
+
+        # Nothing prevents a user from sharing in a repo, and then making that a
+        # subrepo.  Alternately, the previous unshare attempt may have failed
+        # part way through.  So recurse whether or not this layer is shared.
+        if self._repo.shared():
+            self.ui.status(_("unsharing subrepo '%s'\n") % self._relpath)
+
+        hg.unshare(self.ui, self._repo)
+
     def verify(self):
         try:
             rev = self._state[1]