diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2012-04-04 19:58:23 +0100 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2012-04-04 19:58:23 +0100 |
commit | 366974980fe6014a6c8f0246514294d277b7f7dc (patch) | |
tree | 6683b01587b79d80755bea0f68571f8874df0e70 /morph | |
parent | a2d24c6f761f814404094709d8661d021e3df3ae (diff) | |
download | morph-366974980fe6014a6c8f0246514294d277b7f7dc.tar.gz |
Add petrify subcommand
Diffstat (limited to 'morph')
-rwxr-xr-x | morph | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -17,6 +17,7 @@ import cliapp +import json import logging import os @@ -579,6 +580,33 @@ class Morph(cliapp.Application): repo_dir = os.path.join(mine, this_branch, basename) self.runcmd(['git', 'pull', pull_from, other_branch], cwd=repo_dir) + def cmd_petrify(self, args): + '''Make refs to chunks be absolute SHA-1s.''' + + morph_loader = MorphologyLoader(self.settings) + source_manager = morphlib.sourcemanager.SourceManager(self, + update=not self.settings['no-git-update']) + + for filename in args: + with open(filename) as f: + morph = json.load(f) + + if morph['kind'] != 'stratum': + self.msg('Not a stratum: %s' % filename) + continue + + self.msg('Petrifying %s' % filename) + + for source in morph['sources']: + repo = source.get('repo', source['name']) + ref = source['ref'] + self.msg('.. looking up sha1 for %s %s' % (repo, ref)) + treeish = source_manager.get_treeish(repo, ref) + source['ref'] = treeish.sha1 + + with open(filename, 'w') as f: + json.dump(morph, f, indent=2) + def msg(self, msg): '''Show a message to the user about what is going on.''' logging.debug(msg) |