summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--morphlib/morphset.py32
-rw-r--r--morphlib/morphset_tests.py17
2 files changed, 48 insertions, 1 deletions
diff --git a/morphlib/morphset.py b/morphlib/morphset.py
index 10583326..dad3c834 100644
--- a/morphlib/morphset.py
+++ b/morphlib/morphset.py
@@ -214,7 +214,7 @@ class MorphologySet(object):
def wanted_spec(m, kind, spec):
return (spec['repo'], spec['ref']) not in known
- def process_spec(spec):
+ def process_spec(m, kind, spec):
known.add((spec['repo'], spec['ref']))
return False
@@ -222,3 +222,33 @@ class MorphologySet(object):
return known
+ def petrify_chunks(self, resolutions):
+ '''Update _every_ chunk's ref to the value resolved in resolutions.
+
+ `resolutions` must be a {(repo, ref): resolved_ref}
+
+ This is subtly different to change_ref, since that works on
+ changing a single spec including its filename, and the morphology
+ those specs refer to, while petrify_chunks is interested in changing
+ _all_ the refs.
+
+ '''
+
+ def wanted_chunk_spec(m, kind, spec):
+ # Do not attempt to petrify non-chunk specs.
+ # This is not handled by previous implementations, and
+ # the details are tricky.
+ if not (m['kind'] == 'stratum' and kind == 'chunks'):
+ return
+ ref = spec['ref']
+ return (not morphlib.git.is_valid_sha1(ref)
+ and (spec['repo'], ref) in resolutions)
+
+ def process_chunk_spec(m, kind, spec):
+ tup = (spec['repo'], spec['ref'])
+ spec['unpetrify-ref'] = spec['ref']
+ spec['ref'] = resolutions[tup]
+ return True
+
+ self._traverse_specs(process_chunk_spec, wanted_chunk_spec)
+
diff --git a/morphlib/morphset_tests.py b/morphlib/morphset_tests.py
index 24f3d91a..baa3e103 100644
--- a/morphlib/morphset_tests.py
+++ b/morphlib/morphset_tests.py
@@ -191,3 +191,20 @@ class MorphologySetTests(unittest.TestCase):
self.assertEqual(sorted(self.morphs.list_refs()),
[('test:foo-chunk', 'master'),
('test:morphs', 'master')])
+
+ def test_petrify_chunks(self):
+ # TODO: test petrifying a larger morphset
+ self.morphs.add_morphology(self.system)
+ self.morphs.add_morphology(self.stratum)
+ self.morphs.petrify_chunks({('test:foo-chunk', 'master'): '0'*40})
+ self.assertEqual(
+ self.stratum['chunks'],
+ [
+ {
+ 'repo': 'test:foo-chunk',
+ 'ref': '0'*40,
+ 'morph': 'foo-chunk',
+ 'unpetrify-ref': 'master',
+ }
+ ])
+