From f4dd91e9ec9763f51066653c68f3c36f06dee8ae Mon Sep 17 00:00:00 2001 From: mprahl Date: Tue, 30 Apr 2019 09:45:28 -0400 Subject: [PATCH] Add an efficiency improvement to SCM.get_full_commit_hash Basically, if the commit has already been resolved from the branch, the full commit hash is already cached, so just return that. --- module_build_service/scm.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/module_build_service/scm.py b/module_build_service/scm.py index 19c7eb9b..0c50c124 100644 --- a/module_build_service/scm.py +++ b/module_build_service/scm.py @@ -238,10 +238,18 @@ class SCM(object): """ if commit_hash: commit_to_check = commit_hash - elif self.commit: - commit_to_check = self.commit + elif self._commit: + commit_to_check = self._commit else: - raise RuntimeError('No commit hash was specified for "{0}"'.format(self.url)) + try: + # If self._commit was None, then calling `self.commit` will resolve the ref based + # on the branch + return self.commit + except UnprocessableEntity: + # If there was an exception resolving the ref based on the branch (could be the + # default branch that doesn't exist), then there is not enough information to get + # the commit hash + raise RuntimeError('No commit hash was specified for "{0}"'.format(self.url)) if self.scheme == "git": log.debug(