##// END OF EJS Templates
share: declare commands using decorator
Gregory Szorc -
r21253:d2ce7a20 default
parent child Browse files
Show More
@@ -1,75 +1,70 b''
1 # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com>
1 # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com>
2 #
2 #
3 # This software may be used and distributed according to the terms of the
3 # This software may be used and distributed according to the terms of the
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, util
9 from mercurial import cmdutil, hg, commands, util
10
10
11 cmdtable = {}
12 command = cmdutil.command(cmdtable)
11 testedwith = 'internal'
13 testedwith = 'internal'
12
14
15 @command('share',
16 [('U', 'noupdate', None, _('do not create a working copy'))],
17 _('[-U] SOURCE [DEST]'))
13 def share(ui, source, dest=None, noupdate=False):
18 def share(ui, source, dest=None, noupdate=False):
14 """create a new shared repository
19 """create a new shared repository
15
20
16 Initialize a new repository and working directory that shares its
21 Initialize a new repository and working directory that shares its
17 history with another repository.
22 history with another repository.
18
23
19 .. note::
24 .. note::
20
25
21 using rollback or extensions that destroy/modify history (mq,
26 using rollback or extensions that destroy/modify history (mq,
22 rebase, etc.) can cause considerable confusion with shared
27 rebase, etc.) can cause considerable confusion with shared
23 clones. In particular, if two shared clones are both updated to
28 clones. In particular, if two shared clones are both updated to
24 the same changeset, and one of them destroys that changeset
29 the same changeset, and one of them destroys that changeset
25 with rollback, the other clone will suddenly stop working: all
30 with rollback, the other clone will suddenly stop working: all
26 operations will fail with "abort: working directory has unknown
31 operations will fail with "abort: working directory has unknown
27 parent". The only known workaround is to use debugsetparents on
32 parent". The only known workaround is to use debugsetparents on
28 the broken clone to reset it to a changeset that still exists.
33 the broken clone to reset it to a changeset that still exists.
29 """
34 """
30
35
31 return hg.share(ui, source, dest, not noupdate)
36 return hg.share(ui, source, dest, not noupdate)
32
37
38 @command('unshare', [], '')
33 def unshare(ui, repo):
39 def unshare(ui, repo):
34 """convert a shared repository to a normal one
40 """convert a shared repository to a normal one
35
41
36 Copy the store data to the repo and remove the sharedpath data.
42 Copy the store data to the repo and remove the sharedpath data.
37 """
43 """
38
44
39 if repo.sharedpath == repo.path:
45 if repo.sharedpath == repo.path:
40 raise util.Abort(_("this is not a shared repo"))
46 raise util.Abort(_("this is not a shared repo"))
41
47
42 destlock = lock = None
48 destlock = lock = None
43 lock = repo.lock()
49 lock = repo.lock()
44 try:
50 try:
45 # we use locks here because if we race with commit, we
51 # we use locks here because if we race with commit, we
46 # can end up with extra data in the cloned revlogs that's
52 # can end up with extra data in the cloned revlogs that's
47 # not pointed to by changesets, thus causing verify to
53 # not pointed to by changesets, thus causing verify to
48 # fail
54 # fail
49
55
50 destlock = hg.copystore(ui, repo, repo.path)
56 destlock = hg.copystore(ui, repo, repo.path)
51
57
52 sharefile = repo.join('sharedpath')
58 sharefile = repo.join('sharedpath')
53 util.rename(sharefile, sharefile + '.old')
59 util.rename(sharefile, sharefile + '.old')
54
60
55 repo.requirements.discard('sharedpath')
61 repo.requirements.discard('sharedpath')
56 repo._writerequirements()
62 repo._writerequirements()
57 finally:
63 finally:
58 destlock and destlock.release()
64 destlock and destlock.release()
59 lock and lock.release()
65 lock and lock.release()
60
66
61 # update store, spath, sopener and sjoin of repo
67 # update store, spath, sopener and sjoin of repo
62 repo.unfiltered().__init__(repo.baseui, repo.root)
68 repo.unfiltered().__init__(repo.baseui, repo.root)
63
69
64 cmdtable = {
65 "share":
66 (share,
67 [('U', 'noupdate', None, _('do not create a working copy'))],
68 _('[-U] SOURCE [DEST]')),
69 "unshare":
70 (unshare,
71 [],
72 ''),
73 }
74
75 commands.norepo += " share"
70 commands.norepo += " share"
General Comments 0
You need to be logged in to leave comments. Login now