summaryrefslogtreecommitdiff
path: root/morphlib
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2012-09-20 17:19:54 +0100
committerSam Thursfield <sam.thursfield@codethink.co.uk>2012-09-21 16:06:08 +0100
commit3a8ee82f912399739b44688b0f71b04daa8c5c68 (patch)
tree17dbaebe2c382731bc9b32de7583bf6f6b38e913 /morphlib
parente0555e433ea6611d161aa31b10d621905c95c5ae (diff)
downloadmorph-3a8ee82f912399739b44688b0f71b04daa8c5c68.tar.gz
Add 'morph unpetrify'
Tested in the petrify test, to avoid duplication.
Diffstat (limited to 'morphlib')
-rw-r--r--morphlib/plugins/branch_and_merge_plugin.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py
index 9594436b..66109747 100644
--- a/morphlib/plugins/branch_and_merge_plugin.py
+++ b/morphlib/plugins/branch_and_merge_plugin.py
@@ -53,6 +53,7 @@ class BranchAndMergePlugin(cliapp.Plugin):
self.app.add_subcommand('edit', self.edit,
arg_synopsis='SYSTEM STRATUM [CHUNK]')
self.app.add_subcommand('petrify', self.petrify)
+ self.app.add_subcommand('unpetrify', self.unpetrify)
self.app.add_subcommand('build', self.build,
arg_synopsis='SYSTEM')
self.app.add_subcommand('foreach', self.foreach,
@@ -606,6 +607,49 @@ class BranchAndMergePlugin(cliapp.Plugin):
self.print_changelog('The following changes were made but have not '
'been comitted')
+ def unpetrify(self, args):
+ '''Reverse the process of petrification
+
+ Unpetrifies all chunk refs in a branch that were previously petrified.
+ Makes no attempt to 'unedit' strata that were branched solely so they
+ could be petrified.
+
+ If a branch is petrified and then branched from, the child branch can
+ be unpetrified independently of the parent.
+
+ '''
+
+ if len(args) != 0:
+ raise cliapp.AppException('morph unpetrify takes no arguments')
+
+ workspace = self.deduce_workspace()
+ branch, branch_path = self.deduce_system_branch()
+ root_repo = self.get_branch_config(branch_path, 'branch.root')
+ root_repo_dir = self.find_repository(branch_path, root_repo)
+
+ for f in glob.glob(os.path.join(root_repo_dir, '*.morph')):
+ name = os.path.basename(f)[:-len('.morph')]
+ morphology = self.load_morphology(root_repo_dir, name)
+ if morphology['kind'] != 'system':
+ continue
+
+ for stratum_info in morphology['strata']:
+ repo_dir = self.edit_stratum(
+ branch, branch_path, root_repo_dir, stratum_info)
+
+ stratum = self.load_morphology(repo_dir, stratum_info['morph'])
+
+ for chunk_info in stratum['chunks']:
+ if 'unpetrify-ref' in chunk_info:
+ chunk_info['ref'] = chunk_info['unpetrify-ref']
+ del chunk_info['unpetrify-ref']
+ self.save_morphology(repo_dir, stratum_info['morph'], stratum)
+
+ self.save_morphology(root_repo_dir, name, morphology)
+
+ self.print_changelog('The following changes were made but have not '
+ 'been comitted')
+
def load_morphology_pair(self, repo_dir, ref, name):
'''Load two versions of a morphology and check for major conflicts