Use the expanded commit name internally
[invirt/packages/invirt-dev.git] / python / invirt / builder.py
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)
 
-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)