]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
gentoo_build: Pass repo object around instead of creating always new ones.
authorBenjamin Drung <benjamin.drung@profitbricks.com>
Wed, 22 Jan 2014 11:34:51 +0000 (12:34 +0100)
committerBenjamin Drung <benjamin.drung@profitbricks.com>
Wed, 22 Jan 2014 11:34:51 +0000 (12:34 +0100)
gentoo_build

index 0aacfdb1745c1bd855eda620f7d5f19e0d1352fc..dbef0aa9e302e0840c73a44de124ad0accce4b14 100755 (executable)
@@ -227,10 +227,11 @@ def shell_env():
 def gentoo_build(script_name, logger, release_repo_uri, options):
     """Main function that creates a versioned ebuild file and releases it."""
     ebuilds = find_ebuilds(logger, options.category)
+    repo = git.Repo()
     if options.tag_from_debian:
-        git_tag = tag_from_debian_changelog(logger)
+        git_tag = tag_from_debian_changelog(logger, repo)
     else:
-        git_tag = get_latest_tag(logger)
+        git_tag = get_latest_tag(logger, repo)
     for ebuild in ebuilds:
         ebuild.set_version(git_tag)
         ebuild.set_git_commit(git_tag)
@@ -239,7 +240,7 @@ def gentoo_build(script_name, logger, release_repo_uri, options):
         # Checkout release repository
         branch = options.release_branch
         if branch is None:
-            branch = git.Repo().active_branch.name
+            branch = repo.active_branch.name
         logger.info("Check out {branch} branch of {repo} to "
                     "{dir}...".format(repo=release_repo_uri, branch=branch,
                                       dir=tmpdir))
@@ -264,7 +265,7 @@ def gentoo_build(script_name, logger, release_repo_uri, options):
             release_repo.git.push("origin", branch)
 
         if options.tag_from_debian:
-            push_tag(logger, git_tag, options.dry_run)
+            push_tag(logger, repo, git_tag, options.dry_run)
     finally:
         if options.keep:
             logger.warning("Keeping temporary git clone in {dir} as "
@@ -310,7 +311,7 @@ def find_ebuilds(logger, category):
                                   ebuild=" ".join(ebuild_files)))
     return [Ebuild(logger, e, category) for e in ebuild_files]
 
-def tag_from_debian_changelog(logger):
+def tag_from_debian_changelog(logger, repo):
     """Create a tag from the version specified in debian/changelog.
        Returns the name of the created tag.
     """
@@ -326,12 +327,11 @@ def tag_from_debian_changelog(logger):
     new_tag = version.replace('~', '_').replace(':', ',')
     resolve_existing_msg = (" Have you forgotten to create a new Debian "
                             "changelog entry?")
-    tag_head_commit(logger, new_tag, resolve_existing_msg)
+    tag_head_commit(logger, repo, new_tag, resolve_existing_msg)
     return new_tag
 
-def tag_head_commit(logger, new_tag, resolve_existing_msg=""):
+def tag_head_commit(logger, repo, new_tag, resolve_existing_msg=""):
     """Tags the head commit with the given tag name."""
-    repo = git.Repo('.')
     current_commit = repo.commit(repo.active_branch)
     tags = [t.name for t in repo.tags if t.commit == current_commit]
     if len(tags) > 0:
@@ -366,12 +366,11 @@ def format_commit(commit):
     weburl += "/commit/" + commit.hexsha[0:7]
     return commit.hexsha[0:7] + ' (' + weburl + ')'
 
-def get_latest_tag(logger):
+def get_latest_tag(logger, repo):
     """Get the tag name for the branch head commit.
        The function will fail if the branch head commit is not tagged or has
        multiple tags.
     """
-    repo = git.Repo('.')
     current_commit = repo.commit(repo.active_branch)
     tags = [t.name for t in repo.tags if t.commit == current_commit]
     if len(tags) == 0:
@@ -388,15 +387,14 @@ def get_latest_tag(logger):
     logger.info('Use tag "{tag}" as release version.'.format(tag=tag))
     return tag
 
-def push_tag(logger, tag, dry_run):
+def push_tag(logger, repo, tag, dry_run):
     """Pushed the given git tag unless it is a dry run."""
     if dry_run:
         logger.info("Not pushing tag {tag} as dry run was "
                     "requested.".format(tag=tag))
     else:
         logger.info("Pushing tag {tag}...".format(tag=tag))
-        repo = git.Repo()
         repo.git.push("origin", tag)
 
 if __name__ == '__main__':
-    main()
\ No newline at end of file
+    main()