summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-08-04 23:25:56 +0000
committerPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-08-04 23:35:21 +0000
commite2ae92ba6352cc44acae9ff4f2cd57d104009388 (patch)
treee5da9ca902b190c90fe23ebb98eb0457e972bd14
parent61eb7d04e2cd11e56affc1a49feae5145e825ad5 (diff)
downloadmorph-e2ae92ba6352cc44acae9ff4f2cd57d104009388.tar.gz
Add fix and refresh, but refresh uses tag refs
Change-Id: I853be29a778a198751f7ab948009122a633aa899
-rw-r--r--morphlib/definitions_repo.py18
-rw-r--r--morphlib/plugins/fix_ref_plugin.py58
-rw-r--r--without-test-modules1
3 files changed, 59 insertions, 18 deletions
diff --git a/morphlib/definitions_repo.py b/morphlib/definitions_repo.py
index a30c5a7c..2228efe8 100644
--- a/morphlib/definitions_repo.py
+++ b/morphlib/definitions_repo.py
@@ -253,16 +253,26 @@ class DefinitionsRepo(gitdir.GitDirectory):
return loader
+
+ def load_morphology_file(self, filename, loader=None, mf=None):
+ loader = loader or self.get_morphology_loader()
+ mf = mf or morphlib.morphologyfinder.MorphologyFinder(self)
+
+ text = mf.read_file(filename)
+ m = loader.load_from_string(text, filename=filename)
+ m.repo_url = self.remote_url
+ m.ref = self.HEAD
+
+ return m
+
+
def load_all_morphologies(self, loader=None):
loader = loader or self.get_morphology_loader()
mf = morphlib.morphologyfinder.MorphologyFinder(self)
for filename in (f for f in mf.list_morphologies()
if not self.is_symlink(f)):
- text = mf.read_file(filename)
- m = loader.load_from_string(text, filename=filename)
- m.repo_url = self.remote_url
- m.ref = self.HEAD
+ m = self.load_morphology_file(filename, loader, mf)
yield m
def relative_path(self, path, cwd='.'):
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)
diff --git a/without-test-modules b/without-test-modules
index d819c2c9..c654385a 100644
--- a/without-test-modules
+++ b/without-test-modules
@@ -20,6 +20,7 @@ morphlib/writeexts.py
morphlib/cmdline_parse_utils.py
morphlib/plugins/list_artifacts_plugin.py
morphlib/plugins/trovectl_plugin.py
+morphlib/plugins/fix_ref_plugin.py
morphlib/plugins/get_chunk_details_plugin.py
morphlib/plugins/gc_plugin.py
morphlib/plugins/print_architecture_plugin.py