summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--git-gmi/gateway.py8
-rw-r--r--git-gmi/git.py38
2 files changed, 40 insertions, 6 deletions
diff --git a/git-gmi/gateway.py b/git-gmi/gateway.py
index bb7f2e0..671d5cd 100644
--- a/git-gmi/gateway.py
+++ b/git-gmi/gateway.py
@@ -73,5 +73,13 @@ def handle_cgi_request(path: str, query: str):
print(STATUS_TEMPORARY_FAILURE)
return
+ elif view == "refs":
+ try:
+ print(repo.view_refs())
+ return
+ except:
+ print(STATUS_TEMPORARY_FAILURE)
+ return
+
handle_cgi_request(environ.get("PATH_INFO"), environ.get("QUERY_STRING"))
diff --git a/git-gmi/git.py b/git-gmi/git.py
index 52764d2..9721a6f 100644
--- a/git-gmi/git.py
+++ b/git-gmi/git.py
@@ -30,7 +30,8 @@ class GitGmiRepo:
f"=> {CGI_PATH} {GIT_GMI_SITE_TITLE}\n"
f"=> {CGI_PATH}{self.name}/summary summary\n"
f"=> {CGI_PATH}{self.name}/tree/{MAIN_BRANCH}/ tree\n"
- f"=> {CGI_PATH}{self.name}/log log\n\n"
+ f"=> {CGI_PATH}{self.name}/log log\n"
+ f"=> {CGI_PATH}{self.name}/refs refs\n\n"
)
return header
@@ -93,6 +94,28 @@ class GitGmiRepo:
)
return response
+ def get_refs(self) -> list:
+ refs = self.repo.listall_reference_objects()
+ return [
+ {
+ "name": ref.name,
+ "shorthand": ref.shorthand,
+ "target": ref.target,
+ "type": ref.type,
+ }
+ for ref in refs
+ ]
+
+ def view_refs(self) -> str:
+ response = f"{STATUS_SUCCESS} {META_GEMINI}\n" + self.generate_header()
+ refs = self.get_refs()
+ for ref in refs:
+ response += (
+ f"## {ref['shorthand']}\n"
+ f"=> tree/{ref['shorthand']}/ view tree\n\n"
+ )
+ return response
+
@classmethod
def parse_recursive_tree(cls, tree: Tree) -> list:
# recursively replace all Trees with a list of Blobs inside it,
@@ -105,14 +128,17 @@ class GitGmiRepo:
return tree_list
- def get_tree(self, commit_str: str) -> list:
+ def get_tree(self, revision_str: str) -> list:
# returns a recursive list of Blob objects
try:
- commit = self.repo.revparse_single(commit_str)
- # top level tree; may contain sub-trees
- return self.parse_recursive_tree(commit.tree)
+ revision = self.repo.revparse_single(revision_str)
+ if isinstance(revision, Commit):
+ # top level tree; may contain sub-trees
+ return self.parse_recursive_tree(revision.tree)
+ elif isinstance(revision, Tag):
+ return self.parse_recursive_tree(revision.get_object().tree)
except ValueError:
- raise FileNotFoundError(f"Error: no such tree: {commit_str}")
+ raise FileNotFoundError(f"Error: no such tree: {revision_str}")
return None
@staticmethod