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