Mercurial > public > mercurial-scm > hg
comparison mercurial/hg.py @ 45485:b71858b42963
localrepo: load the share source .hg/hgrc also in share-safe mode (API)
The second part of the Share Safe Plan is to share source repo config also.
This patch adds logic to load the source repo .hg/hgrc if we are in share safe
mode. On unshare, we copy and prepend source config to current repo so that
config which was shared is persisted.
A test is added to show that now if we enable a hook on the source repo, that
also runs on the shared repositories.
API change as a new optional argument sharedvfs added to localrepo.loadhgrc()
Differential Revision: https://phab.mercurial-scm.org/D8656
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Thu, 02 Jul 2020 16:23:36 +0530 |
parents | 034d94f8761b |
children | 03726f5b6092 |
comparison
equal
deleted
inserted
replaced
45484:63eb1b5c580d | 45485:b71858b42963 |
---|---|
330 r = repository(ui, dest) | 330 r = repository(ui, dest) |
331 _postshareupdate(r, update, checkout=checkout) | 331 _postshareupdate(r, update, checkout=checkout) |
332 return r | 332 return r |
333 | 333 |
334 | 334 |
335 def _prependsourcehgrc(repo): | |
336 """ copies the source repo config and prepend it in current repo .hg/hgrc | |
337 on unshare. This is only done if the share was perfomed using share safe | |
338 method where we share config of source in shares""" | |
339 srcvfs = vfsmod.vfs(repo.sharedpath) | |
340 dstvfs = vfsmod.vfs(repo.path) | |
341 | |
342 if not srcvfs.exists(b'hgrc'): | |
343 return | |
344 | |
345 currentconfig = b'' | |
346 if dstvfs.exists(b'hgrc'): | |
347 currentconfig = dstvfs.read(b'hgrc') | |
348 | |
349 with dstvfs(b'hgrc', b'wb') as fp: | |
350 sourceconfig = srcvfs.read(b'hgrc') | |
351 fp.write(b"# Config copied from shared source\n") | |
352 fp.write(sourceconfig) | |
353 fp.write(b'\n') | |
354 fp.write(currentconfig) | |
355 | |
356 | |
335 def unshare(ui, repo): | 357 def unshare(ui, repo): |
336 """convert a shared repository to a normal one | 358 """convert a shared repository to a normal one |
337 | 359 |
338 Copy the store data to the repo and remove the sharedpath data. | 360 Copy the store data to the repo and remove the sharedpath data. |
339 | 361 |
348 # can end up with extra data in the cloned revlogs that's | 370 # can end up with extra data in the cloned revlogs that's |
349 # not pointed to by changesets, thus causing verify to | 371 # not pointed to by changesets, thus causing verify to |
350 # fail | 372 # fail |
351 destlock = copystore(ui, repo, repo.path) | 373 destlock = copystore(ui, repo, repo.path) |
352 with destlock or util.nullcontextmanager(): | 374 with destlock or util.nullcontextmanager(): |
375 if requirements.SHARESAFE_REQUIREMENT in repo.requirements: | |
376 # we were sharing .hg/hgrc of the share source with the current | |
377 # repo. We need to copy that while unsharing otherwise it can | |
378 # disable hooks and other checks | |
379 _prependsourcehgrc(repo) | |
353 | 380 |
354 sharefile = repo.vfs.join(b'sharedpath') | 381 sharefile = repo.vfs.join(b'sharedpath') |
355 util.rename(sharefile, sharefile + b'.old') | 382 util.rename(sharefile, sharefile + b'.old') |
356 | 383 |
357 repo.requirements.discard(requirements.SHARED_REQUIREMENT) | 384 repo.requirements.discard(requirements.SHARED_REQUIREMENT) |