From 1bedfa7749300da167808b837d2a8968df43eeb3 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Tue, 3 Sep 2013 16:35:36 +0000 Subject: b&m: re-implement morph unpetrify This also undoes the test suite change to keep it using the old petrify. Petrify and Unpetrify have the same structure: 1. Set up 2. Load all the morphologies 3. Make changes to the morphologies 4. Write back any changes This suggests some re-use in the form of passing a function callback to a morphology visitor. --- morphlib/plugins/branch_and_merge_new_plugin.py | 48 ++++++++++++++++++++++++- morphlib/plugins/branch_and_merge_plugin.py | 2 +- 2 files changed, 48 insertions(+), 2 deletions(-) (limited to 'morphlib') diff --git a/morphlib/plugins/branch_and_merge_new_plugin.py b/morphlib/plugins/branch_and_merge_new_plugin.py index 971c1328..aafc8dcd 100644 --- a/morphlib/plugins/branch_and_merge_new_plugin.py +++ b/morphlib/plugins/branch_and_merge_new_plugin.py @@ -45,6 +45,8 @@ class SimpleBranchAndMergePlugin(cliapp.Plugin): 'edit', self.edit, arg_synopsis='SYSTEM STRATUM [CHUNK]') self.app.add_subcommand( 'petrify', self.petrify, arg_synopsis='') + self.app.add_subcommand( + 'unpetrify', self.unpetrify, arg_synopsis='') self.app.add_subcommand( 'show-system-branch', self.show_system_branch, arg_synopsis='') self.app.add_subcommand( @@ -608,7 +610,7 @@ class SimpleBranchAndMergePlugin(cliapp.Plugin): self.app.output.flush() def _load_all_sysbranch_morphologies(self, sb, loader): - # Read in all the morphologies in the root repository. + '''Read in all the morphologies in the root repository.''' self.app.status(msg='Loading in all morphologies') morphs = morphlib.morphset.MorphologySet() mf = morphlib.morphologyfinder.MorphologyFinder( @@ -695,3 +697,47 @@ class SimpleBranchAndMergePlugin(cliapp.Plugin): # Write morphologies back out again. self._save_dirty_morphologies(loader, sb, morphs.morphologies) + + def unpetrify(self, args): + '''Reverse the process of petrification. + + This undoes the changes `morph petrify` did. + + ''' + + if args: + raise cliapp.AppException('morph petrify takes no arguments') + + ws = morphlib.workspace.open('.') + sb = morphlib.sysbranchdir.open_from_within('.') + loader = morphlib.morphloader.MorphologyLoader() + lrc, rrc = morphlib.util.new_repo_caches(self.app) + update_repos = not self.app.settings['no-git-update'] + done = set() + + morphs = self._load_all_sysbranch_morphologies(sb, loader) + + # Restore the ref for each stratum and chunk + def unpetrify_specs(specs): + dirty = False + for spec in specs: + ref = spec['ref'] + # Don't attempt to unpetrify refs which aren't petrified + if not ('unpetrify-ref' in spec + and morphlib.git.is_valid_sha1(ref)): + continue + spec['ref'] = spec.pop('unpetrify-ref') + dirty = True + return dirty + + for m in morphs.morphologies: + dirty = False + if m['kind'] == 'system': + dirty = dirty or unpetrify_specs(m['strata']) + elif m['kind'] == 'stratum': + dirty = dirty or unpetrify_specs(m['build-depends']) + dirty = dirty or unpetrify_specs(m['chunks']) + m.dirty = True + + # Write morphologies back out again. + self._save_dirty_morphologies(loader, sb, morphs.morphologies) diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py index 4791989b..671071b6 100644 --- a/morphlib/plugins/branch_and_merge_plugin.py +++ b/morphlib/plugins/branch_and_merge_plugin.py @@ -62,7 +62,7 @@ class BranchAndMergePlugin(cliapp.Plugin): # self.app.add_subcommand('edit', self.edit, # arg_synopsis='SYSTEM STRATUM [CHUNK]') self.app.add_subcommand('old-petrify', self.petrify) - self.app.add_subcommand('unpetrify', self.unpetrify) + self.app.add_subcommand('old-unpetrify', self.unpetrify) self.app.add_subcommand( 'tag', self.tag, arg_synopsis='TAG-NAME -- [GIT-COMMIT-ARG...]') self.app.add_subcommand('build', self.build, -- cgit v1.2.1