~fkfd/git.gmi

9ed6b48a00d71c5a37e0ff5f182fc45022bdc879 — Frederick Yin 1 year, 2 months ago a4f8c8a + eb1bd1e
Merge branch 'master' into cache
1 files changed, 11 insertions(+), 11 deletions(-)

M git-gmi/git.py
M git-gmi/git.py => git-gmi/git.py +11 -11
@@ 92,7 92,7 @@ class GitGmiRepo:
        if cached is not None:
            return cached

        response = f"{STATUS_SUCCESS} {META_GEMINI}\n" + self._generate_header()
        response = f"{STATUS_SUCCESS} {META_GEMINI}\r\n" + self._generate_header()
        # show 3 recent commits
        recent_commits = self._get_commit_log()[:3]
        for cmt in recent_commits:


@@ 144,7 144,7 @@ class GitGmiRepo:
        cached = self._read_cache(["log"])
        if cached is not None:
            return cached
        response = f"{STATUS_SUCCESS} {META_GEMINI}\n" + self._generate_header()
        response = f"{STATUS_SUCCESS} {META_GEMINI}\r\n" + self._generate_header()
        log = self._get_commit_log()
        for cmt in log:
            # looks like "2020-06-06 04:51:21 UTC"


@@ 178,7 178,7 @@ class GitGmiRepo:
            return cached
        commit = self._get_commit(commit_str)
        response = (
            f"{STATUS_SUCCESS} {META_GEMINI}\n"
            f"{STATUS_SUCCESS} {META_GEMINI}\r\n"
            + self._generate_header()
            + f"{commit['id']} - {commit['author']} - {commit['time']}\n"
            + commit["msg"]


@@ 193,8 193,8 @@ class GitGmiRepo:
        return response

    def view_raw_commit(self, commit_str) -> str:
        commit = self._get_commit(commit_str)
        response = f"{STATUS_SUCCESS} {META_PLAINTEXT}\n" + commit["patch"]
        commit = self.get_commit(commit_str)
        response = f"{STATUS_SUCCESS} {META_PLAINTEXT}\r\n" + commit["patch"]
        return response

    def _get_refs(self) -> list:


@@ 213,7 213,7 @@ class GitGmiRepo:
        cached = self._read_cache(["refs"])
        if cached is not None:
            return cached
        response = f"{STATUS_SUCCESS} {META_GEMINI}\n" + self._generate_header()
        response = f"{STATUS_SUCCESS} {META_GEMINI}\r\n" + self._generate_header()
        refs = self._get_refs()
        for ref in refs:
            # HACK: filter out refs with slashes as remote branches


@@ 304,8 304,8 @@ class GitGmiRepo:
        contents = self._list_tree(tree, location)
        items = len(contents)
        response = (
            f"{STATUS_SUCCESS} {META_GEMINI}\n"
            + self._generate_header()
            f"{STATUS_SUCCESS} {META_GEMINI}\r\n"
            + self.generate_header()
            + f"## {self.name}{'/' if location else ''}{'/'.join(location)}/"
            f" | {items} {'items' if items > 1 else 'item'}\n\n"
        )


@@ 339,8 339,8 @@ class GitGmiRepo:
            return cached
        blob = self._get_blob(branch, location)
        response = (
            f"{STATUS_SUCCESS} {META_GEMINI}\n"
            + self._generate_header()
            f"{STATUS_SUCCESS} {META_GEMINI}\r\n"
            + self.generate_header()
            + f"## {self.name}/{'/'.join(location)} | {convert_filesize(blob.size)}\n\n"
            f"=> {blob.name}?raw view raw\n\n"
            f"```\n"


@@ 353,6 353,6 @@ class GitGmiRepo:
        blob = self._get_blob(branch, location)
        # if mimetypes can't make out the type, set it to plaintext
        guessed_mimetype = mimetypes.guess_type(blob.name)[0] or META_PLAINTEXT
        response = f"{STATUS_SUCCESS} {guessed_mimetype}\n"
        response = f"{STATUS_SUCCESS} {guessed_mimetype}\r\n"
        response += blob.data.decode("utf-8")
        return response