def __enter__(self): log.debug("About to lock {}".format(self.lockfile)) if not self._acquire(block=False): log.warning("Retrying lock acquisition on {}.".format( self.lockfile)) self._acquire(block=True) log.debug("Received lock on {}".format(self.lockfile))
def __commit_exists(self): try: cmd(self.__bare_path(), [ "git", "cat-file", "-e", "{}^{{commit}}".format(self.revision) ]) return True except subprocess.CalledProcessError as e: log.debug( "Did not find commit {} and instead got output: {}".format( self.revision, e.output)) return False
def cmd(cwd, command): log.debug("Running {} in {}".format( " ".join(command), cwd )) result = subprocess.run(command, cwd=cwd, stdout=subprocess.PIPE, universal_newlines=True, check=True) log.debug("command output: {}".format(result.stdout)) return result
def make_archive(self): if not self.__exists(): log.warning("Fetching tag '{}' from {}".format( self.tag, self.cache.repository)) with self.cache.lock(): bare_path = self.__bare_path() ref = "refs/tags/{}".format(self.tag) setup_bare(bare_path) try: cmd(bare_path, [ "git", "fetch", "--depth=1", self.cache.repository, ref ]) except subprocess.CalledProcessError as e: log.debug( "Did not find tag {}, instead got output: {}".format( self.tag, e.output)) raise NixError("tag-not-found", "Tag {} not found".format(self.tag)) archive_ref(bare_path, "FETCH_HEAD", self.__archive_path()) return self.__archive_path()
def setup_bare(path): if not os.path.isdir(path): log.debug("About to init a bare repository at {}".format(path)) cmd(None, ["git", "init", "--bare", path])
def __exit__(self, *args): log.debug("Releasing lock {}".format(self.lockfile)) self._release()