M gitsrht/blueprints/repo.py => gitsrht/blueprints/repo.py +11 -5
@@ 198,6 198,7 @@ def tree(owner, repo, ref, path):
abort(404)
editorconfig = EditorConfig(git_repo, tree, path)
+ entry = tree
path = path.split("/")
for part in path:
if part == "":
@@ 234,7 235,7 @@ def tree(owner, repo, ref, path):
blob=blob, data=data, commit=orig_commit,
highlight_file=_highlight_file,
editorconfig=editorconfig,
- markdown=md, force_source=force_source)
+ markdown=md, force_source=force_source, pygit2=pygit2)
tree = git_repo.get(entry.id)
if not tree:
@@ 243,7 244,8 @@ def tree(owner, repo, ref, path):
tree = sorted(tree, key=lambda e: e.name)
return render_template("tree.html", view="tree", owner=owner, repo=repo,
- ref=ref, commit=commit, tree=tree, path=path)
+ ref=ref, commit=commit, entry=entry, tree=tree, path=path,
+ pygit2=pygit2)
def resolve_blob(git_repo, ref, path):
commit, ref, path = lookup_ref(git_repo, ref, path)
@@ 324,7 326,7 @@ def blame(owner, repo, ref, path):
repo=repo, ref=ref, path=path, entry=entry, blob=blob, data=data,
blame=blame, commit=orig_commit, highlight_file=_highlight_file,
editorconfig=EditorConfig(git_repo, orig_commit.tree, path),
- lookup_user=lookup_user())
+ lookup_user=lookup_user(), pygit2=pygit2)
@repo.route("/<owner>/<repo>/archive/<path:ref>.tar.gz")
def archive(owner, repo, ref):
@@ 401,9 403,13 @@ def log(owner, repo, ref, path):
commits = get_log(git_repo, commit, path)
+ entry = None
+ if path and commit.tree and path in commit.tree:
+ entry = commit.tree[path]
+
return render_template("log.html", view="log",
- owner=owner, repo=repo, ref=ref, path=path,
- commits=commits, refs=refs)
+ owner=owner, repo=repo, ref=ref, path=path.split("/"),
+ commits=commits, refs=refs, entry=entry, pygit2=pygit2)
@repo.route("/<owner>/<repo>/log/rss.xml", defaults={"ref": None})
M gitsrht/templates/blame.html => gitsrht/templates/blame.html +1 -24
@@ 18,30 18,7 @@ pre, body {
<div class="header-extension" style="margin-bottom: 0;">
<div class="blob container-fluid">
<span>
- {{ utils.breadcrumb(ref, repo, path, path_join) }}
- <span class="text-muted" style="margin-left: 1rem">
- <span title="{{"{0:0o}".format(entry.filemode)}}">
- {{stat.filemode(entry.filemode)}}
- </span>
- </span>
- <span class="text-muted" style="margin-left: 1rem">
- <span title="{{ blob.size }} bytes">
- {{humanize.naturalsize(blob.size,
- binary=True).replace("Byte", "byte")}}
- </span>
- </span>
- <span class="text-muted" style="margin-left: 1rem">
- <a href="{{url_for("repo.raw_blob", owner=repo.owner.canonical_name,
- repo=repo.name, ref=ref, path=path_join(*path))}}">
- View raw
- </a>
- </span>
- <span class="text-muted" style="margin-left: 1rem">
- <a href="{{url_for("repo.tree", owner=repo.owner.canonical_name,
- repo=repo.name, ref=ref, path=path_join(*path))}}">
- Unblame
- </a>
- </span>
+ {{ utils.breadcrumb(ref, repo, path, entry, view, path_join, stat, pygit2, humanize) }}
</span>
<div class="commit">
<a
M gitsrht/templates/blob.html => gitsrht/templates/blob.html +1 -30
@@ 18,36 18,7 @@ pre, body {
<div class="header-extension" style="margin-bottom: 0;">
<div class="blob container-fluid">
<span>
- {{ utils.breadcrumb(ref, repo, path, path_join) }}
- <span class="text-muted" style="margin-left: 1rem">
- <span title="{{"{0:0o}".format(entry.filemode)}}">
- {{stat.filemode(entry.filemode)}}
- </span>
- </span>
- <span class="text-muted" style="margin-left: 1rem">
- <span title="{{ blob.size }} bytes">
- {{humanize.naturalsize(blob.size,
- binary=True).replace("Byte", "byte")}}
- </span>
- </span>
- <span class="text-muted" style="margin-left: 1rem">
- <a href="{{url_for("repo.log", owner=repo.owner.canonical_name,
- repo=repo.name, ref=ref, path=path_join(*path))}}"
- >Log
- </a>
- </span>
- <span class="text-muted" style="margin-left: 1rem">
- <a href="{{url_for("repo.raw_blob", owner=repo.owner.canonical_name,
- repo=repo.name, ref=ref, path=path_join(*path))}}"
- >View raw</a>
- </span>
- {% if not blob.is_binary %}
- <span class="text-muted" style="margin-left: 1rem">
- <a href="{{url_for("repo.blame", owner=repo.owner.canonical_name,
- repo=repo.name, ref=ref, path=path_join(*path))}}"
- >Blame</a>
- </span>
- {% endif %}
+ {{ utils.breadcrumb(ref, repo, path, entry, view, path_join, stat, pygit2, humanize) }}
</span>
{% if commit %}
<div class="commit">
M gitsrht/templates/log.html => gitsrht/templates/log.html +12 -1
@@ 1,7 1,7 @@
{% extends "repo.html" %}
{% import "utils.html" as utils with context %}
{% block title %}
-<title>{{repo.owner.canonical_name}}/{{repo.name}}: {{ref}} - {{cfg("sr.ht", "site-name")}} git</title>
+<title>{{repo.owner.canonical_name}}/{{repo.name}}: {% if path != [''] %}{{path_join(*path)}} {% endif %}{{ref}} - {{cfg("sr.ht", "site-name")}} git</title>
{% endblock %}
{% block head %}
@@ 21,6 21,17 @@
{% endblock %}
{% block content %}
+{% if path != [''] %}
+<div class="header-extension">
+ <div class="container">
+ <span style="padding-left: 1rem">
+ {{ utils.breadcrumb(ref, repo, path, entry, view, path_join, stat, pygit2, humanize) }}
+ </span>
+ <div class="clearfix"></div>
+ </div>
+</div>
+{% endif %}
+
<div class="container">
<div class="row">
<div class="col-md-12">
M gitsrht/templates/tree.html => gitsrht/templates/tree.html +1 -7
@@ 7,13 7,7 @@
<div class="header-extension">
<div class="container">
<span style="padding-left: 1rem">
- {{ utils.breadcrumb(ref, repo, path, path_join) }}
- </span>
- <span class="text-muted" style="margin-left: 1rem">
- <a href="{{url_for("repo.log", owner=repo.owner.canonical_name,
- repo=repo.name, ref=ref, path=path_join(*path))}}"
- >Log
- </a>
+ {{ utils.breadcrumb(ref, repo, path, entry, view, path_join, stat, pygit2, humanize) }}
</span>
<div class="pull-right">
<a
M gitsrht/templates/utils.html => gitsrht/templates/utils.html +55 -1
@@ 1,4 1,4 @@
-{% macro breadcrumb(ref, repo, path, path_join) %}
+{% macro breadcrumb(ref, repo, path, entry, view, path_join, stat, pygit2, humanize) %}
{% if ref != repo.git_repo.default_branch_name() %}
<span style="margin-right: 1rem">
<span class="text-muted">ref:</span> {{ ref }}
@@ 14,6 14,60 @@
path=path_join(*path[:loop.index]))}}"
>{{part}}</a>/{%
endif %}{% endfor %}
+
+{% set is_blob = entry and entry.type == pygit2.GIT_OBJ_BLOB %}
+{% if entry %}
+ {# Root tree has no filemode #}
+ {% set filemode = entry.filemode or stat.S_IFDIR %}
+ <span class="text-muted" style="margin-left: 1rem">
+ <span title="{{"{0:0o}".format(filemode)}}">
+ {{stat.filemode(filemode)}}
+ </span>
+ </span>
+
+ {% if is_blob %}
+ <span class="text-muted" style="margin-left: 1rem">
+ <span title="{{ entry.size }} bytes">
+ {{humanize.naturalsize(entry.size,
+ binary=True).replace("Byte", "byte")}}
+ </span>
+ </span>
+ {% endif %}
+{% endif %}
+
+{% set path = path_join(*path) %}
+<div class="blob-nav" style="margin-left: 1rem">
+ <ul class="nav nav-tabs">
+ <li class="nav-item">
+ <a class="nav-link {% if view in ["blob", "tree"] %}active{% endif %}"
+ href="{{url_for("repo.tree", owner=repo.owner.canonical_name,
+ repo=repo.name, ref=ref, path=path)}}">
+ {%- if is_blob %}View{% else %}Tree{% endif %}</a>
+ </li>
+
+ <li class="nav-item">
+ <a class="nav-link {% if view == "log" %}active{% endif %}"
+ href="{{url_for("repo.log", owner=repo.owner.canonical_name,
+ repo=repo.name, ref=ref, path=path)}}">Log</a>
+ </li>
+
+ {% if is_blob %}
+ {% if not entry.is_binary %}
+ <li class="nav-item">
+ <a class="nav-link {% if view == "blame" %}active{% endif %}"
+ href="{{url_for("repo.blame", owner=repo.owner.canonical_name,
+ repo=repo.name, ref=ref, path=path)}}">Blame</a>
+ </li>
+ {% endif %}
+
+ <li class="nav-item">
+ <a class="nav-link"
+ href="{{url_for("repo.raw_blob", owner=repo.owner.canonical_name,
+ repo=repo.name, ref=ref, path=path)}}">View raw</a>
+ </li>
+ {% endif %}
+ </ul>
+</div>
{% endmacro %}
{% macro commit_event(repo, c,
M scss/main.scss => scss/main.scss +29 -0
@@ 307,6 307,35 @@ img {
}
}
+.blob-nav {
+ display: inline-block;
+ padding-left: 0;
+ padding-right: 0;
+
+ .nav-item:hover {
+ background: #fff;
+ }
+
+ .nav-tabs {
+ padding-left: 0;
+ margin-bottom: -3px;
+ border-bottom: 3px transparent solid;
+
+ .nav-link {
+ padding: 0 0.5rem;
+
+ &:hover {
+ color: black;
+ }
+
+ &.active {
+ border-bottom: 3px #fff solid;
+ background: #fff;
+ }
+ }
+ }
+}
+
dl {
dd {
text-overflow: ellipsis;