Mercurial > public > mercurial-scm > hg
comparison mercurial/upgrade_utils/actions.py @ 46191:aba979b1b90b
upgrade: move `printrequirements()` to UpgradeOperation class
Part of refactor where we make things more arranged and integrated into single
`UpgradeOperation` class.
Differential Revision: https://phab.mercurial-scm.org/D9577
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Sat, 12 Dec 2020 18:09:16 +0530 |
parents | 9ab2ab5bf9af |
children | 25d11b24dedf |
comparison
equal
deleted
inserted
replaced
46190:9ab2ab5bf9af | 46191:aba979b1b90b |
---|---|
555 | 555 |
556 | 556 |
557 class UpgradeOperation(object): | 557 class UpgradeOperation(object): |
558 """represent the work to be done during an upgrade""" | 558 """represent the work to be done during an upgrade""" |
559 | 559 |
560 def __init__(self, ui, requirements, actions, revlogs_to_process): | 560 def __init__( |
561 self, | |
562 ui, | |
563 new_requirements, | |
564 current_requirements, | |
565 actions, | |
566 revlogs_to_process, | |
567 ): | |
561 self.ui = ui | 568 self.ui = ui |
562 self.requirements = requirements | 569 self.new_requirements = new_requirements |
570 self.current_requirements = current_requirements | |
563 self.actions = actions | 571 self.actions = actions |
564 self._actions_names = set([a.name for a in actions]) | 572 self._actions_names = set([a.name for a in actions]) |
565 self.revlogs_to_process = revlogs_to_process | 573 self.revlogs_to_process = revlogs_to_process |
574 # requirements which will be added by the operation | |
575 self._added_requirements = ( | |
576 self.new_requirements - self.current_requirements | |
577 ) | |
578 # requirements which will be removed by the operation | |
579 self._removed_requirements = ( | |
580 self.current_requirements - self.new_requirements | |
581 ) | |
582 # requirements which will be preserved by the operation | |
583 self._preserved_requirements = ( | |
584 self.current_requirements & self.new_requirements | |
585 ) | |
566 | 586 |
567 def _write_labeled(self, l, label): | 587 def _write_labeled(self, l, label): |
568 """ | 588 """ |
569 Utility function to aid writing of a list under one label | 589 Utility function to aid writing of a list under one label |
570 """ | 590 """ |
572 for r in sorted(l): | 592 for r in sorted(l): |
573 if not first: | 593 if not first: |
574 self.ui.write(b', ') | 594 self.ui.write(b', ') |
575 self.ui.write(r, label=label) | 595 self.ui.write(r, label=label) |
576 first = False | 596 first = False |
597 | |
598 def print_requirements(self): | |
599 self.ui.write(_(b'requirements\n')) | |
600 self.ui.write(_(b' preserved: ')) | |
601 self._write_labeled( | |
602 self._preserved_requirements, "upgrade-repo.requirement.preserved" | |
603 ) | |
604 self.ui.write((b'\n')) | |
605 if self._removed_requirements: | |
606 self.ui.write(_(b' removed: ')) | |
607 self._write_labeled( | |
608 self._removed_requirements, "upgrade-repo.requirement.removed" | |
609 ) | |
610 self.ui.write((b'\n')) | |
611 if self._added_requirements: | |
612 self.ui.write(_(b' added: ')) | |
613 self._write_labeled( | |
614 self._added_requirements, "upgrade-repo.requirement.added" | |
615 ) | |
616 self.ui.write((b'\n')) | |
617 self.ui.write(b'\n') | |
577 | 618 |
578 def print_optimisations(self): | 619 def print_optimisations(self): |
579 optimisations = [a for a in self.actions if a.type == OPTIMISATION] | 620 optimisations = [a for a in self.actions if a.type == OPTIMISATION] |
580 optimisations.sort(key=lambda a: a.name) | 621 optimisations.sort(key=lambda a: a.name) |
581 if optimisations: | 622 if optimisations: |