Use the expanded commit name internally
authorGreg Brockman <gdb@mit.edu>
Tue, 6 Jul 2010 04:27:41 +0000 (00:27 -0400)
committerGreg Brockman <gdb@mit.edu>
Tue, 6 Jul 2010 04:27:41 +0000 (00:27 -0400)
svn path=/trunk/packages/invirt-dev/; revision=3035

invirt-submit-build
invirtibuilder
python/invirt/builder.py

index 8175865..f9b5697 100755 (executable)
@@ -41,6 +41,9 @@ def main():
                                      uuid.uuid4()))
 
     try:
                                      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
         b.validateBuild(pocket, package, commit)
     except b.InvalidBuild, e:
         print >>sys.stderr, "E: %s" % e
index aa70b53..24861f5 100755 (executable)
@@ -288,11 +288,11 @@ def build():
 
         try:
             db.failed_stage = 'validating job'
 
         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.
             # 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))
 
 
             db.version = str(b.getVersion(package, commit))
 
index f2cb421..68d56c8 100644 (file)
@@ -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)
 
     """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
     """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)
 
     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)
 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.
     """
     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)
 
     package_repo = getRepo(package)
     new_version = getVersion(package, commit)