Patchwork [7,of,7] share: add support for unsharing full repository shares

login
register
mail settings
Submitter Angel Ezquerra
Date Nov. 25, 2015, 12:22 a.m.
Message ID <77d851ddce949d61ed06.1448410951@waste.org>
Download mbox | patch
Permalink /patch/11637/
State Changes Requested
Headers show

Comments

Angel Ezquerra - Nov. 25, 2015, 12:22 a.m.
# HG changeset patch
# User Angel Ezquerra <angel.ezquerra@gmail.com>
# Date 1448320648 -3600
#      Tue Nov 24 00:17:28 2015 +0100
# Node ID 77d851ddce949d61ed06970888edde45f34f64ae
# Parent  842eee140028656f82d3d05ca3cdc68677a4ce39
share: add support for unsharing full repository shares

Patch

diff --git a/hgext/share.py b/hgext/share.py
--- a/hgext/share.py
+++ b/hgext/share.py
@@ -40,6 +40,7 @@ 
 from mercurial.i18n import _
 from mercurial import cmdutil, commands, hg, util, extensions, bookmarks, error
 from mercurial.hg import repository, parseurl
+from mercurial.localrepo import LOCALREPOFILES
 import errno
 
 cmdtable = {}
@@ -86,8 +87,6 @@ 
     sharetype = repo.shared()
     if not sharetype:
         raise error.Abort(_("this is not a shared repo"))
-    elif sharetype == 'all':
-        raise error.Abort(_("unsharing a fully shared repo is not supported"))
 
     destlock = lock = None
     lock = repo.lock()
@@ -97,10 +96,28 @@ 
         # not pointed to by changesets, thus causing verify to
         # fail
 
-        destlock = hg.copystore(ui, repo, repo.path)
+        dstpath = repo.path
+        if repo.fullshare:
+            # in fullshare repositories we cannot use repo.path because it is
+            # the same as repo.sharedpath
+            dstpath = repo.localpath
+        destlock = hg.copystore(ui, repo, dstpath)
 
-        sharefile = repo.join('sharedpath')
-        util.rename(sharefile, sharefile + '.old')
+        sharepathfile = repo.join('sharedpath')
+        util.rename(sharepathfile, sharepathfile + '.old')
+        if repo.vfs.exists('shared'):
+            sharedfile = repo.join('shared')
+            util.rename(sharedfile, sharedfile + '.old')
+
+        if sharetype == 'all':
+            # copy everything in the source repo into the target repo,
+            # except for the cache, the local repository files (i.e. the things
+            # that are not shared), the store (which was already copied earlier)
+            # and the locks
+            srcpath = repo.sharedpath
+            ignore = [repo.join(f)
+                for f in LOCALREPOFILES + ('cache', 'store', 'lock', 'wlock')]
+            util.copyfiles(srcpath, dstpath, overwrite=False, ignore=ignore)
 
         repo.requirements.discard('sharedpath')
         repo._writerequirements()
diff --git a/tests/test-share.t b/tests/test-share.t
--- a/tests/test-share.t
+++ b/tests/test-share.t
@@ -527,6 +527,154 @@ 
   undo.desc
   undo.dirstate
 
+unshare a full share
+
+  $ hg unshare
+
+after unsharing the repo should have all the files of a regular repository
+
+  $ ls .hg
+  00changelog.i
+  bookmarks
+  bookmarks.current
+  branch
+  cache
+  dirstate
+  last-message.txt
+  requires
+  shared.old
+  sharedpath.old
+  store
+  undo.backup.bookmarks
+  undo.backup.dirstate
+  undo.bookmarks
+  undo.branch
+  undo.desc
+  undo.dirstate
+  $ hg verify
+  checking changesets
+  checking manifests
+  crosschecking files in changesets and manifests
+  checking files
+  2 files, 8 changesets, 8 total revisions
+
+new commits on the unshared repository should not appear on the source repo
+
+  $ echo c > c
+  $ hg add c
+  $ hg branch newbranch
+  marked working directory as branch newbranch
+  $ hg commit -m "add c"
+  $ hg bookmark newbookmark
+  $ hg log -G
+  @  changeset:   8:91c4a0b340bd
+  |  branch:      newbranch
+  |  bookmark:    bm3
+  |  bookmark:    newbookmark
+  |  tag:         tip
+  |  parent:      6:5ea6503932c4
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     add c
+  |
+  | o  changeset:   7:e0fb5f85a10b
+  | |  bookmark:    bm1
+  | |  parent:      3:b87954705719
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     created in share source
+  | |
+  o |  changeset:   6:5ea6503932c4
+  | |  branch:      createdinshare
+  | |  parent:      4:62f4ded848e4
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     created in full share
+  | |
+  +---o  changeset:   5:92793bfc8cad
+  | |    bookmark:    bm4
+  | |    bookmark:    bm5
+  | |    user:        test
+  | |    date:        Thu Jan 01 00:00:00 1970 +0000
+  | |    summary:     foo in b
+  | |
+  o |  changeset:   4:62f4ded848e4
+  | |  parent:      2:c2e0ac586386
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     testing shared bookmarks
+  | |
+  | o  changeset:   3:b87954705719
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     testing shared bookmarks
+  |
+  o  changeset:   2:c2e0ac586386
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     another file
+  |
+  o  changeset:   1:8af4dc49db9e
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     change in shared clone
+  |
+  o  changeset:   0:d3873e73d99e
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     init
+  
+  $ hg --repository ../repo1 log -G
+  @  changeset:   7:e0fb5f85a10b
+  |  bookmark:    bm1
+  |  tag:         tip
+  |  parent:      3:b87954705719
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     created in share source
+  |
+  | o  changeset:   6:5ea6503932c4
+  | |  branch:      createdinshare
+  | |  bookmark:    bm3
+  | |  parent:      4:62f4ded848e4
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     created in full share
+  | |
+  | | o  changeset:   5:92793bfc8cad
+  | |/   bookmark:    bm4
+  | |    bookmark:    bm5
+  | |    user:        test
+  | |    date:        Thu Jan 01 00:00:00 1970 +0000
+  | |    summary:     foo in b
+  | |
+  | o  changeset:   4:62f4ded848e4
+  | |  parent:      2:c2e0ac586386
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     testing shared bookmarks
+  | |
+  o |  changeset:   3:b87954705719
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     testing shared bookmarks
+  |
+  o  changeset:   2:c2e0ac586386
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     another file
+  |
+  o  changeset:   1:8af4dc49db9e
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     change in shared clone
+  |
+  o  changeset:   0:d3873e73d99e
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     init
+  
+
 Explicitly kill daemons to let the test exit on Windows
 
   $ killdaemons.py