From 8ea57ef3a296aee7581359ab38d3c5d52630f07b Mon Sep 17 00:00:00 2001 From: boke0 Date: Sun, 14 Mar 2021 02:39:09 +0900 Subject: [PATCH] [fix] --- izanami/controller.py | 29 ++++++++++++++++------------ izanami/main.py | 2 +- izanami/templates/repo/blob.html | 18 +++++++++++++++++ izanami/templates/repo/retrieve.html | 4 ---- 4 files changed, 36 insertions(+), 17 deletions(-) diff --git a/izanami/controller.py b/izanami/controller.py index 2523500..9f8a3cc 100644 --- a/izanami/controller.py +++ b/izanami/controller.py @@ -1,6 +1,7 @@ from mitama.app import Controller from mitama.app.http import Response from mitama.models import User, Group, InnerRole, Node, is_admin +from pathlib import Path from .model import Repo, Merge, InnerPermission from .forms import MergeCreateForm, SettingsForm, HookCreateForm from . import gitHttpBackend @@ -160,30 +161,34 @@ def retrieve(self, request): def blob(self, request): template = self.view.get_template("repo/blob.html") repo = Repo.retrieve(name=request.params['repo']) - query = request.query - branch = query.get('branch', 'master') + head = request.params.get('head', 'master') entity = git.Repo( self.app.project_dir / 'repos/{}.git'.format(repo.name), ) - head = getattr( + current_head = getattr( entity.heads, - branch + head ) if hasattr( entity.heads, - branch + head ) else None - tree = head.commit.tree or None - content = None - for obj in tree: - if obj.name == request.params['object']: - content = obj.data_stream.read().decode("utf-8") + tree = current_head.commit.tree or None + data = tree / request.params['object'] + content = ( + data.data_stream.read().decode("utf-8") + if isinstance(data, git.objects.blob.Blob) + else None + ) + above = Path("/" + request.params['object']) / '../' + print(above.resolve()) return Response.render(template, { 'repo': repo, - 'branch': branch, - 'head': head, + 'current_head': head, 'tree': tree, 'entity': entity, 'name': request.params['object'], + 'data': data, + 'above': str(above.resolve()), 'content': content }) diff --git a/izanami/main.py b/izanami/main.py index 3dd117f..68eb725 100644 --- a/izanami/main.py +++ b/izanami/main.py @@ -41,7 +41,7 @@ class App(App): view("//update", RepoController, 'update'), view("//delete", RepoController, 'delete'), view("//tree/", RepoController, 'retrieve'), - view("//blob//", RepoController, 'blob'), + view("//blob//", RepoController, 'blob'), view("//commit/", RepoController, 'commit'), view("//log", RepoController, 'log'), view("//log/", RepoController, 'log'), diff --git a/izanami/templates/repo/blob.html b/izanami/templates/repo/blob.html index ec9e8e2..cfa56b3 100644 --- a/izanami/templates/repo/blob.html +++ b/izanami/templates/repo/blob.html @@ -14,6 +14,7 @@ フック + {% if content != None %}
{{ name }}
@@ -22,4 +23,21 @@
{{ name }}
+ {% else %} +
{{ name }}/
+
    +
  • + {% if above == "/" %} + ../ + {% else %} + ../ + {% endif %} +
  • + {% for obj in data %} +
  • + {{ obj.name }} +
  • + {% endfor %} +
+ {% endif %} {% endblock %} diff --git a/izanami/templates/repo/retrieve.html b/izanami/templates/repo/retrieve.html index 79b25d8..a44fd30 100644 --- a/izanami/templates/repo/retrieve.html +++ b/izanami/templates/repo/retrieve.html @@ -32,11 +32,7 @@ {% if tree %} {% for obj in tree %}
  • - {% if isblob(obj) %} {{ obj.name }} - {% else %} - {{ obj.path }} - {% endif %}
  • {% endfor %} {% endif %}