diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2012-09-19 18:04:16 +0100 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2012-09-21 16:06:08 +0100 |
commit | e0555e433ea6611d161aa31b10d621905c95c5ae (patch) | |
tree | 6b880ec82f003e85a2991ef28bc728c597fcd073 | |
parent | 0513d8ebcd7bff35d602719364374b71b152efd5 (diff) | |
download | morph-e0555e433ea6611d161aa31b10d621905c95c5ae.tar.gz |
morph petrify: Rewrite in the style of today
-rwxr-xr-x | morphlib/app.py | 5 | ||||
-rw-r--r-- | morphlib/plugins/branch_and_merge_plugin.py | 84 | ||||
-rwxr-xr-x | tests.branching/petrify.script | 3 | ||||
-rw-r--r-- | tests.branching/petrify.stdout | 3 |
4 files changed, 56 insertions, 39 deletions
diff --git a/morphlib/app.py b/morphlib/app.py index 42a35461..37e494af 100755 --- a/morphlib/app.py +++ b/morphlib/app.py @@ -225,12 +225,11 @@ class Morph(cliapp.Application): category=DeprecationWarning) return self.create_source_pool(*args) - def _resolveref(self, lrc, rrc, reponame, ref, update=True): + def resolve_ref(self, lrc, rrc, reponame, ref, update=True): '''Resolves commit and tree sha1s of the ref in a repo and returns it. If update is True then this has the side-effect of updating or cloning the repository into the local repo cache. - ''' absref = None if lrc.has_repo(reponame): @@ -263,7 +262,7 @@ class Morph(cliapp.Application): while queue: reponame, ref, filename = queue.popleft() - absref, tree = self._resolveref(lrc, rrc, reponame, ref, update) + absref, tree = self.resolve_ref(lrc, rrc, reponame, ref, update) morphology = morph_factory.get_morphology( reponame, absref, filename) visit(reponame, ref, filename, absref, tree, morphology) diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py index cf54e2e4..9594436b 100644 --- a/morphlib/plugins/branch_and_merge_plugin.py +++ b/morphlib/plugins/branch_and_merge_plugin.py @@ -37,8 +37,6 @@ class BranchAndMergePlugin(cliapp.Plugin): self.init_changelog() def enable(self): - self.app.add_subcommand('petrify', self.petrify, - arg_synopsis='STRATUM...') self.app.add_subcommand('init', self.init, arg_synopsis='[DIR]') self.app.add_subcommand('workspace', self.workspace, arg_synopsis='') @@ -54,6 +52,7 @@ class BranchAndMergePlugin(cliapp.Plugin): arg_synopsis='BRANCH') self.app.add_subcommand('edit', self.edit, arg_synopsis='SYSTEM STRATUM [CHUNK]') + self.app.add_subcommand('petrify', self.petrify) self.app.add_subcommand('build', self.build, arg_synopsis='SYSTEM') self.app.add_subcommand('foreach', self.foreach, @@ -319,37 +318,6 @@ class BranchAndMergePlugin(cliapp.Plugin): if max_subdirs > 0 and len(subdirs) > max_subdirs: break - def petrify(self, args): - '''Make refs to chunks be absolute SHA-1s.''' - - app = self.app - cache = morphlib.util.new_repo_caches(app)[0] - - for morphology_name in args: - filename = morphology_name + '.morph' - with open(filename) as f: - morph = morphlib.morph2.Morphology(f.read()) - - if morph['kind'] != 'stratum': - app.status(msg='Not a stratum: %(filename)s', - filename=filename) - continue - - app.status(msg='Petrifying %(filename)s', filename=filename) - - for source in morph['chunks']: - reponame = source.get('repo', source['name']) - ref = source['ref'] - app.status(msg='Looking up sha1 for %(repo_name)s %(ref)s', - repo_name=reponame, - ref=ref) - assert cache.has_repo(reponame) - repo = cache.get_repo(reponame) - source['ref'], tree = repo.resolve_ref(ref) - - with morphlib.savefile.SaveFile(filename, 'w') as f: - morph.write_to_file(f) - def init(self, args): '''Initialize a workspace directory.''' @@ -588,6 +556,56 @@ class BranchAndMergePlugin(cliapp.Plugin): self.print_changelog('The following changes were made but have not ' 'been comitted') + def petrify(self, args): + '''Convert all chunk refs in a branch to be fixed SHA1s + + This allows the developer to work on a feature in isolation, without + changes from upstream breaking the world under their feet. + + Strata refs are not petrified, because they must all be edited to set + the new chunk refs, which requires branching them all for the current + branch - so they will not be updated outside of the user's control in + any case. + + ''' + + if len(args) != 0: + raise cliapp.AppException('morph petrify takes no arguments') + + workspace = self.deduce_workspace() + branch, branch_path = self.deduce_system_branch() + root_repo = self.get_branch_config(branch_path, 'branch.root') + root_repo_dir = self.find_repository(branch_path, root_repo) + + lrc, rrc = morphlib.util.new_repo_caches(self.app) + + for f in glob.glob(os.path.join(root_repo_dir, '*.morph')): + name = os.path.basename(f)[:-len('.morph')] + morphology = self.load_morphology(root_repo_dir, name) + if morphology['kind'] != 'system': + continue + + for stratum_info in morphology['strata']: + if stratum_info['repo'] != root_repo: + raise ('not yet implemented- need to morph edit this stratum') + repo_dir = root_repo_dir + + stratum = self.load_morphology(repo_dir, stratum_info['morph']) + + for chunk_info in stratum['chunks']: + if 'unpetrify-ref' not in chunk_info: + commit_sha1, tree_sha1 = self.app.resolve_ref( + lrc, rrc, chunk_info['repo'], chunk_info['ref'], + update=not self.app.settings['no-git-update']) + chunk_info['unpetrify-ref'] = chunk_info['ref'] + chunk_info['ref'] = commit_sha1 + self.save_morphology(repo_dir, stratum_info['morph'], stratum) + + self.save_morphology(root_repo_dir, name, morphology) + + self.print_changelog('The following changes were made but have not ' + 'been comitted') + def load_morphology_pair(self, repo_dir, ref, name): '''Load two versions of a morphology and check for major conflicts diff --git a/tests.branching/petrify.script b/tests.branching/petrify.script index 30f9f5df..fe516ffb 100755 --- a/tests.branching/petrify.script +++ b/tests.branching/petrify.script @@ -30,9 +30,8 @@ fi cd "$DATADIR/workspace" "$SRCDIR/scripts/test-morph" init -"$SRCDIR/scripts/test-morph" update-gits baserock:morphs master hello-stratum "$SRCDIR/scripts/test-morph" checkout baserock:morphs master cd master/baserock:morphs -"$SRCDIR/scripts/test-morph" petrify hello-stratum +"$SRCDIR/scripts/test-morph" petrify cat hello-stratum.morph diff --git a/tests.branching/petrify.stdout b/tests.branching/petrify.stdout index eecd51ce..4aa2b2ea 100644 --- a/tests.branching/petrify.stdout +++ b/tests.branching/petrify.stdout @@ -6,7 +6,8 @@ "name": "hello", "repo": "baserock:hello", "ref": "f4d032b42c0134e67bdf19a43fa99072493667d7", - "build-depends": [] + "build-depends": [], + "unpetrify-ref": "master" } ] } |