Commit Graph

39 Commits

Author SHA1 Message Date
Yuya Nishihara
c49a9c7ce9 upgrade: simplify workaround for repo.ui.copy()
Copied from commandserver.py.
2017-12-10 19:43:35 +09:00
Boris Feld
d8aa8e36d8 upgrade: add a 'redeltafullall' mode
We add a new mode for delta recomputation, when selected, each full text will
go through the full "addrevision" mechanism again. This is slower than
"redeltaall" but this gives the opportunity for extensions to trigger special
logic. For example, the lfs extensions can decide to promote some revision to
lfs storage during the upgrade.
2017-12-07 20:27:03 +01:00
Boris Feld
84c9e6582a upgrade: use actual filelog to convert filelog
Extensions can add extra logic related to the config, so we must use the actual
class. The path used needs minimal transformation for this to work.
2017-12-07 22:37:18 +01:00
Boris Feld
b70b33bf91 upgrade: more standard creation of the temporary repository
By using the standard path to create a repository we fill some hole in the
current initialization process. The one who triggered this changeset was the
lack of extensions initialization.
2017-12-07 18:56:10 +01:00
Boris Feld
826e838aa1 upgrade: use the repository 'ui' as the base for the new repository
The `repo.baseui` contains all the configuration but the one specific to the
repository (so it can be used when dealing with local peer and sub-
repository). However, we need the repository config to be taken into account
when doing the upgrade. Otherwise, the upgrade related config that exists in
the repository config won't be taken into account when performing the update.
A buggy and surprising behavior.

We had to work around protection set around `repo.ui.copy` since we are an
uncommon case.
2017-12-07 18:55:35 +01:00
Boris Feld
9f250d48c5 upgrade: register compression as a format variants
Compression is a promising vector for speedup, let us make it easier to check
the compression used and upgrade existing repository.
2017-12-07 16:50:48 +01:00
Boris Feld
dd552bcef6 upgrade: rename 'removecldeltachain' to 'plain-cl-delta'
The new naming is more descriptive of a "state" while the older one was more
about "action". I'm looking into command exposing more of data about the state
of the repository so "state" oriented work better there.

The key has not been made public anywhere outside the debug area so it is fine
to update it.
2017-12-07 15:55:59 +01:00
Boris Feld
8a1502d6d0 upgraderepo: allow extension to register preserved requirements
Some requirement does not directly result from config and needs more advanced
logic to be preserved. The current example is 'largefiles'. We add a hook
point in the upgrade code so that extensions can handle these cases.

