summaryrefslogtreecommitdiff
path: root/morphlib/definitions_repo.py
diff options
context:
space:
mode:
authorTiago Gomes <tiago.gomes@codethink.co.uk>2015-11-25 12:15:02 +0000
committerBaserock Gerrit <gerrit@baserock.org>2015-12-11 16:56:39 +0000
commitca1ddcbc1a24e754a2e3d1dc5f3c46c56d0a60d5 (patch)
tree2b06da153298d1bd858fc3ab508ac8c3db385c3b /morphlib/definitions_repo.py
parentae13dbb318be7a6df1d5e11155996c72a4147706 (diff)
downloadmorph-ca1ddcbc1a24e754a2e3d1dc5f3c46c56d0a60d5.tar.gz
Cleanup buildbranch.py module
Now that we don't support system branches, we don't need to iterate over a list of repos to create temporary build branches, commit their local changes and push those branches. We only need to do this for the definitions repository itself. A bug is also fixed where the local build branch was not being deleted due a missing call to _register_cleanup() when commiting the changes. This commit also renames some functions to more clear names, and moves the logic on pushed_build_branch() to the definitions_repo module, the only place where it is used. Change-Id: Id86240d0c189245bed36bc46355be13d46498dbc
Diffstat (limited to 'morphlib/definitions_repo.py')
-rw-r--r--morphlib/definitions_repo.py54
1 files changed, 40 insertions, 14 deletions
diff --git a/morphlib/definitions_repo.py b/morphlib/definitions_repo.py
index e2bfd829..4c13abee 100644
--- a/morphlib/definitions_repo.py
+++ b/morphlib/definitions_repo.py
@@ -67,9 +67,10 @@ class DefinitionsRepo(gitdir.GitDirectory):
return self.get_remote('origin').get_fetch_url()
- def branch_with_local_changes(self, uuid, push=True, build_ref_prefix=None,
+ def branch_with_local_changes(self, build_uuid, push=True,
+ build_ref_prefix=None,
git_user_name=None, git_user_email=None,
- status_cb=None):
+ status_cb=lambda **kwargs: None):
'''Yield a branch that includes the user's local changes to this repo.
When operating on local repos, this isn't really necessary. But when
@@ -87,18 +88,43 @@ class DefinitionsRepo(gitdir.GitDirectory):
to only certain refs in some Git servers.
'''
- if status_cb:
- status_cb(msg='Looking for uncommitted changes (pass '
- '--local-changes=ignore to skip)')
-
- bb = morphlib.buildbranch.BuildBranch(
- build_ref_prefix, uuid, definitions_repo=self)
-
- pbb = morphlib.buildbranch.pushed_build_branch(
- bb, changes_need_pushing=push, name=git_user_name,
- email=git_user_email, build_uuid=uuid,
- status=status_cb)
- return pbb # (repo_url, commit, original_ref)
+
+ status_cb(msg='Looking for uncommitted changes (pass '
+ '--local-changes=ignore to skip)')
+
+ def report_add(gd, build_ref, changed):
+ status_cb(msg='Creating temporary branch in %(dirname)s named '
+ '%(ref)s',
+ dirname=gd.dirname, ref=build_ref)
+
+ def report_commit(gd, build_ref):
+ status_cb(msg='Committing changes in %(dirname)s to %(ref)s',
+ dirname=gd.dirname, ref=build_ref, chatty=True)
+
+ def report_push(gd, build_ref, remote, refspec):
+ status_cb(msg='Pushing %(ref)s in %(dirname)s to %(remote)s',
+ ref=build_ref, dirname=gd.dirname,
+ remote=remote.get_push_url(), chatty=True)
+
+ @contextlib.contextmanager
+ def bbcm():
+ with contextlib.closing(morphlib.buildbranch.BuildBranch(
+ build_ref_prefix, build_uuid, definitions_repo=self)) \
+ as bb:
+ changes_made = bb.stage_uncommited_changes(add_cb=report_add)
+ unpushed = bb.needs_pushing()
+ if not changes_made and not unpushed:
+ yield bb.repo_remote_url, bb.head_commit, bb.head_ref
+ return
+ bb.commit_staged_changes(git_user_name, git_user_email,
+ commit_cb=report_commit)
+ if push:
+ repo_url = bb.repo_remote_url
+ bb.push_build_branch(push_cb=report_push)
+ else:
+ repo_url = bb.repo_local_url
+ yield repo_url, bb.build_commit, bb.build_ref
+ return bbcm()
@contextlib.contextmanager
def source_pool(self, lrc, rrc, cachedir, ref, system_filename,