summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2013-09-23 16:23:49 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2013-09-24 10:34:27 +0000
commite59d4347f511412e2162d97eca3fc65bf1c3b978 (patch)
tree452a31af4578099e4540f68218c69d684e55040d
parente664f2000e233c1f05657e7e2dd85e8a182deb0e (diff)
downloadmorph-e59d4347f511412e2162d97eca3fc65bf1c3b978.tar.gz
MorphSet: Add method for changing refs en-masse
This is used to change all the refs of the morphologies in the root repository to point to the system branch instead.
-rw-r--r--morphlib/morphset.py20
-rw-r--r--morphlib/morphset_tests.py14
2 files changed, 34 insertions, 0 deletions
diff --git a/morphlib/morphset.py b/morphlib/morphset.py
index dad3c834..2343cbae 100644
--- a/morphlib/morphset.py
+++ b/morphlib/morphset.py
@@ -222,6 +222,26 @@ class MorphologySet(object):
return known
+ def repoint_refs(self, repo_url, new_ref):
+ '''Change all specs which refer to (repo, *) to (repo, new_ref).
+
+ This is stunningly similar to change_ref, with the exception of
+ ignoring the morphology name and ref fields.
+
+ It is intended to be used before chunks are petrified
+
+ '''
+ def wanted_spec(m, kind, spec):
+ return spec['repo'] == repo_url
+
+ def process_spec(m, kind, spec):
+ if 'unpetrify-ref' not in spec:
+ spec['unpetrify-ref'] = spec['ref']
+ spec['ref'] = new_ref
+ return True
+
+ self._traverse_specs(process_spec, wanted_spec)
+
def petrify_chunks(self, resolutions):
'''Update _every_ chunk's ref to the value resolved in resolutions.
diff --git a/morphlib/morphset_tests.py b/morphlib/morphset_tests.py
index baa3e103..fa8fa030 100644
--- a/morphlib/morphset_tests.py
+++ b/morphlib/morphset_tests.py
@@ -192,6 +192,20 @@ class MorphologySetTests(unittest.TestCase):
[('test:foo-chunk', 'master'),
('test:morphs', 'master')])
+ def test_repoint_refs(self):
+ self.morphs.add_morphology(self.system)
+ self.morphs.add_morphology(self.stratum)
+ self.morphs.repoint_refs('test:morphs', 'test')
+ self.assertEqual(self.system['strata'],
+ [
+ {
+ 'morph': 'foo-stratum',
+ 'ref': 'test',
+ 'repo': 'test:morphs',
+ 'unpetrify-ref': 'master',
+ }
+ ])
+
def test_petrify_chunks(self):
# TODO: test petrifying a larger morphset
self.morphs.add_morphology(self.system)