Mercurial > hg
comparison mercurial/hg.py @ 39849:d3d4b4b5f725
localrepo: support writing shared file (API)
Now that we can create a shared repository via creation options, we
can handle other special actions related to share at repo creation time
as well.
One of the things we do after creating a shared repository is write
out a .hg/shared file containing the list of additional things to
share. Of which only "bookmarks" is supported.
We add a creation option to hold the set of additional items to
share. If items are defined, we write out the .hg/shared file at
repo creation time.
As part of this, we no longer hold the repo lock when writing the
file. I'm pretty sure we don't care about the tiny race condition
window. I'm also pretty sure the reason we used the lock was because
the vfs auditor on the repo instance complained otherwise. Since the
repo creation code doesn't have an audited vfs, we don't need to
appease it.
Because we no longer need to tell the post share hook what items
are shared, the "bookmarks" argument to that function has been
dropped, incurring an API change.
Differential Revision: https://phab.mercurial-scm.org/D4708
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 19 Sep 2018 17:27:37 -0700 |
parents | 4ece3cdfd907 |
children | 6637b079ae45 |
comparison
equal
deleted
inserted
replaced
39848:4ece3cdfd907 | 39849:d3d4b4b5f725 |
---|---|
257 rev, checkout = addbranchrevs(srcrepo, srcrepo, branches, None) | 257 rev, checkout = addbranchrevs(srcrepo, srcrepo, branches, None) |
258 else: | 258 else: |
259 srcrepo = source.local() | 259 srcrepo = source.local() |
260 checkout = None | 260 checkout = None |
261 | 261 |
262 shareditems = set() | |
263 if bookmarks: | |
264 shareditems.add(sharedbookmarks) | |
265 | |
262 r = repository(ui, dest, create=True, createopts={ | 266 r = repository(ui, dest, create=True, createopts={ |
263 'sharedrepo': srcrepo, | 267 'sharedrepo': srcrepo, |
264 'sharedrelative': relative, | 268 'sharedrelative': relative, |
269 'shareditems': shareditems, | |
265 }) | 270 }) |
266 | 271 |
267 postshare(srcrepo, r, bookmarks=bookmarks, defaultpath=defaultpath) | 272 postshare(srcrepo, r, defaultpath=defaultpath) |
268 _postshareupdate(r, update, checkout=checkout) | 273 _postshareupdate(r, update, checkout=checkout) |
269 return r | 274 return r |
270 | 275 |
271 def unshare(ui, repo): | 276 def unshare(ui, repo): |
272 """convert a shared repository to a normal one | 277 """convert a shared repository to a normal one |
313 | 318 |
314 localrepo.poisonrepository(repo) | 319 localrepo.poisonrepository(repo) |
315 | 320 |
316 return newrepo | 321 return newrepo |
317 | 322 |
318 def postshare(sourcerepo, destrepo, bookmarks=True, defaultpath=None): | 323 def postshare(sourcerepo, destrepo, defaultpath=None): |
319 """Called after a new shared repo is created. | 324 """Called after a new shared repo is created. |
320 | 325 |
321 The new repo only has a requirements file and pointer to the source. | 326 The new repo only has a requirements file and pointer to the source. |
322 This function configures additional shared data. | 327 This function configures additional shared data. |
323 | 328 |
327 default = defaultpath or sourcerepo.ui.config('paths', 'default') | 332 default = defaultpath or sourcerepo.ui.config('paths', 'default') |
328 if default: | 333 if default: |
329 template = ('[paths]\n' | 334 template = ('[paths]\n' |
330 'default = %s\n') | 335 'default = %s\n') |
331 destrepo.vfs.write('hgrc', util.tonativeeol(template % default)) | 336 destrepo.vfs.write('hgrc', util.tonativeeol(template % default)) |
332 | |
333 with destrepo.wlock(): | |
334 if bookmarks: | |
335 destrepo.vfs.write('shared', sharedbookmarks + '\n') | |
336 | 337 |
337 def _postshareupdate(repo, update, checkout=None): | 338 def _postshareupdate(repo, update, checkout=None): |
338 """Maybe perform a working directory update after a shared repo is created. | 339 """Maybe perform a working directory update after a shared repo is created. |
339 | 340 |
340 ``update`` can be a boolean or a revision to update to. | 341 ``update`` can be a boolean or a revision to update to. |