##// END OF EJS Templates
upgrade: Use `improvement` subclasses everywhere, not instances...
Simon Sapin -
r48110:e985a36c default
parent child Browse files
Show More
@@ -44,92 +44,16 b" OPTIMISATION = b'optimization'"
44
44
45
45
46 class improvement(object):
46 class improvement(object):
47 """Represents an improvement that can be made as part of an upgrade.
47 """Represents an improvement that can be made as part of an upgrade."""
48
49 The following attributes are defined on each instance:
50
51 name
52 Machine-readable string uniquely identifying this improvement. It
53 will be mapped to an action later in the upgrade process.
54
55 type
56 Either ``FORMAT_VARIANT`` or ``OPTIMISATION``.
57 A format variant is where we change the storage format. Not all format
58 variant changes are an obvious problem.
59 An optimization is an action (sometimes optional) that
60 can be taken to further improve the state of the repository.
61
62 description
63 Message intended for humans explaining the improvement in more detail,
64 including the implications of it. For ``FORMAT_VARIANT`` types, should be
65 worded in the present tense. For ``OPTIMISATION`` types, should be
66 worded in the future tense.
67
48
68 upgrademessage
49 ### The following attributes should be defined for each subclass:
69 Message intended for humans explaining what an upgrade addressing this
70 issue will do. Should be worded in the future tense.
71
72 postupgrademessage
73 Message intended for humans which will be shown post an upgrade
74 operation when the improvement will be added
75
76 postdowngrademessage
77 Message intended for humans which will be shown post an upgrade
78 operation in which this improvement was removed
79
80 touches_filelogs (bool)
81 Whether this improvement touches filelogs
82
83 touches_manifests (bool)
84 Whether this improvement touches manifests
85
86 touches_changelog (bool)
87 Whether this improvement touches changelog
88
50
89 touches_requirements (bool)
51 # Either ``FORMAT_VARIANT`` or ``OPTIMISATION``.
90 Whether this improvement changes repository requirements
52 # A format variant is where we change the storage format. Not all format
91 """
53 # variant changes are an obvious problem.
92
54 # An optimization is an action (sometimes optional) that
93 def __init__(self, name, type, description, upgrademessage):
55 # can be taken to further improve the state of the repository.
94 self.name = name
56 type = None
95 self.type = type
96 self.description = description
97 self.upgrademessage = upgrademessage
98 self.postupgrademessage = None
99 self.postdowngrademessage = None
100 # By default for now, we assume every improvement touches
101 # all the things
102 self.touches_filelogs = True
103 self.touches_manifests = True
104 self.touches_changelog = True
105 self.touches_requirements = True
106
107 def __eq__(self, other):
108 if not isinstance(other, improvement):
109 # This is what python tell use to do
110 return NotImplemented
111 return self.name == other.name
112
113 def __ne__(self, other):
114 return not (self == other)
115
116 def __hash__(self):
117 return hash(self.name)
118
119
120 allformatvariant = [] # type: List[Type['formatvariant']]
121
122
123 def registerformatvariant(cls):
124 allformatvariant.append(cls)
125 return cls
126
127
128 class formatvariant(improvement):
129 """an improvement subclass dedicated to repository format"""
130
131 type = FORMAT_VARIANT
132 ### The following attributes should be defined for each class:
133
57
134 # machine-readable string uniquely identifying this improvement. it will be
58 # machine-readable string uniquely identifying this improvement. it will be
135 # mapped to an action later in the upgrade process.
59 # mapped to an action later in the upgrade process.
@@ -157,13 +81,32 b' class formatvariant(improvement):'
157 postdowngrademessage = None
81 postdowngrademessage = None
158
82
159 # By default for now, we assume every improvement touches all the things
83 # By default for now, we assume every improvement touches all the things
84
85 # Whether this improvement touches filelogs
160 touches_filelogs = True
86 touches_filelogs = True
87
88 # Whether this improvement touches manifests
161 touches_manifests = True
89 touches_manifests = True
90
91 # Whether this improvement touches changelog
162 touches_changelog = True
92 touches_changelog = True
93
94 # Whether this improvement changes repository requirements
163 touches_requirements = True
95 touches_requirements = True
164
96
165 def __init__(self):
97
166 raise NotImplementedError()
98 allformatvariant = [] # type: List[Type['formatvariant']]
99
100
101 def registerformatvariant(cls):
102 allformatvariant.append(cls)
103 return cls
104
105
106 class formatvariant(improvement):
107 """an improvement subclass dedicated to repository format"""
108
109 type = FORMAT_VARIANT
167
110
168 @staticmethod
111 @staticmethod
169 def fromrepo(repo):
112 def fromrepo(repo):
@@ -545,10 +488,18 b' def register_optimization(obj):'
545 return obj
488 return obj
546
489
547
490
548 register_optimization(
491 class optimization(improvement):
549 improvement(
492 """an improvement subclass dedicated to optimizations"""
550 name=b're-delta-parent',
493
551 type=OPTIMISATION,
494 type = OPTIMISATION
495
496
497 @register_optimization
498 class redeltaparents(optimization):
499 name = b're-delta-parent'
500
501 type = OPTIMISATION
502
552 description=_(
503 description = _(
553 b'deltas within internal storage will be recalculated to '
504 b'deltas within internal storage will be recalculated to '
554 b'choose an optimal base revision where this was not '
505 b'choose an optimal base revision where this was not '
@@ -557,18 +508,20 b' register_optimization('
557 b'this optimization is performed could slow down upgrade '
508 b'this optimization is performed could slow down upgrade '
558 b'execution considerably; subsequent invocations should '
509 b'execution considerably; subsequent invocations should '
559 b'not run noticeably slower'
510 b'not run noticeably slower'
560 ),
511 )
512
561 upgrademessage=_(
513 upgrademessage = _(
562 b'deltas within internal storage will choose a new '
514 b'deltas within internal storage will choose a new '
563 b'base revision if needed'
515 b'base revision if needed'
564 ),
565 )
566 )
516 )
567
517
568 register_optimization(
518
569 improvement(
519 @register_optimization
570 name=b're-delta-multibase',
520 class redeltamultibase(optimization):
571 type=OPTIMISATION,
521 name = b're-delta-multibase'
522
523 type = OPTIMISATION
524
572 description=_(
525 description = _(
573 b'deltas within internal storage will be recalculated '
526 b'deltas within internal storage will be recalculated '
574 b'against multiple base revision and the smallest '
527 b'against multiple base revision and the smallest '
@@ -579,52 +532,55 b' register_optimization('
579 b'of files in the repository; this slow down should not '
532 b'of files in the repository; this slow down should not '
580 b'be significant unless there are tens of thousands of '
533 b'be significant unless there are tens of thousands of '
581 b'files and thousands of merges'
534 b'files and thousands of merges'
582 ),
535 )
536
583 upgrademessage=_(
537 upgrademessage = _(
584 b'deltas within internal storage will choose an '
538 b'deltas within internal storage will choose an '
585 b'optimal delta by computing deltas against multiple '
539 b'optimal delta by computing deltas against multiple '
586 b'parents; may slow down execution time '
540 b'parents; may slow down execution time '
587 b'significantly'
541 b'significantly'
588 ),
589 )
590 )
542 )
591
543
592 register_optimization(
544
593 improvement(
545 @register_optimization
594 name=b're-delta-all',
546 class redeltaall(optimization):
595 type=OPTIMISATION,
547 name = b're-delta-all'
548
549 type = OPTIMISATION
550
596 description=_(
551 description = _(
597 b'deltas within internal storage will always be '
552 b'deltas within internal storage will always be '
598 b'recalculated without reusing prior deltas; this will '
553 b'recalculated without reusing prior deltas; this will '
599 b'likely make execution run several times slower; this '
554 b'likely make execution run several times slower; this '
600 b'optimization is typically not needed'
555 b'optimization is typically not needed'
601 ),
556 )
557
602 upgrademessage=_(
558 upgrademessage = _(
603 b'deltas within internal storage will be fully '
559 b'deltas within internal storage will be fully '
604 b'recomputed; this will likely drastically slow down '
560 b'recomputed; this will likely drastically slow down '
605 b'execution time'
561 b'execution time'
606 ),
607 )
608 )
562 )
609
563
610 register_optimization(
564
611 improvement(
565 @register_optimization
612 name=b're-delta-fulladd',
566 class redeltafulladd(optimization):
613 type=OPTIMISATION,
567 name = b're-delta-fulladd'
568
569 type = OPTIMISATION
570
614 description=_(
571 description = _(
615 b'every revision will be re-added as if it was new '
572 b'every revision will be re-added as if it was new '
616 b'content. It will go through the full storage '
573 b'content. It will go through the full storage '
617 b'mechanism giving extensions a chance to process it '
574 b'mechanism giving extensions a chance to process it '
618 b'(eg. lfs). This is similar to "re-delta-all" but even '
575 b'(eg. lfs). This is similar to "re-delta-all" but even '
619 b'slower since more logic is involved.'
576 b'slower since more logic is involved.'
620 ),
577 )
578
621 upgrademessage=_(
579 upgrademessage = _(
622 b'each revision will be added as new content to the '
580 b'each revision will be added as new content to the '
623 b'internal storage; this will likely drastically slow '
581 b'internal storage; this will likely drastically slow '
624 b'down execution time, but some extensions might need '
582 b'down execution time, but some extensions might need '
625 b'it'
583 b'it'
626 ),
627 )
628 )
584 )
629
585
630
586
General Comments 0
You need to be logged in to leave comments. Login now