The 'largefiles' extension will use it in the next changeset.
2017-12-07 01:51:54 +01:00
Jun Wu
c41f5ca68e codemod: simplify nested withs
This is the result of running:

  python codemod_nestedwith.py **/*.py

where codemod_nestedwith.py looks like this:

#!/usr/bin/env python
# codemod_nestedwith.py - codemod tool to rewrite nested with
#
# Copyright 2017 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import, print_function

import sys

import redbaron

def readpath(path):
    with open(path) as f:
        return f.read()

def writepath(path, content):
    with open(path, 'w') as f:
        f.write(content)

def main(argv):
    if not argv:
        print('Usage: codemod_nestedwith.py FILES')

    for i, path in enumerate(argv):
        print('(%d/%d) scanning %s' % (i + 1, len(argv), path))
        changed = False
        red = redbaron.RedBaron(readpath(path))
        processed = set()
        for node in red.find_all('with'):
            if node in processed or node.type != 'with':
                continue
            top = node
            child = top[0]
            while True:
                if len(top) > 1 or child.type != 'with':
                    break
                # estimate line length after merging two "with"s
                new = '%swith %s:' % (top.indentation, top.contexts.dumps())
                new += ', %s' % child.contexts.dumps()
                # only do the rewrite if the end result is within 80 chars
                if len(new) > 80:
                    break
                processed.add(child)
                top.contexts.extend(child.contexts)
                top.value = child.value
                top.value.decrease_indentation(4)
                child = child[0]
                changed = True
        if changed:
            print('updating %s' % path)
            writepath(path, red.dumps())

if __name__ == "__main__":
    sys.exit(main(sys.argv[1:]))


Differential Revision: https://phab.mercurial-scm.org/D77
2017-07-13 18:31:35 -07:00
Martin von Zweigbergk
c3406ac3db cleanup: use set literals
We no longer support Python 2.6, so we can now use set literals.
2017-02-10 16:56:29 -08:00
Pierre-Yves David
c9ad04b92a upgrade: register all format variants in a list
Now that all known format variants exists outside of the function, we can gather
them in a lists. This build a single entry point other code can use (current
target: extensions).

The repository upgrade code is updated to simply use entries from this list.

As a side effect this will also allow extensions to register their own format
variants, to do this "properly" we should introduce a "registrar" for this
category of object. However I prefer to keep this series simple, and that will
be adventure for future time.
2017-04-12 16:48:13 +02:00
Pierre-Yves David
1d4581993a upgrade: move descriptions and selection logic in individual classes
Our goal here is to get top level definition for all the format variants. Having
them defined outside of the function enabled other users of that logic.

They are two keys components of a format variant:

1) the name and various descriptions of its effect,

2) the code that checks if the repo is using this variant and if the config
   enables it.

That second items make us pick a class-based approach, since different variants
requires different code (even if in practice, many can reuse the same logic).
Each variants define its own class that is then used like a singleton.  The
class-based approach also clarify the definitions part a bit since each are
simple assignment in an indented block.

The 'fromdefault' and 'fromconfig' are respectively replaced by a class
attribute and a method to be called at the one place where "fromconfig"
matters.

Overall, they are many viable approach for this, but this is the one I picked.
2017-04-12 16:34:05 +02:00
Pierre-Yves David
62412d4eb9 upgrade: introduce a 'formatvariant' class
The 'deficiency' type has multiple specificities. We create a dedicated class to
host them. More logic will be added incrementally in future changesets.
2017-04-10 23:34:43 +02:00
Pierre-Yves David
285b20d327 upgrade: implement '__hash__' on 'improvement' class
The pythonomicon request its implementation.
2017-04-17 13:07:31 +02:00
Pierre-Yves David
258609b002 upgrade: implement '__ne__' on 'improvement' class
The pythonomicon request its implementation.
2017-04-17 13:07:22 +02:00
Pierre-Yves David
63f0ebdb7f upgrade: simplify the "origin" dispatch in dry run
We could compute the final set we need directly.
2017-04-11 00:03:11 +02:00
Pierre-Yves David
0befb32302 upgrade: use 'improvement' object for action too
This simplify multiple pieces of code. For now we restrict this upgrade to the
top level function to keep this patch simple.
2017-04-10 23:11:45 +02:00
Pierre-Yves David
8343e068f0 upgrade: implement equality for 'improvement' object
Through the code, we use a mix of 'improvement' object and string. Having a
single type would be simpler. For this we need the object to be comparable.
2017-04-10 23:10:03 +02:00
Pierre-Yves David
28e1ded0a7 upgrade: simplify some of the initial dispatch for dry run
Since we already have the list of deficiencies, we can use it directly.
2017-04-10 22:15:17 +02:00
Pierre-Yves David
917b0eb147 upgrade: simplify 'determineactions'
Since we only takes 'deficiencies', we can simplify the function and clarify its
arguments.
2017-04-07 18:39:27 +02:00
Pierre-Yves David
dbe4fb45ab upgrade: filter optimizations outside of 'determineactions'
This sounds like higher level logic to process arguments.

Moving it out of 'determineactions' will allow passing only deficiencies to the
function. Then, in a future changeset, we will remove  dispatch on "improvement
type" within the function. See next changeset for details.
2017-04-11 23:46:16 +02:00
Pierre-Yves David
74208899a2 upgrade: directly iterate over optimisations
Since we already have the list of optimisations independent from the
deficiencies, we can use it directly.

(we make a dual assignement in this changeset to simplify the next one)
2017-04-07 18:46:27 +02:00
Pierre-Yves David
a5369d6f5d upgrade: simplify optimisations validation
Since we fetch optimizations distinctly from the deficiencies, we can simplify
some code.
2017-04-10 21:01:06 +02:00
Pierre-Yves David
6e51b0fbf0 upgrade: split finding deficiencies from finding optimisations
Our ultimate goal is to make it easier to get a diagnostic of the repository
format. A first important and step for that is to separate part related to
repository format from the optimisation. We start by having two different
functions returning the two categories of possible "improvement".
2017-04-10 21:00:52 +02:00
Pierre-Yves David
a73976f4f4 upgrade: update the copyright statement 2017-04-11 22:07:40 +02:00
Pierre-Yves David
ef922b1da6 upgrade: update the header comment 2017-04-11 22:07:15 +02:00
Pierre-Yves David
f958f09136 upgrade: import 'localrepo' globally
The in-function imports mention a cycle that seems to no longer be relevant. As
a result, we just import it globally.
2017-04-11 22:01:13 +02:00
Yuya Nishihara
0c147d5d5b merge with stable 2017-04-11 23:12:14 +09:00
Pierre-Yves David
26d206d2eb upgrade: drop the prefix to the '_finishdatamigration' function
Now that we are in the 'upgrade' module we can simplify the name.
2017-04-10 18:06:22 +02:00
Pierre-Yves David
00c5df46ac upgrade: drop the prefix to the '_filterstorefile' function
Now that we are in the 'upgrade' module we can simplify the name.
2017-04-10 18:06:12 +02:00
Pierre-Yves David
5b86dfbc64 upgrade: drop the prefix to the 'determineactions' function
Now that we are in the 'upgrade' module we can simplify the name.
2017-04-10 18:05:57 +02:00
Pierre-Yves David
05aee6cdc6 upgrade: drop the prefix to the 'findimprovements' function
Now that we are in the 'upgrade' module we can simplify the name.
2017-04-10 18:05:42 +02:00
Pierre-Yves David
11540e4514 upgrade: drop the prefix to the 'supporteddestrequirements' function
Now that we are in the 'upgrade' module we can simplify the name.
2017-04-10 18:04:50 +02:00
Pierre-Yves David
22b935febf upgrade: drop the prefix to the 'allowednewrequirements' function
Now that we are in the 'upgrade' module we can simplify the name.
2017-04-10 18:03:11 +02:00
Pierre-Yves David
b2c10b5f98 upgrade: drop the prefix to the 'improvement' class
Now that we are in the 'upgrade' module we can simplify the name.
2017-04-10 18:01:29 +02:00
Pierre-Yves David
c84b2083be upgrade: drop the prefix to the 'supportremovedrequirements' function
Now that we are in the 'upgrade' module we can simplify the name.
2017-04-10 18:00:27 +02:00
Pierre-Yves David
32ac44c068 upgrade: drop the prefix to the 'blocksourcerequirements' function
Now that we are in the 'upgrade' module we can simplify the name.
2017-04-10 17:56:29 +02:00
Pierre-Yves David
14adb0955f upgrade: drop the prefix to the 'requiredsourcerequirements' function
Now that we are in the 'upgrade' module we can simplify the name.
2017-04-10 17:55:47 +02:00
Pierre-Yves David
64e5cd2f7e upgrade: extract code in its own module
Given about 2/3 or 'mercurial.repair' is now about repository upgrade, I think
it is fair to move it into its own module.

An expected benefit is the ability to drop the 'upgrade' prefix of many
functions. This will be done in coming changesets.
2017-04-07 18:53:17 +02:00