summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-08-04 16:45:59 +0000
committerPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-08-04 16:45:59 +0000
commit0c33da01dcd98c56a14c7d8ae90b7d5a5fee99dd (patch)
tree5a1261efe3e837a83075b20dfdadc0b312bf63ae
parentd2792f5070a2d2fdd2bdedc41dd3b9a9893f1fcd (diff)
downloadmorph-0c33da01dcd98c56a14c7d8ae90b7d5a5fee99dd.tar.gz
begining
Change-Id: I0453930690b04eeba808b6bf46375c2a06df227e
-rw-r--r--morphlib/plugins/fix_ref_plugin.py (renamed from morphlib/plugins/fix_ref.py)121
1 files changed, 114 insertions, 7 deletions
diff --git a/morphlib/plugins/fix_ref.py b/morphlib/plugins/fix_ref_plugin.py
index 7e65647d..40130ad0 100644
--- a/morphlib/plugins/fix_ref.py
+++ b/morphlib/plugins/fix_ref_plugin.py
@@ -24,15 +24,17 @@ import morphlib
class FixRefPlugin(cliapp.Plugin):
- '''Add subcommands for handling workspaces and system branches.'''
def enable(self):
self.app.add_subcommand(
- 'fix', self.petrify, arg_synopsis='')
+ 'fix', self.fix, arg_synopsis='FIX YOUR REFS')
self.app.add_subcommand(
- 'unfix', self.unpetrify, arg_synopsis='')
+ 'unfix', self.unfix, arg_synopsis='UNFIX YOUR REFS')
- def petrify(self, args):
+ def disable(self):
+ pass
+
+ def fix(self, args):
'''Convert all chunk refs in a system branch to be fixed SHA1s.
This modifies all git commit references in system and stratum
@@ -71,8 +73,113 @@ class FixRefPlugin(cliapp.Plugin):
'''
- if args:
- raise cliapp.AppException('morph petrify takes no arguments')
+# if args:
+# raise cliapp.AppException('morph petrify takes no arguments')
+
+
+ filename = morphlib.util.sanitise_morphology_path(args[0])
+
+ 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='.')
+
+
+# source_pool_context = definitions_repo.source_pool(
+# definitions_repo.HEAD, filename)
+# with source_pool_context as source_pool:
+# bc = morphlib.buildcommand.BuildCommand(self.app)
+# root = bc.resolve_artifacts(source_pool)
+# print root
+ def unset_defaults(self, morphology):
+ '''If a field is equal to its default, delete it.
+
+ The morphology is assumed to be valid.
+
+ '''
+
+ kind = morphology['kind']
+ defaults = morphlib.morphloader._static_defaults[kind]
+ for key in defaults:
+ if key in morphology and morphology[key] == defaults[key]:
+ del morphology[key]
+ getattr(self, '_unset_%s_defaults' % kind)(morphology)
+
+
+ for morph in definitions_repo.load_all_morphologies():
+ print morph
+ print morph.filename
+
+ if morph['kind'] != 'stratum':
+ continue
+ 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
+ unset_defaults(morph)
+ loader.save_to_file(morph.filename, morph)
+
+
+ continue
+ # TODO: Handle refs that are only in workspace in general
+ if (repo == sb.root_repository_url
+ and ref == sb.system_branch_name):
+ continue
+ commit_sha1, tree_sha1 = self.app.resolve_ref(
+ lrc, rrc, repo, ref, update=update_repos)
+
+ def _load_all_sysbranch_morphologies(root):
+ '''Read in all the morphologies in the root repository.'''
+ self.app.status(msg='Loading in all morphologies')
+ morphs = morphlib.morphset.MorphologySet()
+ for source in set(a.source for a in root.walk()):
+ morphs.add_morphology(source)
+ return morphs
+
+ morphs = _load_all_sysbranch_morphologies(root)
+ for repo, ref in morphs.list_refs():
+ print repo
+ #print morphs
+
+
+ for source in set(a.source for a in root.walk()):
+ if source.morphology['kind'] != 'stratum':
+ continue
+
+ name = source.morphology['name']
+ print name
+ ref = source.original_ref
+ print ref
+ print source.morphology
+ unpetrify = source.morphology['unpetrify-ref']
+ print unpetrify
+
+
+ # Test that chunk has a sha1 ref
+ # TODO: Could allow either sha1 or existent tag.
+ if not morphlib.git.is_valid_sha1(ref):
+ warnings.warn('Chunk "{}" has non-sha1 ref: "{}"\n'
+ .format(name, ref))
+ certified = False
+
+ cached = self.repo_cache.get_updated_repo(source.repo_name, ref)
+
+ # Test that sha1 ref is anchored in a tag or branch,
+ # and thus not a candidate for removal on `git gc`.
+ if (morphlib.git.is_valid_sha1(ref) and
+ not len(cached.tags_containing_sha1(ref)) and
+ not len(cached.branches_containing_sha1(ref))):
+ warnings.warn('Chunk "{}" has unanchored ref: "{}"\n'
+ .format(name, ref))
+ certified = False
+
+
+###########
ws = morphlib.workspace.open('.')
sb = morphlib.sysbranchdir.open_from_within('.')
@@ -104,7 +211,7 @@ class FixRefPlugin(cliapp.Plugin):
# Write morphologies back out again.
self._save_dirty_morphologies(loader, sb, morphs.morphologies)
- def unpetrify(self, args):
+ def unfix(self, args):
'''Reverse the process of petrification.
This undoes the changes `morph petrify` did.