How to use the peru.cache.GitSession function in peru

To help you get started, we’ve selected a few peru examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github buildinspace / peru / peru / cache.py View on Github external
def no_index_git_session(self):
        return GitSession(self.trees_path, os.devnull, os.devnull)
github buildinspace / peru / peru / cache.py View on Github external
def clean_git_session(self, working_copy=None):
        with self.keyval.tmp_dir_context() as tmp_dir:
            # Git will initialize a nonexistent index file. Empty files cause
            # an error though.
            index_file = os.path.join(tmp_dir, "index")
            yield GitSession(self.trees_path, index_file, working_copy)
github buildinspace / peru / peru / cache.py View on Github external
tree = tree or (await self.get_empty_tree())
        previous_tree = previous_tree or (await self.get_empty_tree())

        makedirs(dest)

        with contextlib.ExitStack() as stack:

            # If the caller gave us an index file, create a git session around
            # it. Otherwise, create a clean one. Note that because we delete
            # the index file whenever there are errors, we also allow the
            # caller to pass in a path to a nonexistent file. In that case we
            # have to pay the cost to recreate it.
            did_refresh = False
            if previous_index_file:
                session = GitSession(self.trees_path, previous_index_file,
                                     dest)
                stack.enter_context(delete_if_error(previous_index_file))
                if not os.path.exists(previous_index_file):
                    did_refresh = True
                    await session.read_tree_and_stats_into_index(previous_tree)
            else:
                session = stack.enter_context(self.clean_git_session(dest))
                did_refresh = True
                await session.read_tree_and_stats_into_index(previous_tree)

            # The fast path. If the previous tree is the same as the current
            # one, and no files have changed at all, short-circuit.
            if previous_tree == tree:
                if (await session.working_copy_matches_index()):
                    return