Show More
@@ -6,7 +6,9 b'' | |||||
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 |
|
9 | from mercurial import cmdutil, hg, util, extensions, bookmarks | |
|
10 | from mercurial.hg import repository, parseurl | |||
|
11 | import errno | |||
10 |
|
12 | |||
11 | cmdtable = {} |
|
13 | cmdtable = {} | |
12 | command = cmdutil.command(cmdtable) |
|
14 | command = cmdutil.command(cmdtable) | |
@@ -67,3 +69,61 b' def unshare(ui, repo):' | |||||
67 |
|
69 | |||
68 | # update store, spath, sopener and sjoin of repo |
|
70 | # update store, spath, sopener and sjoin of repo | |
69 | repo.unfiltered().__init__(repo.baseui, repo.root) |
|
71 | repo.unfiltered().__init__(repo.baseui, repo.root) | |
|
72 | ||||
|
73 | def extsetup(ui): | |||
|
74 | extensions.wrapfunction(bookmarks.bmstore, 'getbkfile', getbkfile) | |||
|
75 | extensions.wrapfunction(bookmarks.bmstore, 'recordchange', recordchange) | |||
|
76 | extensions.wrapfunction(bookmarks.bmstore, 'write', write) | |||
|
77 | ||||
|
78 | def _hassharedbookmarks(repo): | |||
|
79 | """Returns whether this repo has shared bookmarks""" | |||
|
80 | try: | |||
|
81 | repo.vfs.read('bookmarks.shared') | |||
|
82 | return True | |||
|
83 | except IOError, inst: | |||
|
84 | if inst.errno != errno.ENOENT: | |||
|
85 | raise | |||
|
86 | return False | |||
|
87 | ||||
|
88 | def _getsrcrepo(repo): | |||
|
89 | """ | |||
|
90 | Returns the source repository object for a given shared repository. | |||
|
91 | If repo is not a shared repository, return None. | |||
|
92 | """ | |||
|
93 | srcrepo = None | |||
|
94 | try: | |||
|
95 | # strip because some tools write with newline after | |||
|
96 | sharedpath = repo.vfs.read('sharedpath').strip() | |||
|
97 | # the sharedpath always ends in the .hg; we want the path to the repo | |||
|
98 | source = sharedpath.rsplit('/.hg', 1)[0] | |||
|
99 | srcurl, branches = parseurl(source) | |||
|
100 | srcrepo = repository(repo.ui, srcurl) | |||
|
101 | except IOError, inst: | |||
|
102 | if inst.errno != errno.ENOENT: | |||
|
103 | raise | |||
|
104 | return srcrepo | |||
|
105 | ||||
|
106 | def getbkfile(orig, self, repo): | |||
|
107 | if _hassharedbookmarks(repo): | |||
|
108 | srcrepo = _getsrcrepo(repo) | |||
|
109 | if srcrepo is not None: | |||
|
110 | repo = srcrepo | |||
|
111 | return orig(self, repo) | |||
|
112 | ||||
|
113 | def recordchange(orig, self, tr): | |||
|
114 | # Continue with write to local bookmarks file as usual | |||
|
115 | orig(self, tr) | |||
|
116 | ||||
|
117 | if _hassharedbookmarks(self._repo): | |||
|
118 | srcrepo = _getsrcrepo(self._repo) | |||
|
119 | if srcrepo is not None: | |||
|
120 | category = 'share-bookmarks' | |||
|
121 | tr.addpostclose(category, lambda tr: self._writerepo(srcrepo)) | |||
|
122 | ||||
|
123 | def write(orig, self): | |||
|
124 | # First write local bookmarks file in case we ever unshare | |||
|
125 | orig(self) | |||
|
126 | if _hassharedbookmarks(self._repo): | |||
|
127 | srcrepo = _getsrcrepo(self._repo) | |||
|
128 | if srcrepo is not None: | |||
|
129 | self._writerepo(srcrepo) |
@@ -128,6 +128,175 b' check that a change does not propagate' | |||||
128 |
|
128 | |||
129 | $ cd .. |
|
129 | $ cd .. | |
130 |
|
130 | |||
|
131 | ||||
|
132 | test sharing bookmarks (manually add bookmarks.shared file for now) | |||
|
133 | ||||
|
134 | $ hg share repo1 repo3 && touch repo3/.hg/bookmarks.shared | |||
|
135 | updating working directory | |||
|
136 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |||
|
137 | $ cd repo1 | |||
|
138 | $ hg bookmark bm1 | |||
|
139 | $ hg bookmarks | |||
|
140 | * bm1 2:c2e0ac586386 | |||
|
141 | $ cd ../repo2 | |||
|
142 | $ hg book bm2 | |||
|
143 | $ hg bookmarks | |||
|
144 | * bm2 3:0e6e70d1d5f1 | |||
|
145 | $ cd ../repo3 | |||
|
146 | $ hg bookmarks | |||
|
147 | bm1 2:c2e0ac586386 | |||
|
148 | $ hg book bm3 | |||
|
149 | $ hg bookmarks | |||
|
150 | bm1 2:c2e0ac586386 | |||
|
151 | * bm3 2:c2e0ac586386 | |||
|
152 | $ cd ../repo1 | |||
|
153 | $ hg bookmarks | |||
|
154 | * bm1 2:c2e0ac586386 | |||
|
155 | bm3 2:c2e0ac586386 | |||
|
156 | ||||
|
157 | test that commits work | |||
|
158 | ||||
|
159 | $ echo 'shared bookmarks' > a | |||
|
160 | $ hg commit -m 'testing shared bookmarks' | |||
|
161 | $ hg bookmarks | |||
|
162 | * bm1 3:b87954705719 | |||
|
163 | bm3 2:c2e0ac586386 | |||
|
164 | $ cd ../repo3 | |||
|
165 | $ hg bookmarks | |||
|
166 | bm1 3:b87954705719 | |||
|
167 | * bm3 2:c2e0ac586386 | |||
|
168 | $ echo 'more shared bookmarks' > a | |||
|
169 | $ hg commit -m 'testing shared bookmarks' | |||
|
170 | created new head | |||
|
171 | $ hg bookmarks | |||
|
172 | bm1 3:b87954705719 | |||
|
173 | * bm3 4:62f4ded848e4 | |||
|
174 | $ cd ../repo1 | |||
|
175 | $ hg bookmarks | |||
|
176 | * bm1 3:b87954705719 | |||
|
177 | bm3 4:62f4ded848e4 | |||
|
178 | $ cd .. | |||
|
179 | ||||
|
180 | test pushing bookmarks works | |||
|
181 | ||||
|
182 | $ hg clone repo3 repo4 | |||
|
183 | updating to branch default | |||
|
184 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |||
|
185 | $ cd repo4 | |||
|
186 | $ hg boo bm4 | |||
|
187 | $ echo foo > b | |||
|
188 | $ hg commit -m 'foo in b' | |||
|
189 | $ hg boo | |||
|
190 | bm1 3:b87954705719 | |||
|
191 | bm3 4:62f4ded848e4 | |||
|
192 | * bm4 5:92793bfc8cad | |||
|
193 | $ hg push -B bm4 | |||
|
194 | pushing to $TESTTMP/repo3 (glob) | |||
|
195 | searching for changes | |||
|
196 | adding changesets | |||
|
197 | adding manifests | |||
|
198 | adding file changes | |||
|
199 | added 1 changesets with 1 changes to 1 files | |||
|
200 | exporting bookmark bm4 | |||
|
201 | $ cd ../repo1 | |||
|
202 | $ hg bookmarks | |||
|
203 | * bm1 3:b87954705719 | |||
|
204 | bm3 4:62f4ded848e4 | |||
|
205 | bm4 5:92793bfc8cad | |||
|
206 | $ cd ../repo3 | |||
|
207 | $ hg bookmarks | |||
|
208 | bm1 3:b87954705719 | |||
|
209 | * bm3 4:62f4ded848e4 | |||
|
210 | bm4 5:92793bfc8cad | |||
|
211 | $ cd .. | |||
|
212 | ||||
|
213 | test behavior when sharing a shared repo | |||
|
214 | ||||
|
215 | $ hg share repo3 repo5 && touch repo5/.hg/bookmarks.shared | |||
|
216 | updating working directory | |||
|
217 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |||
|
218 | $ cd repo5 | |||
|
219 | $ hg book | |||
|
220 | bm1 3:b87954705719 | |||
|
221 | bm3 4:62f4ded848e4 | |||
|
222 | bm4 5:92793bfc8cad | |||
|
223 | $ cd .. | |||
|
224 | ||||
|
225 | test what happens when an active bookmark is deleted | |||
|
226 | ||||
|
227 | $ cd repo1 | |||
|
228 | $ hg boo -d bm3 | |||
|
229 | $ hg boo | |||
|
230 | * bm1 3:b87954705719 | |||
|
231 | bm4 5:92793bfc8cad | |||
|
232 | $ cd ../repo3 | |||
|
233 | $ hg boo | |||
|
234 | bm1 3:b87954705719 | |||
|
235 | bm4 5:92793bfc8cad | |||
|
236 | $ cd .. | |||
|
237 | ||||
|
238 | verify that bookmarks are not written on failed transaction | |||
|
239 | ||||
|
240 | $ cat > failpullbookmarks.py << EOF | |||
|
241 | > """A small extension that makes bookmark pulls fail, for testing""" | |||
|
242 | > from mercurial import extensions, exchange, error | |||
|
243 | > def _pullbookmarks(orig, pullop): | |||
|
244 | > orig(pullop) | |||
|
245 | > raise error.HookAbort('forced failure by extension') | |||
|
246 | > def extsetup(ui): | |||
|
247 | > extensions.wrapfunction(exchange, '_pullbookmarks', _pullbookmarks) | |||
|
248 | > EOF | |||
|
249 | $ cd repo4 | |||
|
250 | $ hg boo | |||
|
251 | bm1 3:b87954705719 | |||
|
252 | bm3 4:62f4ded848e4 | |||
|
253 | * bm4 5:92793bfc8cad | |||
|
254 | $ cd ../repo3 | |||
|
255 | $ hg boo | |||
|
256 | bm1 3:b87954705719 | |||
|
257 | bm4 5:92793bfc8cad | |||
|
258 | $ hg --config "extensions.failpullbookmarks=$TESTTMP/failpullbookmarks.py" pull $TESTTMP/repo4 | |||
|
259 | pulling from $TESTTMP/repo4 (glob) | |||
|
260 | searching for changes | |||
|
261 | no changes found | |||
|
262 | adding remote bookmark bm3 | |||
|
263 | abort: forced failure by extension | |||
|
264 | [255] | |||
|
265 | $ hg boo | |||
|
266 | bm1 3:b87954705719 | |||
|
267 | bm4 5:92793bfc8cad | |||
|
268 | $ hg pull $TESTTMP/repo4 | |||
|
269 | pulling from $TESTTMP/repo4 (glob) | |||
|
270 | searching for changes | |||
|
271 | no changes found | |||
|
272 | adding remote bookmark bm3 | |||
|
273 | $ hg boo | |||
|
274 | bm1 3:b87954705719 | |||
|
275 | * bm3 4:62f4ded848e4 | |||
|
276 | bm4 5:92793bfc8cad | |||
|
277 | $ cd .. | |||
|
278 | ||||
|
279 | verify bookmark behavior after unshare | |||
|
280 | ||||
|
281 | $ cd repo3 | |||
|
282 | $ hg unshare | |||
|
283 | $ hg boo | |||
|
284 | bm1 3:b87954705719 | |||
|
285 | * bm3 4:62f4ded848e4 | |||
|
286 | bm4 5:92793bfc8cad | |||
|
287 | $ hg boo -d bm4 | |||
|
288 | $ hg boo bm5 | |||
|
289 | $ hg boo | |||
|
290 | bm1 3:b87954705719 | |||
|
291 | bm3 4:62f4ded848e4 | |||
|
292 | * bm5 4:62f4ded848e4 | |||
|
293 | $ cd ../repo1 | |||
|
294 | $ hg boo | |||
|
295 | * bm1 3:b87954705719 | |||
|
296 | bm3 4:62f4ded848e4 | |||
|
297 | bm4 5:92793bfc8cad | |||
|
298 | $ cd .. | |||
|
299 | ||||
131 | Explicitly kill daemons to let the test exit on Windows |
|
300 | Explicitly kill daemons to let the test exit on Windows | |
132 |
|
301 | |||
133 | $ "$TESTDIR/killdaemons.py" $DAEMON_PIDS |
|
302 | $ "$TESTDIR/killdaemons.py" $DAEMON_PIDS |
General Comments 0
You need to be logged in to leave comments.
Login now