{% extends "repo.html" %}
{% import "utils.html" as utils %}
{% block title %}
<title>{{repo.owner.canonical_name}}/{{repo.name}} ({{ ref }}): {{path_join(*path)}}/ - {{cfg("sr.ht", "site-name")}} git</title>
{% endblock %}

{% block content %}
<div class="header-extension">
  <div class="container tree-header">
    <div class="breadcrumb">
      {{ utils.breadcrumb(ref, commit.id, repo, path, entry, view, path_join, stat, pygit2, humanize, current_user) }}
    </div>
    <div class="commit-info">
      <a
        href="{{url_for("repo.commit",
          owner=repo.owner.canonical_name,
          repo=repo.name,
          ref=str(commit.id))}}"
        rel="nofollow"
      >{{str(commit.id)[:8]}}</a> &mdash;
      {% set author_user = lookup_user(commit.author.email) %}
      {% if author_user %}
      <a href="{{url_for("public.user_index",
        username=author_user.username)}}">{{commit.author.name}}</a>
      {% else %}
      {{commit.author.name}}
      {% endif %}
      {{trim_commit(commit.message)}}
      <span class="text-muted">
        {{ commit_time(commit) | date }}
      </span>
    </div>
  </div>
</div>
<div class="container">
  <div class="row mb-3">
    <div class="col-md-12">
      {# chromium has a hard limit on 1000 rows per grid #}
      {% for index in range(0, len(tree), 501) %}
      {% set group = tree[index:index + 501] %}
      <div class="tree-list">
      {% if path != [''] and index == 0 %}
      <div class="mode"></div>
      <div class="name tree">
        <a
          href="{{url_for("repo.tree",
            owner=repo.owner.canonical_name, repo=repo.name, ref=ref,
            path=path_join(*path[:-1]) if path[:-1] else None)}}"
          rel="nofollow"
        >..</a>
      </div>
      <div class="commit"></div>
      <div class="date"></div>
      <div class="size"></div>
      {% endif %}
      {% for entry in group %}
      <div class="mode">
        <span title="{{"{0:0o}".format(entry.filemode)}}">
          {% if entry.filemode == 57344 %}
          {# git submodule #}
          m---------
          {% else %}
          {{stat.filemode(entry.filemode)}}
          {% endif %}
        </span>
      </div>
      <div class="name {{entry.type}}">
        {% if entry.type == "commit" %}
        {{entry.name}} @ {{ entry.id }}
        {% else %}
        <a
          href="{{url_for("repo.tree",
            owner=repo.owner.canonical_name, repo=repo.name, ref=ref,
            path=path_join(*(path + [entry.name])))}}"
          rel="nofollow"
        >
          {{entry.name}}{% if entry.type == "tree" %}/{% endif %}
        </a>
        {% endif %}
      </div>
      <div class="commit">
        {% if entry.commit %}
        <a
          href="{{url_for("repo.commit",
            owner=repo.owner.canonical_name,
            repo=repo.name,
            ref=str(entry.commit.id))}}"
          rel="nofollow"
        >{{trim_commit(entry.commit.message)}}</a>
        {% endif %}
      </div>
      <div class="date">
        {% if entry.commit %}
        {{ commit_time(entry.commit) | date }}
        {% endif %}
      </div>
      <div class="size">
        {% if entry.type == "blob" %}
        <span title="{{ entry.blob.size }} bytes">
          {{humanize.naturalsize(entry.blob.size,
            binary=True).replace("Byte", "byte")}}
        </span>
        {% endif %}
      </div>
      {% endfor %}
      </div>
      {% endfor %}
    </div>
</div>
{% endblock %}
