Reasoning is same as previous patch which adds automatic upgrade support.
Downgrade is required as if automatic upgrade is enabled, all shares upgrade and
then source repository downgrades, shares won't work. We need to downgrade them.
marmoute | |
Alphare |
hg-reviewers |
Reasoning is same as previous patch which adds automatic upgrade support.
Downgrade is required as if automatic upgrade is enabled, all shares upgrade and
then source repository downgrades, shares won't work. We need to downgrade them.
No Linters Available |
No Unit Test Coverage |
In D9680#146569, @marmoute wrote:(I assume the same feedback apply there)
Yes, incorporated those already.
Path | Packages | |||
---|---|---|---|---|
M | mercurial/configitems.py (5 lines) | |||
M | mercurial/localrepo.py (34 lines) | |||
M | mercurial/scmutil.py (17 lines) | |||
M | tests/test-share-safe.t (14 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
3a8ee8016537 | 98a050e6b5b1 | Pulkit Goyal | Jan 6 2021, 8:01 AM |
) | ) | ||||
coreconfigitem( | coreconfigitem( | ||||
b'experimental', | b'experimental', | ||||
b'server.stream-narrow-clones', | b'server.stream-narrow-clones', | ||||
default=False, | default=False, | ||||
) | ) | ||||
coreconfigitem( | coreconfigitem( | ||||
b'experimental', | b'experimental', | ||||
b'sharesafe-auto-downgrade-shares', | |||||
default=False, | |||||
) | |||||
coreconfigitem( | |||||
b'experimental', | |||||
b'sharesafe-auto-upgrade-shares', | b'sharesafe-auto-upgrade-shares', | ||||
default=False, | default=False, | ||||
) | ) | ||||
coreconfigitem( | coreconfigitem( | ||||
b'experimental', | b'experimental', | ||||
b'single-head-per-branch', | b'single-head-per-branch', | ||||
default=False, | default=False, | ||||
) | ) |
# to be reshared | # to be reshared | ||||
if requirementsmod.SHARESAFE_REQUIREMENT in requirements: | if requirementsmod.SHARESAFE_REQUIREMENT in requirements: | ||||
if ( | if ( | ||||
shared | shared | ||||
and requirementsmod.SHARESAFE_REQUIREMENT | and requirementsmod.SHARESAFE_REQUIREMENT | ||||
not in _readrequires(sharedvfs, True) | not in _readrequires(sharedvfs, True) | ||||
): | ): | ||||
if ui.configbool( | |||||
b'experimental', b'sharesafe-auto-downgrade-shares' | |||||
): | |||||
sourcerequires = _readrequires(sharedvfs, True) | |||||
wlock = None | |||||
try: | |||||
wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0) | |||||
requirements = scmutil.downgrade_share_to_non_safe( | |||||
hgvfs, requirements, sourcerequires | |||||
) | |||||
ui.warn( | |||||
_(b'repository downgraded to not use share-safe mode\n') | |||||
) | |||||
except Exception as e: | |||||
ui.warn( | |||||
_(b'failed to downgrade share, got error: %s') | |||||
% stringutil.forcebytestr(e) | |||||
) | |||||
finally: | |||||
if wlock: | |||||
wlock.release() | |||||
else: | |||||
raise error.Abort( | raise error.Abort( | ||||
_(b"share source does not support exp-sharesafe requirement") | _( | ||||
b"share source does not support exp-sharesafe requirement" | |||||
) | ) | ||||
) | |||||
else: | |||||
requirements |= _readrequires(storevfs, False) | requirements |= _readrequires(storevfs, False) | ||||
elif shared: | elif shared: | ||||
sourcerequires = _readrequires(sharedvfs, False) | sourcerequires = _readrequires(sharedvfs, False) | ||||
if requirementsmod.SHARESAFE_REQUIREMENT in sourcerequires: | if requirementsmod.SHARESAFE_REQUIREMENT in sourcerequires: | ||||
if ui.configbool(b'experimental', b'sharesafe-auto-upgrade-shares'): | if ui.configbool(b'experimental', b'sharesafe-auto-upgrade-shares'): | ||||
storerequires = _readrequires(storevfs, False) | storerequires = _readrequires(storevfs, False) | ||||
wlock = None | wlock = None | ||||
try: | try: | ||||
wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0) | wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0) |
diffrequires = current_requirements - store_requirements | diffrequires = current_requirements - store_requirements | ||||
# add share-safe requirement as it will mark the share as share-safe | # add share-safe requirement as it will mark the share as share-safe | ||||
diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT) | diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT) | ||||
writerequires(hgvfs, diffrequires) | writerequires(hgvfs, diffrequires) | ||||
current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT) | current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT) | ||||
return current_requirements | return current_requirements | ||||
def downgrade_share_to_non_safe( | |||||
hgvfs, current_requirements, source_requirements | |||||
): | |||||
"""Downgrades a share which use share-safe to not use it | |||||
Returns the set of new repository requirements | |||||
""" | |||||
# we cannot be 100% sure on which requirements were present in store when | |||||
# the source supported share-safe. However, we do know that working | |||||
# directory requirements were not there. Hence we remove them | |||||
source_requirements -= requirementsmod.WORKING_DIR_REQUIREMENTS | |||||
current_requirements |= source_requirements | |||||
current_requirements.remove(requirementsmod.SHARESAFE_REQUIREMENT) | |||||
writerequires(hgvfs, current_requirements) | |||||
return current_requirements | |||||
class filecachesubentry(object): | class filecachesubentry(object): | ||||
def __init__(self, path, stat): | def __init__(self, path, stat): | ||||
self.path = path | self.path = path | ||||
self.cachestat = None | self.cachestat = None | ||||
self._cacheable = None | self._cacheable = None | ||||
if stat: | if stat: | ||||
self.cachestat = filecachesubentry.stat(self.path) | self.cachestat = filecachesubentry.stat(self.path) |
| | | | ||||
o f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo | o f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo | ||||
$ hg log -GT "{node}: {desc}\n" -R ../ss-share | $ hg log -GT "{node}: {desc}\n" -R ../ss-share | ||||
abort: share source does not support exp-sharesafe requirement | abort: share source does not support exp-sharesafe requirement | ||||
[255] | [255] | ||||
Testing automatic downgrade of shares when config is set | |||||
$ hg log -GT "{node}: {desc}\n" -R ../ss-share --config experimental.sharesafe-auto-downgrade-shares=true | |||||
repository downgraded to not use share-safe mode | |||||
@ f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar | |||||
| | |||||
o f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo | |||||
$ hg log -GT "{node}: {desc}\n" -R ../ss-share | |||||
@ f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar | |||||
| | |||||
o f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo | |||||
Testing automatic upgrade of shares when config is set | Testing automatic upgrade of shares when config is set | ||||
$ hg debugupgraderepo -q --run --config format.exp-share-safe=True | $ hg debugupgraderepo -q --run --config format.exp-share-safe=True | ||||
upgrade will perform the following actions: | upgrade will perform the following actions: | ||||
requirements | requirements | ||||
preserved: dotencode, fncache, generaldelta, revlogv1, sparserevlog, store | preserved: dotencode, fncache, generaldelta, revlogv1, sparserevlog, store |