[PATCH 04 of 10] repair: identify repository deficiencies
Gregory Szorc
gregory.szorc at gmail.com
Tue Nov 22 06:02:38 UTC 2016
On Mon, Nov 21, 2016 at 6:14 PM, Pierre-Yves David <
pierre-yves.david at ens-lyon.org> wrote:
> On 11/06/2016 05:40 AM, Gregory Szorc wrote:
>
>> # HG changeset patch
>> # User Gregory Szorc <gregory.szorc at gmail.com>
>> # Date 1478382332 25200
>> # Sat Nov 05 14:45:32 2016 -0700
>> # Node ID 7518e68e2f8276e85fb68174b3055a9dd16c665d
>> # Parent 9daec9c7adabe8c84cf2c01fc938e010ee4884d6
>> repair: identify repository deficiencies
>>
>> A command that upgrades repositories but doesn't say what it is doing
>> or why it is doing it is less helpful than a command that does. So,
>> we start the implementation of repository upgrades by introducing
>> detection of sub-optimal repository state. Deficiencies with the
>> existing repository are now printed at the beginning of command
>> execution.
>>
>> The added function returns a set of planned upgrade actions. This
>> variable will be used by subsequent patches.
>>
>> diff --git a/mercurial/commands.py b/mercurial/commands.py
>> --- a/mercurial/commands.py
>> +++ b/mercurial/commands.py
>> @@ -3756,7 +3756,7 @@ def debugupgraderepo(ui, repo, **opts):
>>
>> At times during the upgrade, the repository may not be readable.
>> """
>> - raise error.Abort(_('not yet implemented'))
>> + return repair.upgraderepo(ui, repo, dryrun=opts.get('dry_run'))
>>
>> @command('debugwalk', walkopts, _('[OPTION]... [FILE]...'),
>> inferrepo=True)
>> def debugwalk(ui, repo, *pats, **opts):
>> diff --git a/mercurial/repair.py b/mercurial/repair.py
>> --- a/mercurial/repair.py
>> +++ b/mercurial/repair.py
>> @@ -360,3 +360,57 @@ def deleteobsmarkers(obsstore, indices):
>> newobsstorefile.write(bytes)
>> newobsstorefile.close()
>> return n
>> +
>> +def upgradefinddeficiencies(repo):
>> + """Obtain deficiencies with the existing repo and planned actions to
>> fix.
>> +
>> + Returns a list of strings that will be printed to the user and a set
>> + of machine-readable actions that will be acted on later.
>> + """
>> + l = []
>> + actions = set()
>> +
>> + # We could detect lack of revlogv1 and store here, but they were
>> added
>> + # in 0.9.2 and we don't support upgrading repos without these
>> + # requirements, so let's not bother.
>> +
>> + if 'fncache' not in repo.requirements:
>> + l.append(_('not using fncache; long and reserved filenames '
>> + 'may not work correctly'))
>>
>
>
> notes: I like the idea of explaining the benefit of each upgrade.
>
> + actions.add('fncache')
>> +
>> + if 'dotencode' not in repo.requirements:
>> + l.append(_('not using dotencode; filenames beginning with '
>> + 'a period or space may not work correctly'))
>> + actions.add('dotencode')
>> +
>> + if 'generaldelta' not in repo.requirements:
>> + l.append(_('not using generaldelta storage; repository is larger
>> '
>> + 'and slower than it could be, pulling from '
>> + 'generaldelta repositories will be slow'))
>> + actions.add('generaldelta')
>> +
>> + cl = repo.changelog
>> + for rev in cl:
>> + chainbase = cl.chainbase(rev)
>> + if chainbase != rev:
>> + l.append(_('changelog using delta chains; changelog reading '
>> + 'is slower than it could be'))
>> + actions.add('removecldeltachain')
>> + break
>> +
>> + return l, actions
>>
>
> At some point we probably needs this to be extensible for extension to be
> able to extend the list of format variant detection. But this can come
> later.
>
I kinda bent over backwards in this series to isolate each step to its own
function explicitly so extensions could inject code at the appropriate
point. I'm not too worried about this not being extensible :)
> This version if performing unconditional upgrade of all features. Will be
> quite unhandy in some case (eg: cohabitation with older versions,
> experimental format, etc). The approach have been using on my side was to
> use three points of data for each variants:
>
> * current format, default format, configured format.
>
> Then, 'hg debugformat' would highlight case were 'current' ≠ 'config' and
> 'config' ≠ 'default'. A `hg debugformat --upgrade` would always move a
> variant from 'current' to 'config'.
>
I *really* like being able to distinguish between these states. I'll try to
find a way to work this into v2.
>
> +def upgraderepo(ui, repo, dryrun=False):
>> + """Upgrade a repository in place."""
>> + repo = repo.unfiltered()
>> + deficiencies, actions = upgradefinddeficiencies(repo)
>> +
>> + if deficiencies:
>> + ui.write(_('the following deficiencies with the existing
>> repository '
>> + 'have been identified:\n\n'))
>> +
>> + for d in deficiencies:
>> + ui.write('* %s\n' % d)
>> + else:
>> + ui.write(_('no obvious deficiencies found in existing
>> repository\n'))
>> diff --git a/tests/test-upgrade-repo.t b/tests/test-upgrade-repo.t
>> --- a/tests/test-upgrade-repo.t
>> +++ b/tests/test-upgrade-repo.t
>> @@ -1,5 +1,18 @@
>> $ hg init empty
>> $ cd empty
>> $ hg debugupgraderepo
>> - abort: not yet implemented
>> - [255]
>> + no obvious deficiencies found in existing repository
>> +
>> +Various sub-optimal detections work
>> +
>> + $ cat > .hg/requires << EOF
>> + > revlogv1
>> + > store
>> + > EOF
>> +
>> + $ hg debugupgraderepo
>> + the following deficiencies with the existing repository have been
>> identified:
>> +
>> + * not using fncache; long and reserved filenames may not work correctly
>> + * not using dotencode; filenames beginning with a period or space may
>> not work correctly
>> + * not using generaldelta storage; repository is larger and slower than
>> it could be, pulling from generaldelta repositories will be slow
>> _______________________________________________
>> Mercurial-devel mailing list
>> Mercurial-devel at mercurial-scm.org
>> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>>
>>
> --
> Pierre-Yves David
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-devel/attachments/20161121/6f1fbbca/attachment-0002.html>
More information about the Mercurial-devel
mailing list