Commit Graph

30 Commits

Author SHA1 Message Date
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