From 13fa0d15645e2d21c9c41d1f6c481233e24a8cfd Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Mon, 23 Nov 2015 17:07:24 +0000 Subject: Prepare the removal of workspace and system branches code Change-Id: Id470c7a77a47c89118a5d9d0d23b2206d8a839e4 --- morphlib/__init__.py | 2 - morphlib/buildbranch.py | 125 ++++++--------------------- morphlib/definitions_repo.py | 103 +++------------------- morphlib/extensions.py | 9 +- morphlib/plugins/build_plugin.py | 15 ++-- morphlib/plugins/deploy_plugin.py | 2 +- morphlib/plugins/get_chunk_details_plugin.py | 2 +- morphlib/plugins/get_repo_plugin.py | 2 +- morphlib/plugins/show_build_log_plugin.py | 2 +- morphlib/util.py | 6 +- 10 files changed, 53 insertions(+), 215 deletions(-) (limited to 'morphlib') diff --git a/morphlib/__init__.py b/morphlib/__init__.py index 09775773..2ea657e7 100644 --- a/morphlib/__init__.py +++ b/morphlib/__init__.py @@ -85,9 +85,7 @@ import sourcepool import sourceresolver import stagingarea import stopwatch -import sysbranchdir import util -import workspace import yamlparse diff --git a/morphlib/buildbranch.py b/morphlib/buildbranch.py index 9937f9ca..455438ed 100644 --- a/morphlib/buildbranch.py +++ b/morphlib/buildbranch.py @@ -34,32 +34,15 @@ class BuildBranchCleanupError(cliapp.AppException): % locals()) -class NoReposError(cliapp.AppException): - def __init__(self, bb, ignored): - self.bb = bb - cliapp.AppException.__init__( - self, "No repos were found in system branch (ignored %i which " - "didn't have the right morph.uuid setting)" % (ignored)) - - - class BuildBranch(object): - '''Represent the sources modified in a system branch. + '''Represent the sources modified in a definitions repo. - This is an abstraction on top of SystemBranchDirectories, providing - the ability to add uncommitted changes to the temporary build branch, - push temporary build branches and retrieve the correct repository - URI and ref to build the system. + This provides the ability to add uncommitted changes to a temporary build + branch. ''' - # TODO: This currently always uses the temporary build ref. It - # would be better to not use local repositories and temporary refs, - # so building from a workspace appears to be identical to using - # `morph build-morphology` - def __init__(self, build_ref_prefix, build_uuid, system_branch=None, - definitions_repo=None): - self._sb = system_branch + def __init__(self, build_ref_prefix, build_uuid, definitions_repo=None): self._definitions_repo = definitions_repo self._cleanup = collections.deque() @@ -67,73 +50,25 @@ class BuildBranch(object): self._td = fs.tempfs.TempFS() self._register_cleanup(self._td.close) - if system_branch: - # Old-style Morph system branch which may involve multiple repos. - # - # Temporary refs will look like this: - # - # $build-ref-prefix/$branch_uuid/$repo_uuid. For - # - # For example: - # - # baserock/builds/f0b21fe240b244edb7e4142b6e201658/8df11f234ab... - self._to_push = self.collect_repos_for_system_branch( - system_branch, build_ref_prefix) - - branch_root = system_branch.get_config('branch.root') - self._root = system_branch.definitions_repo - _, self._root_index = self._to_push[self._root] - else: - # Temporary branch of only a definitions.git repo. - # - # Temporary ref will look like this: - # - # $build-ref-prefix/$HEAD/$build_uuid - # - # For example: - # - # baserock/builds/master/f0b21fe240b244edb7e4142b6e201658 - ref = definitions_repo.HEAD - build_ref = os.path.join( - 'refs/heads', build_ref_prefix, ref, build_uuid) - - index = definitions_repo.get_index(self._td.getsyspath('index')) - head_tree = definitions_repo.resolve_ref_to_tree(ref) - index.set_to_tree(head_tree) - - self._to_push[definitions_repo] = (build_ref, index) - self._root, self._root_index = definitions_repo, index - - def collect_repos_for_system_branch(self, sb, build_ref_prefix): - branch_uuid = sb.get_config('branch.uuid') - to_push = dict() - for count, gd in enumerate(sb.list_git_directories()): - try: - repo_uuid = gd.get_config('morph.uuid') - except cliapp.AppException: - # Not a repository cloned by morph, ignore - continue - - if gd.dirname == sb.definitions_repo.dirname: - # Avoid creating a new GitDirectory instance for the - # definitions repo, which we already have a DefinitionsRepo - # instance for. This means that to_push[sb.definitions_repo] - # returns the expected results. - gd = sb.definitions_repo - - build_ref = os.path.join('refs/heads', build_ref_prefix, - branch_uuid, repo_uuid) - # index is commit of workspace + uncommitted changes may want - # to change to use user's index instead of user's commit, - # so they can add new files first - index = gd.get_index(self._td.getsyspath(repo_uuid)) - index.set_to_tree(gd.resolve_ref_to_tree(gd.HEAD)) - to_push[gd] = (build_ref, index) - - if len(to_push) == 0: - raise NoReposError(self, count) - - return to_push + # Temporary branch of only a definitions.git repo. + # + # Temporary ref will look like this: + # + # $build-ref-prefix/$HEAD/$build_uuid + # + # For example: + # + # baserock/builds/master/f0b21fe240b244edb7e4142b6e201658 + ref = definitions_repo.HEAD + build_ref = os.path.join( + 'refs/heads', build_ref_prefix, ref, build_uuid) + + index = definitions_repo.get_index(self._td.getsyspath('index')) + head_tree = definitions_repo.resolve_ref_to_tree(ref) + index.set_to_tree(head_tree) + + self._to_push[definitions_repo] = (build_ref, index) + self._root, self._root_index = definitions_repo, index def _register_cleanup(self, func, *args, **kwargs): self._cleanup.append((func, args, kwargs)) @@ -174,9 +109,6 @@ class BuildBranch(object): ''' commit_message = 'Morph build %s\n' % uuid - if self._sb: - commit_message += "\nSystem branch: %s\n'" % \ - self._sb.system_branch_name author_name = name committer_name = 'Morph (on behalf of %s)' % name author_email = committer_email = email @@ -247,17 +179,12 @@ class BuildBranch(object): @property def root_repo_url(self): '''URI of the repository that systems may be found in.''' - if self._sb: - return self._sb.get_config('branch.root') - else: - return self._definitions_repo.remote_url + + return self._definitions_repo.remote_url @property def root_ref(self): - if self._sb: - return self._sb.get_config('branch.name') - else: - return self._definitions_repo.HEAD + return self._definitions_repo.HEAD @property def root_commit(self): diff --git a/morphlib/definitions_repo.py b/morphlib/definitions_repo.py index 6d14fcbb..e2bfd829 100644 --- a/morphlib/definitions_repo.py +++ b/morphlib/definitions_repo.py @@ -45,20 +45,11 @@ class FileOutsideRepo(cliapp.AppException): class DefinitionsRepo(gitdir.GitDirectory): '''Represents a definitions.git repo checked out locally. - This can either be a normal Git clone, or a Git clone inside an old-style - Morph workspace. - - If the repo is inside a Morph workspace, certain behaviours are enabled for - consistency with old versions of Morph. See function documentation for - details. - ''' - def __init__(self, path, search_for_root=False, system_branch=None, - allow_missing=False): + def __init__(self, path, search_for_root=False, allow_missing=False): morphlib.gitdir.GitDirectory.__init__( self, path, search_for_root=search_for_root, allow_missing=allow_missing) - self.system_branch = system_branch @property def HEAD(self): @@ -67,32 +58,14 @@ class DefinitionsRepo(gitdir.GitDirectory): In a normal Git checkout, this will return whatever ref is checked out as the working tree (HEAD, in Git terminology). - If this definitions repo is in an old-style Morph system branch, it - will return the ref that was checked out with `morph branch` or `morph - checkout`, which will NOT necessarily correspond to what is checked out - in the Git repo. - ''' - if self.system_branch is None: - return morphlib.gitdir.GitDirectory.HEAD.fget(self) - else: - return self.system_branch.get_config('branch.name') + return morphlib.gitdir.GitDirectory.HEAD.fget(self) @property def remote_url(self): - '''Return the 'upstream' URL of this repo. - - If this repo is inside a Morph system branch checkout, this will be - whatever URL was passed to `morph checkout` or `morph branch`. That may - be a keyed URL such as baserock:baserock/definitions. + '''Return the 'upstream' URL of this repo.''' - Otherwise, the fetch URL of the 'origin' remote is returned. - - ''' - if self.system_branch is None: - return self.get_remote('origin').get_fetch_url() - else: - return self.system_branch.root_repository_url + return self.get_remote('origin').get_fetch_url() def branch_with_local_changes(self, uuid, push=True, build_ref_prefix=None, git_user_name=None, git_user_email=None, @@ -118,11 +91,7 @@ class DefinitionsRepo(gitdir.GitDirectory): status_cb(msg='Looking for uncommitted changes (pass ' '--local-changes=ignore to skip)') - if self.system_branch: - bb = morphlib.buildbranch.BuildBranch( - build_ref_prefix, uuid, system_branch=self.system_branch) - else: - bb = morphlib.buildbranch.BuildBranch( + bb = morphlib.buildbranch.BuildBranch( build_ref_prefix, uuid, definitions_repo=self) pbb = morphlib.buildbranch.pushed_build_branch( @@ -365,22 +334,7 @@ class DefinitionsRepoWithApp(DefinitionsRepo): status_cb=self.app.status, update_repos=(not self.app.settings['no-git-update'])) - -def _system_branch(path): - '''Open an old-style Morph system branch in an old-style Morph workspace. - - Raises morphlib.workspace.NotInWorkspace or - morphlib.sysbranchdir.NotInSystemBranch if either workspace or - system-branch are not found. - - ''' - morphlib.workspace.open(path) - system_branch = morphlib.sysbranchdir.open_from_within(path) - return system_branch - - -def _local_definitions_repo(path, search_for_root, system_branch=None, - app=None): +def _local_definitions_repo(path, search_for_root, app=None): '''Open a local Git repo containing Baserock definitions, at 'path'. Raises morphlib.gitdir.NoGitRepoError if there is no repo found at 'path'. @@ -388,15 +342,14 @@ def _local_definitions_repo(path, search_for_root, system_branch=None, ''' if app: gitdir = morphlib.definitions_repo.DefinitionsRepoWithApp( - app, path, search_for_root=search_for_root, - system_branch=system_branch) + app, path, search_for_root=search_for_root) else: gitdir = morphlib.definitions_repo.DefinitionsRepo( - path, search_for_root=search_for_root, system_branch=system_branch) + path, search_for_root=search_for_root) return gitdir -def open(path, search_for_root=False, search_workspace=False, app=None): +def open(path, search_for_root=False, app=None): '''Open the definitions.git repo at 'path'. Returns a DefinitionsRepo instance. @@ -408,40 +361,12 @@ def open(path, search_for_root=False, search_workspace=False, app=None): path entered manually by the user, you may want to set this to False to avoid confusion. - If 'search_workspace' is True, this function will check if 'path' is inside - an old-style Morph workspace. If it is, there will be two changes to its - behaviour. First, the definitions.git will be returned even if 'path' is - inside a different repo, because the old-style Morph system branch will - identify which is the correct definitions.git repo. Second, the value - returned for HEAD will not be the ref checked out in the definitions.git - repo, but rather the ref that was passed to `morph checkout` or `morph - branch` when the system branch was originally checked out. This behaviour - may seem confusing if you are new to Morph, but in fact Morph forced users - to work this way for several years, so we need preserve this behaviour for - a while to avoid disrupting existing users. - ''' - sb = None - - if search_workspace: - try: - sb = _system_branch(path) - except (morphlib.workspace.NotInWorkspace, - morphlib.sysbranchdir.NotInSystemBranch): - logging.debug('Did not find old-style Morph system branch') - if sb: - path = sb.get_git_directory_name(sb.root_repository_url) + try: definitions_repo = _local_definitions_repo( - path=path, search_for_root=False, system_branch=sb, app=app) - logging.info('Opened definitions repo %s from Morph system branch %s', - definitions_repo, sb) - else: - try: - definitions_repo = _local_definitions_repo( - path, search_for_root=search_for_root, app=app) - except morphlib.gitdir.NoGitRepoError: - raise DefinitionsRepoNotFound() - logging.info('Opened definitions repo %s', definitions_repo) - + path, search_for_root=search_for_root, app=app) + except morphlib.gitdir.NoGitRepoError: + raise DefinitionsRepoNotFound() + logging.info('Opened definitions repo %s', definitions_repo) return definitions_repo diff --git a/morphlib/extensions.py b/morphlib/extensions.py index b2a015b1..7290f7c1 100644 --- a/morphlib/extensions.py +++ b/morphlib/extensions.py @@ -24,7 +24,6 @@ import tempfile import cliapp import morphlib -import sysbranchdir class ExtensionError(morphlib.Error): @@ -67,12 +66,10 @@ def _list_extensions(kind): repo_extension_filenames = [] try: definitions_repo = morphlib.definitions_repo.open( - '.', search_for_root=True, search_workspace=True) + '.', search_for_root=True) repo_extension_filenames = \ _list_repo_extension_filenames(definitions_repo, kind) - except (morphlib.workspace.NotInWorkspace, - sysbranchdir.NotInSystemBranch, - morphlib.definitions_repo.DefinitionsRepoNotFound): + except morphlib.definitions_repo.DefinitionsRepoNotFound: # Squash this and just return no system branch extensions pass morph_extension_filenames = _list_morph_extension_filenames(kind) @@ -129,7 +126,7 @@ class get_extension_filename(): try: ext_contents = _get_repo_extension_contents( self.definitions_repo, self.name, self.kind) - except (IOError, cliapp.AppException, sysbranchdir.NotInSystemBranch): + except (IOError, cliapp.AppException): # Not found: look for it in the Morph code. ext_filename = _get_morph_extension_filename(self.name, self.kind) if not os.path.exists(ext_filename): diff --git a/morphlib/plugins/build_plugin.py b/morphlib/plugins/build_plugin.py index 226a2c85..0da5d7cf 100644 --- a/morphlib/plugins/build_plugin.py +++ b/morphlib/plugins/build_plugin.py @@ -55,7 +55,7 @@ class BuildPlugin(cliapp.Plugin): return 'usage: morph %s %s' % (cmd, self.app.cmd_synopsis[cmd]) def distbuild_morphology(self, args): - '''Distbuild a system, outside of a system branch. + '''Distbuild a system without having to clone a definitions repo. Command line arguments: @@ -80,7 +80,7 @@ class BuildPlugin(cliapp.Plugin): self._distbuild(repo, ref, filename, component_names=component_names) def distbuild(self, args): - '''Distbuild a system image in the current system branch + '''Distbuild a system image in the current definitions repo Command line arguments: @@ -114,7 +114,7 @@ class BuildPlugin(cliapp.Plugin): raise cliapp.AppException(self._cmd_usage('distbuild')) definitions_repo = morphlib.definitions_repo.open( - '.', search_for_root=True, search_workspace=True, app=self.app) + '.', search_for_root=True, app=self.app) filename = args[0] filename = morphlib.util.sanitise_morphology_path(filename) @@ -180,7 +180,7 @@ class BuildPlugin(cliapp.Plugin): component_names=component_names) def build_morphology(self, args): - '''Build a system, outside of a system branch. + '''Build a system without having to clone a definitions repo. Command line arguments: @@ -190,11 +190,6 @@ class BuildPlugin(cliapp.Plugin): * `COMPONENT...` is the names of one or more chunks or strata to build. If none are given then the system at FILENAME is built. - You probably want `morph build` instead. However, in some - cases it is more convenient to not have to create a Morph - workspace and check out the relevant system branch, and only - just run the build. For those times, this command exists. - This subcommand does not automatically commit changes to a temporary branch, so you can only build from properly committed sources that have been pushed to the git server. @@ -272,7 +267,7 @@ class BuildPlugin(cliapp.Plugin): raise cliapp.AppException(self._cmd_usage('build')) definitions_repo = morphlib.definitions_repo.open( - '.', search_for_root=True, search_workspace=True, app=self.app) + '.', search_for_root=True, app=self.app) filename = args[0] filename = morphlib.util.sanitise_morphology_path(filename) diff --git a/morphlib/plugins/deploy_plugin.py b/morphlib/plugins/deploy_plugin.py index 89b88373..189222a8 100644 --- a/morphlib/plugins/deploy_plugin.py +++ b/morphlib/plugins/deploy_plugin.py @@ -335,7 +335,7 @@ class DeployPlugin(cliapp.Plugin): '/', 0) definitions_repo = morphlib.definitions_repo.open( - '.', search_for_root=True, search_workspace=True, app=self.app) + '.', search_for_root=True, app=self.app) cluster_filename = morphlib.util.sanitise_morphology_path(args[0]) cluster_filename = definitions_repo.relative_path(cluster_filename) diff --git a/morphlib/plugins/get_chunk_details_plugin.py b/morphlib/plugins/get_chunk_details_plugin.py index 90e71c52..e3b9220c 100644 --- a/morphlib/plugins/get_chunk_details_plugin.py +++ b/morphlib/plugins/get_chunk_details_plugin.py @@ -48,7 +48,7 @@ class GetChunkDetailsPlugin(cliapp.Plugin): '(see help)') definitions_repo = morphlib.definitions_repo.open( - '.', search_for_root=True, search_workspace=True, app=self.app) + '.', search_for_root=True, app=self.app) aliases = self.app.settings['repo-alias'] self.resolver = morphlib.repoaliasresolver.RepoAliasResolver(aliases) diff --git a/morphlib/plugins/get_repo_plugin.py b/morphlib/plugins/get_repo_plugin.py index c1cb6d0e..e8ebf229 100644 --- a/morphlib/plugins/get_repo_plugin.py +++ b/morphlib/plugins/get_repo_plugin.py @@ -125,7 +125,7 @@ class GetRepoPlugin(cliapp.Plugin): found = 0 definitions_repo = morphlib.definitions_repo.open( - '.', search_for_root=True, search_workspace=True, app=self.app) + '.', search_for_root=True, app=self.app) self.app.status(msg='Loading in all morphologies') for morph in definitions_repo.load_all_morphologies(): diff --git a/morphlib/plugins/show_build_log_plugin.py b/morphlib/plugins/show_build_log_plugin.py index f2a975c1..e6dbee96 100644 --- a/morphlib/plugins/show_build_log_plugin.py +++ b/morphlib/plugins/show_build_log_plugin.py @@ -59,7 +59,7 @@ class ShowBuildLog(cliapp.Plugin): morphlib.buildcommand.BuildCommand._validate_architecture = validate definitions_repo = morphlib.definitions_repo.open( - '.', search_for_root=True, search_workspace=True, app=self.app) + '.', search_for_root=True, app=self.app) source_pool_context = definitions_repo.source_pool( ref=definitions_repo.HEAD, system_filename=system) with source_pool_context as source_pool: diff --git a/morphlib/util.py b/morphlib/util.py index ec83df25..0ec071e4 100644 --- a/morphlib/util.py +++ b/morphlib/util.py @@ -359,11 +359,7 @@ def find_root(dirname, subdir_name): '''Find parent of a directory, at or above a given directory. The sought-after directory is indicated by the existence of a - subdirectory of the indicated name. For example, dirname might - be the current working directory of the process, and subdir_name - might be ".morph"; then the returned value would be the Morph - workspace root directory, which has a subdirectory called - ".morph". + subdirectory of the indicated name. Return path to desired directory, or None if not found. -- cgit v1.2.1