comparison hgext/share.py @ 15079:ea96bdda593c

hgext: introduce unshare command
author Simon Heimberg <simohe@besonet.ch>
date Thu, 11 Aug 2011 00:04:00 +0200
parents 4ac734b9b3fd
children d23dfcbb8840
comparison
equal deleted inserted replaced
15078:193e7018dc8c 15079:ea96bdda593c
4 # GNU General Public License version 2 or any later version. 4 # GNU General Public License version 2 or any later version.
5 5
6 '''share a common history between several working directories''' 6 '''share a common history between several working directories'''
7 7
8 from mercurial.i18n import _ 8 from mercurial.i18n import _
9 from mercurial import hg, commands 9 from mercurial import hg, commands, util
10
11 import os.path
10 12
11 def share(ui, source, dest=None, noupdate=False): 13 def share(ui, source, dest=None, noupdate=False):
12 """create a new shared repository 14 """create a new shared repository
13 15
14 Initialize a new repository and working directory that shares its 16 Initialize a new repository and working directory that shares its
26 (e.g. tip). 28 (e.g. tip).
27 """ 29 """
28 30
29 return hg.share(ui, source, dest, not noupdate) 31 return hg.share(ui, source, dest, not noupdate)
30 32
33 def unshare(ui, repo):
34 """convert a shared repository to a normal one
35
36 Copy the store data to the repo and remove the sharedpath data.
37 """
38
39 if repo.sharedpath == repo.path:
40 raise util.Abort(_("this is not a shared repo"))
41
42 destlock = lock = None
43 lock = repo.lock()
44 try:
45 # we use locks here because if we race with commit, we
46 # can end up with extra data in the cloned revlogs that's
47 # not pointed to by changesets, thus causing verify to
48 # fail
49
50 destlock = hg.copystore(ui, repo, repo.path)
51
52 sharefile = repo.join('sharedpath')
53 util.rename(sharefile, sharefile + '.old')
54
55 repo.requirements.discard('sharedpath')
56 repo._writerequirements()
57 finally:
58 destlock and destlock.release()
59 lock and lock.release()
60
61 # update store, spath, sopener and sjoin of repo
62 repo.__init__(ui, repo.root)
63
31 cmdtable = { 64 cmdtable = {
32 "share": 65 "share":
33 (share, 66 (share,
34 [('U', 'noupdate', None, _('do not create a working copy'))], 67 [('U', 'noupdate', None, _('do not create a working copy'))],
35 _('[-U] SOURCE [DEST]')), 68 _('[-U] SOURCE [DEST]')),
69 "unshare":
70 (unshare,
71 [],
72 ''),
36 } 73 }
37 74
38 commands.norepo += " share" 75 commands.norepo += " share"