##// 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 46 class improvement(object):
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.
47 """Represents an improvement that can be made as part of an upgrade."""
67 48
68 upgrademessage
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
49 ### The following attributes should be defined for each subclass:
88 50
89 touches_requirements (bool)
90 Whether this improvement changes repository requirements
91 """
92
93 def __init__(self, name, type, description, upgrademessage):
94 self.name = name
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:
51 # Either ``FORMAT_VARIANT`` or ``OPTIMISATION``.
52 # A format variant is where we change the storage format. Not all format
53 # variant changes are an obvious problem.
54 # An optimization is an action (sometimes optional) that
55 # can be taken to further improve the state of the repository.
56 type = None
133 57
134 58 # machine-readable string uniquely identifying this improvement. it will be
135 59 # mapped to an action later in the upgrade process.
@@ -157,13 +81,32 b' class formatvariant(improvement):'
157 81 postdowngrademessage = None
158 82
159 83 # By default for now, we assume every improvement touches all the things
84
85 # Whether this improvement touches filelogs
160 86 touches_filelogs = True
87
88 # Whether this improvement touches manifests
161 89 touches_manifests = True
90
91 # Whether this improvement touches changelog
162 92 touches_changelog = True
93
94 # Whether this improvement changes repository requirements
163 95 touches_requirements = True
164 96
165 def __init__(self):
166 raise NotImplementedError()
97
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 111 @staticmethod
169 112 def fromrepo(repo):
@@ -545,87 +488,100 b' def register_optimization(obj):'
545 488 return obj
546 489
547 490
548 register_optimization(
549 improvement(
550 name=b're-delta-parent',
551 type=OPTIMISATION,
552 description=_(
553 b'deltas within internal storage will be recalculated to '
554 b'choose an optimal base revision where this was not '
555 b'already done; the size of the repository may shrink and '
556 b'various operations may become faster; the first time '
557 b'this optimization is performed could slow down upgrade '
558 b'execution considerably; subsequent invocations should '
559 b'not run noticeably slower'
560 ),
561 upgrademessage=_(
562 b'deltas within internal storage will choose a new '
563 b'base revision if needed'
564 ),
491 class optimization(improvement):
492 """an improvement subclass dedicated to optimizations"""
493
494 type = OPTIMISATION
495
496
497 @register_optimization
498 class redeltaparents(optimization):
499 name = b're-delta-parent'
500
501 type = OPTIMISATION
502
503 description = _(
504 b'deltas within internal storage will be recalculated to '
505 b'choose an optimal base revision where this was not '
506 b'already done; the size of the repository may shrink and '
507 b'various operations may become faster; the first time '
508 b'this optimization is performed could slow down upgrade '
509 b'execution considerably; subsequent invocations should '
510 b'not run noticeably slower'
565 511 )
566 )
512
513 upgrademessage = _(
514 b'deltas within internal storage will choose a new '
515 b'base revision if needed'
516 )
517
518
519 @register_optimization
520 class redeltamultibase(optimization):
521 name = b're-delta-multibase'
522
523 type = OPTIMISATION
524
525 description = _(
526 b'deltas within internal storage will be recalculated '
527 b'against multiple base revision and the smallest '
528 b'difference will be used; the size of the repository may '
529 b'shrink significantly when there are many merges; this '
530 b'optimization will slow down execution in proportion to '
531 b'the number of merges in the repository and the amount '
532 b'of files in the repository; this slow down should not '
533 b'be significant unless there are tens of thousands of '
534 b'files and thousands of merges'
535 )
567 536
568 register_optimization(
569 improvement(
570 name=b're-delta-multibase',
571 type=OPTIMISATION,
572 description=_(
573 b'deltas within internal storage will be recalculated '
574 b'against multiple base revision and the smallest '
575 b'difference will be used; the size of the repository may '
576 b'shrink significantly when there are many merges; this '
577 b'optimization will slow down execution in proportion to '
578 b'the number of merges in the repository and the amount '
579 b'of files in the repository; this slow down should not '
580 b'be significant unless there are tens of thousands of '
581 b'files and thousands of merges'
582 ),
583 upgrademessage=_(
584 b'deltas within internal storage will choose an '
585 b'optimal delta by computing deltas against multiple '
586 b'parents; may slow down execution time '
587 b'significantly'
588 ),
537 upgrademessage = _(
538 b'deltas within internal storage will choose an '
539 b'optimal delta by computing deltas against multiple '
540 b'parents; may slow down execution time '
541 b'significantly'
589 542 )
590 )
543
544
545 @register_optimization
546 class redeltaall(optimization):
547 name = b're-delta-all'
548
549 type = OPTIMISATION
550
551 description = _(
552 b'deltas within internal storage will always be '
553 b'recalculated without reusing prior deltas; this will '
554 b'likely make execution run several times slower; this '
555 b'optimization is typically not needed'
556 )
591 557
592 register_optimization(
593 improvement(
594 name=b're-delta-all',
595 type=OPTIMISATION,
596 description=_(
597 b'deltas within internal storage will always be '
598 b'recalculated without reusing prior deltas; this will '
599 b'likely make execution run several times slower; this '
600 b'optimization is typically not needed'
601 ),
602 upgrademessage=_(
603 b'deltas within internal storage will be fully '
604 b'recomputed; this will likely drastically slow down '
605 b'execution time'
606 ),
558 upgrademessage = _(
559 b'deltas within internal storage will be fully '
560 b'recomputed; this will likely drastically slow down '
561 b'execution time'
607 562 )
608 )
563
564
565 @register_optimization
566 class redeltafulladd(optimization):
567 name = b're-delta-fulladd'
568
569 type = OPTIMISATION
609 570
610 register_optimization(
611 improvement(
612 name=b're-delta-fulladd',
613 type=OPTIMISATION,
614 description=_(
615 b'every revision will be re-added as if it was new '
616 b'content. It will go through the full storage '
617 b'mechanism giving extensions a chance to process it '
618 b'(eg. lfs). This is similar to "re-delta-all" but even '
619 b'slower since more logic is involved.'
620 ),
621 upgrademessage=_(
622 b'each revision will be added as new content to the '
623 b'internal storage; this will likely drastically slow '
624 b'down execution time, but some extensions might need '
625 b'it'
626 ),
571 description = _(
572 b'every revision will be re-added as if it was new '
573 b'content. It will go through the full storage '
574 b'mechanism giving extensions a chance to process it '
575 b'(eg. lfs). This is similar to "re-delta-all" but even '
576 b'slower since more logic is involved.'
627 577 )
628 )
578
579 upgrademessage = _(
580 b'each revision will be added as new content to the '
581 b'internal storage; this will likely drastically slow '
582 b'down execution time, but some extensions might need '
583 b'it'
584 )
629 585
630 586
631 587 def findoptimizations(repo):
General Comments 0
You need to be logged in to leave comments. Login now