[PATCH 1 of 2] share: move the implementation of 'unshare' to the 'hg' module

Matt Harbison mharbison72 at gmail.com
Wed Oct 18 04:12:38 UTC 2017


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1508291336 14400
#      Tue Oct 17 21:48:56 2017 -0400
# Node ID a6b470f15cc5f902afd54f29b0e53e5c03f6eec6
# Parent  14c87708f4328fa46938be99d6deba678f3455aa
share: move the implementation of 'unshare' to the 'hg' module

This will be used to setup unsharing subrepos.  Usually cmdutil is used for
this purpose.  But the implementation needs hg.copystore(), and the hg module
already imports cmdutil.

diff --git a/hgext/share.py b/hgext/share.py
--- a/hgext/share.py
+++ b/hgext/share.py
@@ -114,28 +114,7 @@
     if not repo.shared():
         raise error.Abort(_("this is not a shared repo"))
 
-    destlock = lock = None
-    lock = repo.lock()
-    try:
-        # we use locks here because if we race with commit, we
-        # can end up with extra data in the cloned revlogs that's
-        # not pointed to by changesets, thus causing verify to
-        # fail
-
-        destlock = hg.copystore(ui, repo, repo.path)
-
-        sharefile = repo.vfs.join('sharedpath')
-        util.rename(sharefile, sharefile + '.old')
-
-        repo.requirements.discard('shared')
-        repo.requirements.discard('relshared')
-        repo._writerequirements()
-    finally:
-        destlock and destlock.release()
-        lock and lock.release()
-
-    # update store, spath, svfs and sjoin of repo
-    repo.unfiltered().__init__(repo.baseui, repo.root)
+    hg.unshare(ui, repo)
 
 # Wrap clone command to pass auto share options.
 def clone(orig, ui, source, *args, **opts):
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -257,6 +257,35 @@
     _postshareupdate(r, update, checkout=checkout)
     return r
 
+def unshare(ui, repo):
+    """convert a shared repository to a normal one
+
+    Copy the store data to the repo and remove the sharedpath data.
+    """
+
+    destlock = lock = None
+    lock = repo.lock()
+    try:
+        # we use locks here because if we race with commit, we
+        # can end up with extra data in the cloned revlogs that's
+        # not pointed to by changesets, thus causing verify to
+        # fail
+
+        destlock = copystore(ui, repo, repo.path)
+
+        sharefile = repo.vfs.join('sharedpath')
+        util.rename(sharefile, sharefile + '.old')
+
+        repo.requirements.discard('shared')
+        repo.requirements.discard('relshared')
+        repo._writerequirements()
+    finally:
+        destlock and destlock.release()
+        lock and lock.release()
+
+    # update store, spath, svfs and sjoin of repo
+    repo.unfiltered().__init__(repo.baseui, repo.root)
+
 def postshare(sourcerepo, destrepo, bookmarks=True, defaultpath=None):
     """Called after a new shared repo is created.
 


More information about the Mercurial-devel mailing list