summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2013-09-03 16:35:36 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2013-09-05 14:38:26 +0000
commit1bedfa7749300da167808b837d2a8968df43eeb3 (patch)
treecccad4d945e4be1e48c4c7738c266a9c1d01cdc5
parent4db444d0fc239eb74d11e8ebcfb50aa3e79ad500 (diff)
downloadmorph-1bedfa7749300da167808b837d2a8968df43eeb3.tar.gz
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.
-rw-r--r--morphlib/plugins/branch_and_merge_new_plugin.py48
-rw-r--r--morphlib/plugins/branch_and_merge_plugin.py2
-rwxr-xr-xtests.branching/petrify.script2
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