From 7bc450adac529e07b594f2b38d268c056563ac9e Mon Sep 17 00:00:00 2001 From: Greg Brockman Date: Tue, 6 Jul 2010 00:27:41 -0400 Subject: [PATCH] Use the expanded commit name internally svn path=/trunk/packages/invirt-dev/; revision=3035 --- invirt-submit-build | 3 +++ invirtibuilder | 6 +++--- python/invirt/builder.py | 12 ++++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/invirt-submit-build b/invirt-submit-build index 8175865..f9b5697 100755 --- a/invirt-submit-build +++ b/invirt-submit-build @@ -41,6 +41,9 @@ def main(): uuid.uuid4())) try: + # TODO: clean up this interface. + b.ensureValidPackage(package) + commit = b.canonicalize_commit(package, commit) b.validateBuild(pocket, package, commit) except b.InvalidBuild, e: print >>sys.stderr, "E: %s" % e diff --git a/invirtibuilder b/invirtibuilder index aa70b53..24861f5 100755 --- a/invirtibuilder +++ b/invirtibuilder @@ -288,11 +288,11 @@ def build(): try: db.failed_stage = 'validating job' - src = b.validateBuild(pocket, package, commit) # Don't expand the commit in the DB until we're sure the user # isn't trying to be tricky. - db.commit = commit = c.captureOutput(['git', 'rev-parse', commit], - cwd=b.getRepo(package)).strip() + b.ensureValidPackage(package) + db.commit = commit = b.canonicalize_commit(package, commit) + src = b.validateBuild(pocket, package, commit) db.version = str(b.getVersion(package, commit)) diff --git a/python/invirt/builder.py b/python/invirt/builder.py index f2cb421..68d56c8 100644 --- a/python/invirt/builder.py +++ b/python/invirt/builder.py @@ -28,7 +28,7 @@ def getRepo(package): """Return the path to the git repo for a given package.""" return os.path.join(_REPO_DIR, 'invirt/packages', '%s.git' % package) -def ensureValidRepo(package): +def ensureValidPackage(package): """Perform some basic sanity checks that the requested repo is in a subdirectory of _REPO_DIR/invirt/packages. This prevents weirdness such as submitting a package like '../prod/...git'. Also ensures that @@ -42,6 +42,14 @@ def ensureValidRepo(package): elif not os.path.exists(repo): raise InvalidBuild('Nonexisting package %s' % package) +def canonicalize_commit(package, commit, shorten=False): + if shorten: + flags = ['--short'] + else: + flags = [] + return c.captureOutput(['git', 'rev-parse'] + flags + [commit], + cwd=getRepo(package)).strip() + def pocketToGit(pocket): """Map a pocket in the configuration to a git branch.""" return getattr(getattr(config.build.pockets, pocket), 'git', pocket) @@ -98,7 +106,7 @@ def validateBuild(pocket, package, commit): another pocket, then this function returns that pocket. Otherwise, it returns True. """ - ensureValidRepo(package) + ensureValidPackage(package) package_repo = getRepo(package) new_version = getVersion(package, commit) -- 1.7.9.5