##// END OF EJS Templates
share: replace reference to 'sopener' with 'svfs'...
Siddharth Agarwal -
r25666:1c7e6236 default
parent child Browse files
Show More
@@ -1,129 +1,129 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 cmdutil, hg, util, extensions, bookmarks
9 from mercurial import cmdutil, hg, util, extensions, bookmarks
10 from mercurial.hg import repository, parseurl
10 from mercurial.hg import repository, parseurl
11 import errno
11 import errno
12
12
13 cmdtable = {}
13 cmdtable = {}
14 command = cmdutil.command(cmdtable)
14 command = cmdutil.command(cmdtable)
15 # Note for extension authors: ONLY specify testedwith = 'internal' for
15 # Note for extension authors: ONLY specify testedwith = 'internal' for
16 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
16 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
17 # be specifying the version(s) of Mercurial they are tested with, or
17 # be specifying the version(s) of Mercurial they are tested with, or
18 # leave the attribute unspecified.
18 # leave the attribute unspecified.
19 testedwith = 'internal'
19 testedwith = 'internal'
20
20
21 @command('share',
21 @command('share',
22 [('U', 'noupdate', None, _('do not create a working directory')),
22 [('U', 'noupdate', None, _('do not create a working directory')),
23 ('B', 'bookmarks', None, _('also share bookmarks'))],
23 ('B', 'bookmarks', None, _('also share bookmarks'))],
24 _('[-U] [-B] SOURCE [DEST]'),
24 _('[-U] [-B] SOURCE [DEST]'),
25 norepo=True)
25 norepo=True)
26 def share(ui, source, dest=None, noupdate=False, bookmarks=False):
26 def share(ui, source, dest=None, noupdate=False, bookmarks=False):
27 """create a new shared repository
27 """create a new shared repository
28
28
29 Initialize a new repository and working directory that shares its
29 Initialize a new repository and working directory that shares its
30 history (and optionally bookmarks) with another repository.
30 history (and optionally bookmarks) with another repository.
31
31
32 .. note::
32 .. note::
33
33
34 using rollback or extensions that destroy/modify history (mq,
34 using rollback or extensions that destroy/modify history (mq,
35 rebase, etc.) can cause considerable confusion with shared
35 rebase, etc.) can cause considerable confusion with shared
36 clones. In particular, if two shared clones are both updated to
36 clones. In particular, if two shared clones are both updated to
37 the same changeset, and one of them destroys that changeset
37 the same changeset, and one of them destroys that changeset
38 with rollback, the other clone will suddenly stop working: all
38 with rollback, the other clone will suddenly stop working: all
39 operations will fail with "abort: working directory has unknown
39 operations will fail with "abort: working directory has unknown
40 parent". The only known workaround is to use debugsetparents on
40 parent". The only known workaround is to use debugsetparents on
41 the broken clone to reset it to a changeset that still exists.
41 the broken clone to reset it to a changeset that still exists.
42 """
42 """
43
43
44 return hg.share(ui, source, dest, not noupdate, bookmarks)
44 return hg.share(ui, source, dest, not noupdate, bookmarks)
45
45
46 @command('unshare', [], '')
46 @command('unshare', [], '')
47 def unshare(ui, repo):
47 def unshare(ui, repo):
48 """convert a shared repository to a normal one
48 """convert a shared repository to a normal one
49
49
50 Copy the store data to the repo and remove the sharedpath data.
50 Copy the store data to the repo and remove the sharedpath data.
51 """
51 """
52
52
53 if not repo.shared():
53 if not repo.shared():
54 raise util.Abort(_("this is not a shared repo"))
54 raise util.Abort(_("this is not a shared repo"))
55
55
56 destlock = lock = None
56 destlock = lock = None
57 lock = repo.lock()
57 lock = repo.lock()
58 try:
58 try:
59 # we use locks here because if we race with commit, we
59 # we use locks here because if we race with commit, we
60 # can end up with extra data in the cloned revlogs that's
60 # can end up with extra data in the cloned revlogs that's
61 # not pointed to by changesets, thus causing verify to
61 # not pointed to by changesets, thus causing verify to
62 # fail
62 # fail
63
63
64 destlock = hg.copystore(ui, repo, repo.path)
64 destlock = hg.copystore(ui, repo, repo.path)
65
65
66 sharefile = repo.join('sharedpath')
66 sharefile = repo.join('sharedpath')
67 util.rename(sharefile, sharefile + '.old')
67 util.rename(sharefile, sharefile + '.old')
68
68
69 repo.requirements.discard('sharedpath')
69 repo.requirements.discard('sharedpath')
70 repo._writerequirements()
70 repo._writerequirements()
71 finally:
71 finally:
72 destlock and destlock.release()
72 destlock and destlock.release()
73 lock and lock.release()
73 lock and lock.release()
74
74
75 # update store, spath, sopener and sjoin of repo
75 # update store, spath, svfs and sjoin of repo
76 repo.unfiltered().__init__(repo.baseui, repo.root)
76 repo.unfiltered().__init__(repo.baseui, repo.root)
77
77
78 def extsetup(ui):
78 def extsetup(ui):
79 extensions.wrapfunction(bookmarks.bmstore, 'getbkfile', getbkfile)
79 extensions.wrapfunction(bookmarks.bmstore, 'getbkfile', getbkfile)
80 extensions.wrapfunction(bookmarks.bmstore, 'recordchange', recordchange)
80 extensions.wrapfunction(bookmarks.bmstore, 'recordchange', recordchange)
81 extensions.wrapfunction(bookmarks.bmstore, 'write', write)
81 extensions.wrapfunction(bookmarks.bmstore, 'write', write)
82
82
83 def _hassharedbookmarks(repo):
83 def _hassharedbookmarks(repo):
84 """Returns whether this repo has shared bookmarks"""
84 """Returns whether this repo has shared bookmarks"""
85 try:
85 try:
86 shared = repo.vfs.read('shared').splitlines()
86 shared = repo.vfs.read('shared').splitlines()
87 except IOError as inst:
87 except IOError as inst:
88 if inst.errno != errno.ENOENT:
88 if inst.errno != errno.ENOENT:
89 raise
89 raise
90 return False
90 return False
91 return 'bookmarks' in shared
91 return 'bookmarks' in shared
92
92
93 def _getsrcrepo(repo):
93 def _getsrcrepo(repo):
94 """
94 """
95 Returns the source repository object for a given shared repository.
95 Returns the source repository object for a given shared repository.
96 If repo is not a shared repository, return None.
96 If repo is not a shared repository, return None.
97 """
97 """
98 if repo.sharedpath == repo.path:
98 if repo.sharedpath == repo.path:
99 return None
99 return None
100
100
101 # the sharedpath always ends in the .hg; we want the path to the repo
101 # the sharedpath always ends in the .hg; we want the path to the repo
102 source = repo.vfs.split(repo.sharedpath)[0]
102 source = repo.vfs.split(repo.sharedpath)[0]
103 srcurl, branches = parseurl(source)
103 srcurl, branches = parseurl(source)
104 return repository(repo.ui, srcurl)
104 return repository(repo.ui, srcurl)
105
105
106 def getbkfile(orig, self, repo):
106 def getbkfile(orig, self, repo):
107 if _hassharedbookmarks(repo):
107 if _hassharedbookmarks(repo):
108 srcrepo = _getsrcrepo(repo)
108 srcrepo = _getsrcrepo(repo)
109 if srcrepo is not None:
109 if srcrepo is not None:
110 repo = srcrepo
110 repo = srcrepo
111 return orig(self, repo)
111 return orig(self, repo)
112
112
113 def recordchange(orig, self, tr):
113 def recordchange(orig, self, tr):
114 # Continue with write to local bookmarks file as usual
114 # Continue with write to local bookmarks file as usual
115 orig(self, tr)
115 orig(self, tr)
116
116
117 if _hassharedbookmarks(self._repo):
117 if _hassharedbookmarks(self._repo):
118 srcrepo = _getsrcrepo(self._repo)
118 srcrepo = _getsrcrepo(self._repo)
119 if srcrepo is not None:
119 if srcrepo is not None:
120 category = 'share-bookmarks'
120 category = 'share-bookmarks'
121 tr.addpostclose(category, lambda tr: self._writerepo(srcrepo))
121 tr.addpostclose(category, lambda tr: self._writerepo(srcrepo))
122
122
123 def write(orig, self):
123 def write(orig, self):
124 # First write local bookmarks file in case we ever unshare
124 # First write local bookmarks file in case we ever unshare
125 orig(self)
125 orig(self)
126 if _hassharedbookmarks(self._repo):
126 if _hassharedbookmarks(self._repo):
127 srcrepo = _getsrcrepo(self._repo)
127 srcrepo = _getsrcrepo(self._repo)
128 if srcrepo is not None:
128 if srcrepo is not None:
129 self._writerepo(srcrepo)
129 self._writerepo(srcrepo)
General Comments 0
You need to be logged in to leave comments. Login now