diff options
-rw-r--r-- | morphlib/plugins/branch_and_merge_new_plugin.py | 48 | ||||
-rw-r--r-- | morphlib/plugins/branch_and_merge_plugin.py | 2 | ||||
-rwxr-xr-x | tests.branching/petrify.script | 2 |
3 files changed, 49 insertions, 3 deletions
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 @@ -46,6 +46,8 @@ class SimpleBranchAndMergePlugin(cliapp.Plugin): 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( 'show-branch-root', self.show_branch_root, arg_synopsis='') @@ -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, diff --git a/tests.branching/petrify.script b/tests.branching/petrify.script index 3134ab66..fed8e965 100755 --- a/tests.branching/petrify.script +++ b/tests.branching/petrify.script @@ -32,7 +32,7 @@ git push --quiet origin HEAD "$SRCDIR/scripts/test-morph" edit hello-system hello-stratum goodbye (cd ../test:goodbye && git push --quiet origin HEAD) -"$SRCDIR/scripts/test-morph" old-petrify +"$SRCDIR/scripts/test-morph" petrify echo "Petrified:" cat hello-stratum.morph |