##// END OF EJS Templates
share: unmark --relative as EXPERIMENTAL...
Pulkit Goyal -
r43564:6a8c166a default
parent child Browse files
Show More
@@ -1,208 +1,203 b''
1 1 # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com>
2 2 #
3 3 # This software may be used and distributed according to the terms of the
4 4 # GNU General Public License version 2 or any later version.
5 5
6 6 '''share a common history between several working directories
7 7
8 8 Automatic Pooled Storage for Clones
9 9 -----------------------------------
10 10
11 11 When this extension is active, :hg:`clone` can be configured to
12 12 automatically share/pool storage across multiple clones. This
13 13 mode effectively converts :hg:`clone` to :hg:`clone` + :hg:`share`.
14 14 The benefit of using this mode is the automatic management of
15 15 store paths and intelligent pooling of related repositories.
16 16
17 17 The following ``share.`` config options influence this feature:
18 18
19 19 ``share.pool``
20 20 Filesystem path where shared repository data will be stored. When
21 21 defined, :hg:`clone` will automatically use shared repository
22 22 storage instead of creating a store inside each clone.
23 23
24 24 ``share.poolnaming``
25 25 How directory names in ``share.pool`` are constructed.
26 26
27 27 "identity" means the name is derived from the first changeset in the
28 28 repository. In this mode, different remotes share storage if their
29 29 root/initial changeset is identical. In this mode, the local shared
30 30 repository is an aggregate of all encountered remote repositories.
31 31
32 32 "remote" means the name is derived from the source repository's
33 33 path or URL. In this mode, storage is only shared if the path or URL
34 34 requested in the :hg:`clone` command matches exactly to a repository
35 35 that was cloned before.
36 36
37 37 The default naming mode is "identity".
38 38 '''
39 39
40 40 from __future__ import absolute_import
41 41
42 42 import errno
43 43 from mercurial.i18n import _
44 44 from mercurial import (
45 45 bookmarks,
46 46 commands,
47 47 error,
48 48 extensions,
49 49 hg,
50 50 registrar,
51 51 txnutil,
52 52 util,
53 53 )
54 54
55 55 cmdtable = {}
56 56 command = registrar.command(cmdtable)
57 57 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
58 58 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
59 59 # be specifying the version(s) of Mercurial they are tested with, or
60 60 # leave the attribute unspecified.
61 61 testedwith = b'ships-with-hg-core'
62 62
63 63
64 64 @command(
65 65 b'share',
66 66 [
67 67 (b'U', b'noupdate', None, _(b'do not create a working directory')),
68 68 (b'B', b'bookmarks', None, _(b'also share bookmarks')),
69 (
70 b'',
71 b'relative',
72 None,
73 _(b'point to source using a relative path (EXPERIMENTAL)'),
74 ),
69 (b'', b'relative', None, _(b'point to source using a relative path'),),
75 70 ],
76 71 _(b'[-U] [-B] SOURCE [DEST]'),
77 72 helpcategory=command.CATEGORY_REPO_CREATION,
78 73 norepo=True,
79 74 )
80 75 def share(
81 76 ui, source, dest=None, noupdate=False, bookmarks=False, relative=False
82 77 ):
83 78 """create a new shared repository
84 79
85 80 Initialize a new repository and working directory that shares its
86 81 history (and optionally bookmarks) with another repository.
87 82
88 83 .. note::
89 84
90 85 using rollback or extensions that destroy/modify history (mq,
91 86 rebase, etc.) can cause considerable confusion with shared
92 87 clones. In particular, if two shared clones are both updated to
93 88 the same changeset, and one of them destroys that changeset
94 89 with rollback, the other clone will suddenly stop working: all
95 90 operations will fail with "abort: working directory has unknown
96 91 parent". The only known workaround is to use debugsetparents on
97 92 the broken clone to reset it to a changeset that still exists.
98 93 """
99 94
100 95 hg.share(
101 96 ui,
102 97 source,
103 98 dest=dest,
104 99 update=not noupdate,
105 100 bookmarks=bookmarks,
106 101 relative=relative,
107 102 )
108 103 return 0
109 104
110 105
111 106 @command(b'unshare', [], b'', helpcategory=command.CATEGORY_MAINTENANCE)
112 107 def unshare(ui, repo):
113 108 """convert a shared repository to a normal one
114 109
115 110 Copy the store data to the repo and remove the sharedpath data.
116 111 """
117 112
118 113 if not repo.shared():
119 114 raise error.Abort(_(b"this is not a shared repo"))
120 115
121 116 hg.unshare(ui, repo)
122 117
123 118
124 119 # Wrap clone command to pass auto share options.
125 120 def clone(orig, ui, source, *args, **opts):
126 121 pool = ui.config(b'share', b'pool')
127 122 if pool:
128 123 pool = util.expandpath(pool)
129 124
130 125 opts[r'shareopts'] = {
131 126 b'pool': pool,
132 127 b'mode': ui.config(b'share', b'poolnaming'),
133 128 }
134 129
135 130 return orig(ui, source, *args, **opts)
136 131
137 132
138 133 def extsetup(ui):
139 134 extensions.wrapfunction(bookmarks, b'_getbkfile', getbkfile)
140 135 extensions.wrapfunction(bookmarks.bmstore, b'_recordchange', recordchange)
141 136 extensions.wrapfunction(bookmarks.bmstore, b'_writerepo', writerepo)
142 137 extensions.wrapcommand(commands.table, b'clone', clone)
143 138
144 139
145 140 def _hassharedbookmarks(repo):
146 141 """Returns whether this repo has shared bookmarks"""
147 142 if bookmarks.bookmarksinstore(repo):
148 143 # Kind of a lie, but it means that we skip our custom reads and writes
149 144 # from/to the source repo.
150 145 return False
151 146 try:
152 147 shared = repo.vfs.read(b'shared').splitlines()
153 148 except IOError as inst:
154 149 if inst.errno != errno.ENOENT:
155 150 raise
156 151 return False
157 152 return hg.sharedbookmarks in shared
158 153
159 154
160 155 def getbkfile(orig, repo):
161 156 if _hassharedbookmarks(repo):
162 157 srcrepo = hg.sharedreposource(repo)
163 158 if srcrepo is not None:
164 159 # just orig(srcrepo) doesn't work as expected, because
165 160 # HG_PENDING refers repo.root.
166 161 try:
167 162 fp, pending = txnutil.trypending(
168 163 repo.root, repo.vfs, b'bookmarks'
169 164 )
170 165 if pending:
171 166 # only in this case, bookmark information in repo
172 167 # is up-to-date.
173 168 return fp
174 169 fp.close()
175 170 except IOError as inst:
176 171 if inst.errno != errno.ENOENT:
177 172 raise
178 173
179 174 # otherwise, we should read bookmarks from srcrepo,
180 175 # because .hg/bookmarks in srcrepo might be already
181 176 # changed via another sharing repo
182 177 repo = srcrepo
183 178
184 179 # TODO: Pending changes in repo are still invisible in
185 180 # srcrepo, because bookmarks.pending is written only into repo.
186 181 # See also https://www.mercurial-scm.org/wiki/SharedRepository
187 182 return orig(repo)
188 183
189 184
190 185 def recordchange(orig, self, tr):
191 186 # Continue with write to local bookmarks file as usual
192 187 orig(self, tr)
193 188
194 189 if _hassharedbookmarks(self._repo):
195 190 srcrepo = hg.sharedreposource(self._repo)
196 191 if srcrepo is not None:
197 192 category = b'share-bookmarks'
198 193 tr.addpostclose(category, lambda tr: self._writerepo(srcrepo))
199 194
200 195
201 196 def writerepo(orig, self, repo):
202 197 # First write local bookmarks file in case we ever unshare
203 198 orig(self, repo)
204 199
205 200 if _hassharedbookmarks(self._repo):
206 201 srcrepo = hg.sharedreposource(self._repo)
207 202 if srcrepo is not None:
208 203 orig(self, srcrepo)
General Comments 0
You need to be logged in to leave comments. Login now