hgext: introduce unshare command
authorSimon Heimberg <simohe@besonet.ch>
Thu, 11 Aug 2011 00:04:00 +0200
changeset 15079 ea96bdda593c
parent 15078 193e7018dc8c
child 15080 574dc5d74f9b
hgext: introduce unshare command
hgext/share.py
--- a/hgext/share.py	Thu Aug 11 00:03:16 2011 +0200
+++ b/hgext/share.py	Thu Aug 11 00:04:00 2011 +0200
@@ -6,7 +6,9 @@
 '''share a common history between several working directories'''
 
 from mercurial.i18n import _
-from mercurial import hg, commands
+from mercurial import hg, commands, util
+
+import os.path
 
 def share(ui, source, dest=None, noupdate=False):
     """create a new shared repository
@@ -28,11 +30,46 @@
 
     return hg.share(ui, source, dest, not noupdate)
 
+def unshare(ui, repo):
+    """convert a shared repository to a normal one
+
+    Copy the store data to the repo and remove the sharedpath data.
+    """
+
+    if repo.sharedpath == repo.path:
+        raise util.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.join('sharedpath')
+        util.rename(sharefile, sharefile + '.old')
+
+        repo.requirements.discard('sharedpath')
+        repo._writerequirements()
+    finally:
+        destlock and destlock.release()
+        lock and lock.release()
+
+    # update store, spath, sopener and sjoin of repo
+    repo.__init__(ui, repo.root)
+
 cmdtable = {
     "share":
     (share,
      [('U', 'noupdate', None, _('do not create a working copy'))],
      _('[-U] SOURCE [DEST]')),
+    "unshare":
+    (unshare,
+    [],
+    ''),
 }
 
 commands.norepo += " share"