+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
+ the repo exists."""
+ # TODO: this might be easier just to regex
+ repo = os.path.abspath(getRepo(package))
+ parent_dir = os.path.dirname(repo)
+ prefix = os.path.join(_REPO_DIR, 'invirt/packages')
+ if not parent_dir.startswith(prefix):
+ raise InvalidBuild('Invalid package name %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()