248 lines
7.8 KiB
HTML
248 lines
7.8 KiB
HTML
{% macro breadcrumb(ref, repo, path, entry, view, path_join, stat, pygit2, humanize) %}
|
|
{% set ref_s = ref.decode("utf-8", "replace") %}
|
|
{% if ref_s != repo.git_repo.default_branch_name() %}
|
|
<span style="margin-right: 1rem">
|
|
<span class="text-muted">ref:</span> {{ ref_s }}
|
|
</span>
|
|
{% endif %}
|
|
{% if path != [''] %}
|
|
<a href="{{url_for("repo.tree",
|
|
owner=repo.owner.canonical_name, repo=repo.name, ref=ref)}}"
|
|
>{{repo.name}}</a>{% endif %}/{% for part in path%}{%
|
|
if loop.last %}{{part}}{% else %}<a
|
|
href="{{url_for("repo.tree", owner=repo.owner.canonical_name,
|
|
repo=repo.name, ref=ref,
|
|
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,
|
|
full_body=False, refs={}, full_id=False, diff=None, href=None,
|
|
parents=False, skip_body=False, target_blank=False, path=None,
|
|
lookup=lookup_user) %}
|
|
<div>
|
|
{% if full_id %}
|
|
{{c.id.hex}}
|
|
{% else %}
|
|
<a
|
|
{% if href %}
|
|
href="{{href}}"
|
|
{% else %}
|
|
href="{{url_for("repo.commit", owner=repo.owner.canonical_name,
|
|
repo=repo.name, ref=c.id.hex)}}{% if path %}#{{path}}{% endif %}"
|
|
{% endif %}
|
|
title="{{c.id.hex}}"
|
|
{% if target_blank %}
|
|
target="_blank"
|
|
{% endif %}
|
|
>{{c.id.hex[:8]}}</a>
|
|
{% endif %}
|
|
—
|
|
{% set author_user = lookup(c.author.email) %}
|
|
{% if author_user %}
|
|
<a href="{{url_for("public.user_index",
|
|
username=author_user.username)}}">{{c.author.name}}</a>
|
|
{% else %}
|
|
{{c.author.name}}
|
|
{% endif %}
|
|
<small class="pull-right">
|
|
<a
|
|
id="log-{{c.id}}"
|
|
href="{{url_for("repo.log", owner=repo.owner.canonical_name,
|
|
repo=repo.name)}}?from={{c.id}}#log-{{c.id}}"
|
|
>{{ commit_time(c) | date }}</a>
|
|
</small>
|
|
|
|
{% if parents and any(c.parents) %}
|
|
<span style="margin-left: 0.5rem">
|
|
{{icon('code-branch', cls="sm")}}
|
|
{% for parent in c.parents %}
|
|
<a href="{{url_for("repo.commit",
|
|
owner=repo.owner.canonical_name,
|
|
repo=repo.name,
|
|
ref=parent.id.hex)}}"
|
|
>{{parent.short_id}}</a>
|
|
{% if not loop.last %}
|
|
+
|
|
{% endif %}
|
|
{% endfor %}
|
|
</span>
|
|
{% endif %}
|
|
|
|
{% if c.id.hex in refs %}
|
|
<span style="margin-left: 0.5rem">
|
|
{% for ref in refs[c.id.hex] %}
|
|
<a
|
|
class="ref {{ref.type}}
|
|
{{"annotated" if ref.type == "tag" and ref.tag.message else ""}}"
|
|
{% if ref.type == "branch" %}
|
|
href="{{url_for("repo.tree",
|
|
owner=repo.owner.canonical_name, repo=repo.name, ref=ref.name)}}"
|
|
{% elif ref.type == "tag" %}
|
|
href="{{url_for("repo.ref",
|
|
owner=repo.owner.canonical_name,
|
|
repo=repo.name,
|
|
ref=ref.name)}}"
|
|
{% endif %}
|
|
>{{ref.name.decode("utf-8", "replace")}}</a>
|
|
</span>
|
|
{% endfor %}
|
|
{% endif %}
|
|
</div>
|
|
{% if not skip_body %}
|
|
{% if full_body %}
|
|
<pre class="commit">{{ c.message | commit_links(repo) | safe }}
|
|
{%- if diff %}
|
|
{{diffstat(diff, anchor=c.oid.hex + "-")}}{% endif -%}
|
|
</pre>
|
|
{% else %}
|
|
<pre class="commit">{{ trim_commit(c.message) }}</pre>
|
|
{% endif %}
|
|
{% endif %}
|
|
{% endmacro %}
|
|
|
|
{% macro commit_diff(repo, commit, diff, anchor="", target_blank=False) %}
|
|
{# God, working with <pre> tags is such a fucking mess #}
|
|
{% if diff.stats.insertions + diff.stats.deletions > 10000 %}
|
|
<div class="alert alert-warning">
|
|
This diff is too large to display. Try <a
|
|
href="{{url_for('repo.patch',
|
|
owner=repo.owner.canonical_name,
|
|
repo=repo.name,
|
|
ref=commit.id)}}"
|
|
>viewing the raw diff</a>
|
|
instead.
|
|
</div>
|
|
{% else %}
|
|
{% for patch in diff %}
|
|
<pre style="margin-bottom: 0; background: transparent; padding: 0;"
|
|
>{#
|
|
#}{{patch.delta.status_char()}} {% if parent %}<a
|
|
href="{{url_for("repo.tree",
|
|
owner=repo.owner.canonical_name,
|
|
repo=repo.name,
|
|
ref=parent.id.hex,
|
|
path=patch.delta.old_file.raw_path.decode('utf-8', 'replace'))}}"
|
|
id="{{anchor}}{{patch.delta.old_file.raw_path.decode('utf-8', 'replace')}}"
|
|
{% if target_blank %}
|
|
target="_blank"
|
|
{% endif %}
|
|
>{{patch.delta.old_file.raw_path.decode('utf-8', 'replace')}}</a>{#
|
|
#}{% endif %} => {#
|
|
#}<a
|
|
href="{{url_for("repo.tree",
|
|
owner=repo.owner.canonical_name,
|
|
repo=repo.name,
|
|
ref=commit.id.hex,
|
|
path=patch.delta.new_file.raw_path.decode('utf-8', 'replace'))}}"
|
|
id="{{anchor}}{{patch.delta.new_file.raw_path.decode('utf-8', 'replace')}}"
|
|
{% if target_blank %}
|
|
target="_blank"
|
|
{% endif %}
|
|
>{{patch.delta.new_file.raw_path.decode('utf-8', 'replace')}}</a>{#
|
|
#} <span class="pull-right"><ins class="text-success">+{{patch.line_stats[1]}}</ins>{#
|
|
#} <del class="text-danger">-{{patch.line_stats[2]}}</del></span>{%
|
|
if patch.delta.old_file.mode != patch.delta.new_file.mode %}{#
|
|
#}{#
|
|
#}{% endif %}</pre>
|
|
{% if patch.hunks|length %}<div class="event diff">
|
|
<pre>{% for hunk in patch.hunks %}
|
|
{% set hunk_index = loop.index %}<strong
|
|
class="text-info"
|
|
>@@ {#
|
|
#}{% if parent %}<a
|
|
style="text-decoration: underline"
|
|
href="{{url_for("repo.tree",
|
|
owner=repo.owner.canonical_name,
|
|
repo=repo.name,
|
|
ref=parent.id.hex,
|
|
path=patch.delta.old_file.raw_path.decode('utf-8', 'replace'))}}#L{{hunk.old_start}}"
|
|
{% if target_blank %}
|
|
target="_blank"
|
|
{% endif %}
|
|
>{{hunk.old_start}}</a>,{{hunk.old_lines}} {#
|
|
#}{% endif %}<a
|
|
style="text-decoration: underline"
|
|
href="{{url_for("repo.tree",
|
|
owner=repo.owner.canonical_name,
|
|
repo=repo.name,
|
|
ref=commit.id.hex,
|
|
path=patch.delta.new_file.raw_path.decode('utf-8', 'replace'))}}#L{{hunk.new_start}}"
|
|
{% if target_blank %}
|
|
target="_blank"
|
|
{% endif %}
|
|
>{{hunk.new_start}}</a>,{{hunk.new_lines}} {#
|
|
#}@@{{hunk.header.split('@@')[-1][:-1]}}</strong>
|
|
{% for line in hunk.lines
|
|
%}<span class="{{({
|
|
"+":"text-success",
|
|
"-":"text-danger",
|
|
}).get(line.origin) or ""}}"><a
|
|
href="#{{anchor}}{{patch.delta.old_file.raw_path.decode('utf-8', 'replace')}}-{{hunk_index}}-{{loop.index}}"
|
|
id="{{anchor}}{{patch.delta.old_file.raw_path.decode('utf-8', 'replace')}}-{{hunk_index}}-{{loop.index}}"
|
|
aria-hidden="true"
|
|
class="lineno"
|
|
style="color: inherit"
|
|
>{{line.origin}}</a>{{line.content}}{#
|
|
#}</span>{% endfor %}
|
|
{% endfor %}</pre>
|
|
</div>{% endif %}
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% endmacro %}
|