# HG changeset patch # User Gregory Szorc <gregory.sz...@gmail.com> # Date 1478393040 25200 # Sat Nov 05 17:44:00 2016 -0700 # Node ID 82799afa72be5bb540b2b07cd878f307622c4354 # Parent b768004ef2db9c2e6dd267997e9e0c011f1b732a repair: print what upgrade will do
The final part of pre-upgrade checks is validating what the upgrade will do and printing a summary of this to the user. This patch implements that. Again, multiple functions are used to facilitate monkeypatching by extensions. diff --git a/mercurial/repair.py b/mercurial/repair.py --- a/mercurial/repair.py +++ b/mercurial/repair.py @@ -480,6 +480,61 @@ def upgradereporequirements(repo): return createreqs +def upgradevalidateactions(repo, sourcereqs, destreqs, actions): + """Validate (and modify accordingly) the list of actions to perform. + + Returns a set of actions that will be performed. The set is advisory + only and is intended to drive presentation of what actions will be + taken. + + Extensions can monkeypatch this to mutate the set of actions that + will be performed. + """ + newactions = set(actions) + + for req in ('dotencode', 'fncache', 'generaldelta'): + if req in actions and req not in destreqs: + newactions.remove(req) + + return newactions + +def upgradesummarizeactions(repo, actions): + """Summarize actions that will be taken as part of upgrade. + + Receives a set of action names. Returns a list of strings that will be + presented to user describing these actions and a set of actions processed + by this function. + """ + l = [] + handled = set() + + if 'dotencode' in actions: + l.append(_('dotencode repository layout will be used; the repository ' + 'will be able be more resilient to storing paths beginning ' + 'with periods or spaces')) + handled.add('dotencode') + + if 'fncache' in actions: + l.append(_('fncache repository layout will be used; the repository ' + 'will be more resilient storing long paths and special ' + 'filenames')) + handled.add('fncache') + + if 'generaldelta' in actions: + l.append(_('repository data will be re-encoded as "generaldelta"; ' + 'files inside the repository should be smaller, read times ' + 'should decrease, and interacting with other generaldelta ' + 'repositories should be faster')) + handled.add('generaldelta') + + if 'removecldeltachain' in actions: + l.append(_('delta chains will be removed from the changelog; reading ' + 'changelogs should be faster, changelogs may decrease ' + 'in size\n')) + handled.add('removecldeltachain') + + return l, handled + def upgraderepo(ui, repo, dryrun=False): """Upgrade a repository in place.""" repo = repo.unfiltered() @@ -507,3 +562,24 @@ def upgraderepo(ui, repo, dryrun=False): ui.write(_('adding repository requirements: %s\n') % ', '.join(sorted(newreqs - repo.requirements))) + actions = upgradevalidateactions(repo, repo.requirements, newreqs, actions) + + changes, handledactions = upgradesummarizeactions(repo, actions) + + unhandled = actions - handledactions + if unhandled: + raise error.Abort(_('unable to upgrade repository; proposed upgrade ' + 'action not handled: %s') % + ', '.join(sorted(unhandled))) + + if actions: + ui.write(_('upgrading the repository will make the following ' + 'significant changes:\n\n')) + for change in changes: + ui.write('* %s\n' % change) + else: + ui.write(_('no notable upgrade changes identified\n')) + + if dryrun: + ui.warn(_('dry run requested; not continuing with upgrade\n')) + return 1 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 @@ -5,6 +5,18 @@ checking repository requirements... preserving repository requirements: dotencode, fncache, generaldelta, revlogv1, store + no notable upgrade changes identified + +dry run works + + $ hg debugupgraderepo --dry-run + no obvious deficiencies found in existing repository + + checking repository requirements... + preserving repository requirements: dotencode, fncache, generaldelta, revlogv1, store + no notable upgrade changes identified + dry run requested; not continuing with upgrade + [1] Various sub-optimal detections work @@ -23,6 +35,11 @@ Various sub-optimal detections work checking repository requirements... preserving repository requirements: revlogv1, store adding repository requirements: dotencode, fncache, generaldelta + upgrading the repository will make the following significant changes: + + * dotencode repository layout will be used; the repository will be able be more resilient to storing paths beginning with periods or spaces + * fncache repository layout will be used; the repository will be more resilient storing long paths and special filenames + * repository data will be re-encoded as "generaldelta"; files inside the repository should be smaller, read times should decrease, and interacting with other generaldelta repositories should be faster $ cd .. _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel