summaryrefslogtreecommitdiff
path: root/morphlib/plugins
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2012-10-17 13:43:31 +0100
committerSam Thursfield <sam.thursfield@codethink.co.uk>2012-10-18 11:51:00 +0100
commitc1d2fe7d811b15eb411b976b2619c44f46b8267e (patch)
treee410ecc95513da3cc78e4ff742ba3f62850e2418 /morphlib/plugins
parentcf7ed1cb79d4862c92261ac57a27b082a8f10f84 (diff)
downloadmorph-c1d2fe7d811b15eb411b976b2619c44f46b8267e.tar.gz
morph petrify: Avoid petrifying chunks that have already been edited
This change causes 'morph petrify' to avoid petrifying any chunk whose ref matches the current system branch, because it makes no sense to petrify something that is also being edited. It also improves efficiency slightly and adds warning where different systems point to different refs of the same stratum. A non-obvious effect of this is that if you try to petrify 'master', many of the chunks won't get petrified because they are built from 'master'. However, petrifying master makes no sense so I'm not sure that we need to worry.
Diffstat (limited to 'morphlib/plugins')
-rw-r--r--morphlib/plugins/branch_and_merge_plugin.py57
1 files changed, 39 insertions, 18 deletions
diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py
index 384f0550..050410d4 100644
--- a/morphlib/plugins/branch_and_merge_plugin.py
+++ b/morphlib/plugins/branch_and_merge_plugin.py
@@ -722,7 +722,8 @@ class BranchAndMergePlugin(cliapp.Plugin):
Strata refs are not petrified, because they must all be edited to set
the new chunk refs, which requires branching them all for the current
branch - so they will not be updated outside of the user's control in
- any case.
+ any case. Chunks that have already been edited on the current branch
+ are also not petrified.
'''
@@ -733,9 +734,11 @@ class BranchAndMergePlugin(cliapp.Plugin):
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)
-
self.lrc, self.rrc = morphlib.util.new_repo_caches(self.app)
+ # We must first get the full set of strata. One same stratum may be
+ # in multiple systems and each system may use a different ref.
+ strata = {}
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)
@@ -743,24 +746,42 @@ class BranchAndMergePlugin(cliapp.Plugin):
continue
for stratum_info in morphology['strata']:
- repo_dir = self.edit_stratum(
- branch, branch_path, root_repo, root_repo_dir,
- stratum_info)
-
- stratum = self.load_morphology(repo_dir, stratum_info['morph'])
-
- for chunk_info in stratum['chunks']:
- if 'unpetrify-ref' not in chunk_info:
- commit_sha1, tree_sha1 = self.app.resolve_ref(
- self.lrc, self.rrc, chunk_info['repo'],
- chunk_info['ref'],
- update=not self.app.settings['no-git-update'])
- chunk_info['unpetrify-ref'] = chunk_info['ref']
- chunk_info['ref'] = commit_sha1
- self.save_morphology(repo_dir, stratum_info['morph'], stratum)
-
+ key = (stratum_info['repo'], stratum_info['morph'])
+ if key in strata:
+ original_ref = strata[key]
+ if stratum_info['ref'] == branch:
+ strata[key] = branch
+ elif stratum_info['ref'] != original_ref:
+ if original_ref != branch:
+ self.app.output.write(
+ 'WARNING: not merging any differences from '
+ 'ref %s into %s of stratum %s\n' %
+ (stratum_info['ref'], original_ref,
+ stratum_info['morph']))
+ stratum_info['ref'] = branch
+ else:
+ strata[key] = stratum_info['ref']
+ stratum_info['ref'] = branch
self.save_morphology(root_repo_dir, name, morphology)
+ for (repo, morph), ref in strata.iteritems():
+ repo_dir = self.edit_stratum(
+ branch, branch_path, root_repo, root_repo_dir,
+ { 'repo': repo, 'ref': ref, 'morph': morph})
+
+ stratum = self.load_morphology(repo_dir, morph)
+
+ for chunk_info in stratum['chunks']:
+ if chunk_info['ref'] != branch and \
+ 'unpetrify-ref' not in chunk_info:
+ commit_sha1, tree_sha1 = self.app.resolve_ref(
+ self.lrc, self.rrc, chunk_info['repo'],
+ chunk_info['ref'],
+ update=not self.app.settings['no-git-update'])
+ chunk_info['unpetrify-ref'] = chunk_info['ref']
+ chunk_info['ref'] = commit_sha1
+ self.save_morphology(repo_dir, morph, stratum)
+
self.print_changelog('The following changes were made but have not '
'been comitted')