summaryrefslogtreecommitdiff
path: root/morphlib/plugins/fix_ref_plugin.py
diff options
context:
space:
mode:
Diffstat (limited to 'morphlib/plugins/fix_ref_plugin.py')
-rw-r--r--morphlib/plugins/fix_ref_plugin.py58
1 files changed, 44 insertions, 14 deletions
diff --git a/morphlib/plugins/fix_ref_plugin.py b/morphlib/plugins/fix_ref_plugin.py
index d06487f0..a1dca166 100644
--- a/morphlib/plugins/fix_ref_plugin.py
+++ b/morphlib/plugins/fix_ref_plugin.py
@@ -29,6 +29,8 @@ class FixRefPlugin(cliapp.Plugin):
self.app.add_subcommand(
'fix', self.fix, arg_synopsis='FIX YOUR REFS')
self.app.add_subcommand(
+ 'refresh', self.refresh, arg_synopsis='FIX YOUR REFS')
+ self.app.add_subcommand(
'unfix', self.unfix, arg_synopsis='UNFIX YOUR REFS')
def disable(self):
@@ -77,13 +79,40 @@ class FixRefPlugin(cliapp.Plugin):
# raise cliapp.AppException('morph petrify takes no arguments')
- filename = morphlib.util.sanitise_morphology_path(args[0])
+ def fix_ref(repo_cache, chunk):
+ repo = chunk.get('repo')
+ ref = chunk.get('ref')
+ if repo is None or ref is None:
+ return chunk
+ sha1, _ = repo_cache.resolve_ref_to_commit_and_tree(repo, ref)
+ if sha1 != chunk['ref']:
+ chunk['ref'] = sha1
+ chunk['unpetrify-ref'] = ref
+ return chunk
+
+ self._modify_refs(args, fix_ref)
+
+
+ def refresh(self, args):
+ def refresh_ref(repo_cache, chunk):
+ repo = chunk.get('repo')
+ ref = chunk.get('unpetrify-ref')
+ if repo is None or ref is None:
+ return chunk
+ sha1, _ = repo_cache.resolve_ref_to_commit_and_tree(repo, ref)
+ chunk['ref'] = sha1
+ return chunk
+
+ self._modify_refs(args, refresh_ref)
+
+ def _modify_refs(self, args, modifier):
definitions_repo = morphlib.definitions_repo.open(
'.', search_for_root=True, app=self.app)
loader = definitions_repo.get_morphology_loader()
- filename = definitions_repo.relative_path(filename, cwd='.')
+ repo_cache = morphlib.util.new_repo_cache(self.app)
+
# source_pool_context = definitions_repo.source_pool(
@@ -118,22 +147,23 @@ class FixRefPlugin(cliapp.Plugin):
del spec['submodules']
+ if len(args) > 0:
+ morphs = []
+ for arg in args:
+ filename = morphlib.util.sanitise_morphology_path(arg)
+ filename = definitions_repo.relative_path(filename, cwd='.')
+ morph = definitions_repo.load_morphology_file(filename, loader)
+ morphs.append(morph)
+ else:
+ morphs = definitions_repo.load_all_morphologies()
- for morph in definitions_repo.load_all_morphologies():
- print morph['name']
+ for morph in morphs:
if morph['kind'] != 'stratum':
continue
- # TODO for testing
- if morph['name'] != "build-essential":
- continue
+ print morph['name']
for chunk in morph['chunks']:
- repo = chunk.get('repo')
- ref = chunk.get('ref')
- if repo is None or ref is None:
- print "FAIL"
- continue
- chunk['ref'] = 'xxx'
- chunk['unpetrify-ref'] = ref
+ chunk = modifier(repo_cache, chunk)
+
unset_defaults(morph)
loader.save_to_file(morph.filename, morph)