summaryrefslogtreecommitdiff
path: root/morphlib/morphset.py
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2013-09-20 14:38:26 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2013-09-24 10:26:03 +0000
commite664f2000e233c1f05657e7e2dd85e8a182deb0e (patch)
treee3ae31c3282124188f1c81e3a7d50b1b7360c6a3 /morphlib/morphset.py
parent924e2192ae3de5974ee058c0ea9c180f2e46d78e (diff)
downloadmorph-e664f2000e233c1f05657e7e2dd85e8a182deb0e.tar.gz
MorphSet: Add petrify_chunks() method
petrify_chunks handles regular petrification and branch_from_image's petrifying to another point in time. It is given the values to petrify to, instead of doing the ref resolution itself, since now it will consistently resolve refs to the same thing, and a different resolution can be passed in to petrify to another point in time. It only petrifies chunks, since petrifying strata and systems is a more complex operation that is not currently handled anyway.
Diffstat (limited to 'morphlib/morphset.py')
-rw-r--r--morphlib/morphset.py32
1 files changed, 31 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)
+