diff options
Diffstat (limited to 'morphlib')
-rw-r--r-- | morphlib/definitions_repo.py | 18 | ||||
-rw-r--r-- | morphlib/plugins/fix_ref_plugin.py | 58 |
2 files changed, 58 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) |