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