diff --git a/src/git.rs b/src/git.rs
@@ -212,12 +212,12 @@ impl OpenRepository {
}
built_refs.branch.sort_unstable_by(|one, two| {
- one.commit.committer.time.cmp(&two.commit.committer.time)
+ two.commit.committer.time.cmp(&one.commit.committer.time)
});
built_refs.tag.sort_unstable_by(|one, two| {
let one_tagger = one.tagger.as_ref().map(|v| v.time);
let two_tagger = two.tagger.as_ref().map(|v| v.time);
- one_tagger.cmp(&two_tagger)
+ two_tagger.cmp(&one_tagger)
});
Arc::new(built_refs)
diff --git a/src/methods/repo.rs b/src/methods/repo.rs
@@ -113,13 +113,31 @@ pub async fn service<ReqBody: Send + 'static>(mut request: Request<ReqBody>) ->
#[derive(Template)]
#[template(path = "repo/summary.html")]
-pub struct SummaryView {
- pub repo: Repository,
+pub struct SummaryView<'a> {
+ repo: Repository,
+ refs: Arc<Refs>,
+ commit_list: Vec<&'a crate::database::schema::commit::Commit<'a>>,
}
-#[allow(clippy::unused_async)]
-pub async fn handle_summary(Extension(repo): Extension<Repository>) -> Response {
- into_response(&SummaryView { repo })
+pub async fn handle_summary(
+ Extension(repo): Extension<Repository>,
+ Extension(RepositoryPath(repository_path)): Extension<RepositoryPath>,
+ Extension(git): Extension<Arc<Git>>,
+ Extension(db): Extension<sled::Db>,
+) -> Response {
+ let open_repo = git.repo(repository_path).await;
+ let refs = open_repo.refs().await;
+
+ let repository = crate::database::schema::repository::Repository::open(&db, &*repo).unwrap();
+ let commit_tree = repository.get().commit_tree(&db, "refs/heads/master");
+ let commits = commit_tree.fetch_latest(11, 0).await;
+ let commit_list = commits.iter().map(Yoke::get).collect();
+
+ into_response(&SummaryView {
+ repo,
+ refs,
+ commit_list,
+ })
}
#[derive(Deserialize)]
diff --git a/statics/sass/tables.scss b/statics/sass/tables.scss
@@ -23,6 +23,10 @@ table.repositories {
background: #f7f7f7;
}
+ &.no-background {
+ background: none;
+ }
+
&.has-parent td:first-of-type {
padding-left: 1rem;
}
diff --git a/templates/repo/log.html b/templates/repo/log.html
@@ -1,33 +1,11 @@
+{% import "macros/refs.html" as refs %}
{% extends "repo/base.html" %}
{% block log_nav_class %}active{% endblock %}
{% block content %}
<table class="repositories">
- <thead>
- <tr>
- <th>Age</th>
- <th>Commit message</th>
- <th>Author</th>
- </tr>
- </thead>
-
- <tbody>
- {% for commit in commits %}
- <tr>
- <td>
- <time datetime="{{ commit.committer.time }}" title="{{ commit.committer.time }}">
- {{ commit.committer.time.clone()|timeago }}
- </time>
- </td>
- <td><a href="/{{ repo.display() }}/commit/?id={{ commit.hash|hex }}">{{ commit.summary }}</a></td>
- <td>
- <img src="https://www.gravatar.com/avatar/{{ commit.author.email|md5 }}?s=13&d=retro" width="13" height="13">
- {{ commit.author.name }}
- </td>
- </tr>
- {% endfor %}
- </tbody>
+ {% call refs::commit_table(commits, false) %}
</table>
{% if let Some(next_offset) = next_offset %}
diff --git a/templates/repo/macros/refs.html b/templates/repo/macros/refs.html
@@ -0,0 +1,92 @@
+{% macro branch_table(branches) %}
+<thead>
+<tr>
+ <th>Branch</th>
+ <th>Commit message</th>
+ <th>Author</th>
+ <th>Age</th>
+</tr>
+</thead>
+
+<tbody>
+{% for branch in branches %}
+<tr>
+ <td><a href="/{{ repo.display() }}/log/?h={{ branch.name }}">{{ branch.name }}</a></td>
+ <td><a href="/{{ repo.display() }}/commit/?id={{ branch.commit.oid() }}">{{ branch.commit.summary() }}</a></td>
+ <td>
+ <img src="https://www.gravatar.com/avatar/{{ branch.commit.author().email_md5() }}?s=13&d=retro" width="13" height="13">
+ {{ branch.commit.author().name() }}
+ </td>
+ <td>
+ <time datetime="{{ branch.commit.author().time() }}" title="{{ branch.commit.author().time() }}">
+ {{ branch.commit.author().time()|timeago }}
+ </time>
+ </td>
+</tr>
+{% endfor %}
+</tbody>
+{% endmacro %}
+
+{% macro tag_table(tags) %}
+<thead>
+<tr class="no-background">
+ <th>Tag</th>
+ <th>Download</th>
+ <th>Author</th>
+ <th>Age</th>
+</tr>
+</thead>
+
+<tbody>
+{% for tag in tags %}
+<tr>
+ <td><a href="/{{ repo.display() }}/tag/?h={{ tag.name }}">{{ tag.name }}</a></td>
+ <td></td>
+ <td>
+ {% if let Some(tagger) = tag.tagger %}
+ <img src="https://www.gravatar.com/avatar/{{ tagger.email_md5() }}?s=13&d=retro" width="13" height="13">
+ {{ tagger.name() }}
+ {% endif %}
+ </td>
+ <td>
+ {% if let Some(tagger) = tag.tagger %}
+ <time datetime="{{ tagger.time() }}" title="{{ tagger.time() }}">
+ {{ tagger.time()|timeago }}
+ </time>
+ {% endif %}
+ </td>
+</tr>
+{% endfor %}
+</thead>
+{% endmacro %}
+
+{% macro commit_table(commits, with_extras) %}
+<thead>
+<tr>
+ <th>Age</th>
+ <th>Commit message</th>
+ <th>Author</th>
+</tr>
+</thead>
+
+<tbody>
+{% for commit in commits %}
+<tr>
+ <td>
+ <time datetime="{{ commit.committer.time }}" title="{{ commit.committer.time }}">
+ {{ commit.committer.time.clone()|timeago }}
+ </time>
+ </td>
+ <td><a href="/{{ repo.display() }}/commit/?id={{ commit.hash|hex }}">{{ commit.summary }}</a></td>
+ <td>
+ <img src="https://www.gravatar.com/avatar/{{ commit.author.email|md5 }}?s=13&d=retro" width="13" height="13">
+ {{ commit.author.name }}
+ </td>
+
+ {% if with_extras %}
+ <td></td>
+ {% endif %}
+</tr>
+{% endfor %}
+</tbody>
+{% endmacro %}
\ No newline at end of file
diff --git a/templates/repo/refs.html b/templates/repo/refs.html
@@ -1,35 +1,11 @@
+{% import "macros/refs.html" as refs %}
{% extends "repo/base.html" %}
{% block refs_nav_class %}active{% endblock %}
{% block content %}
<table class="repositories">
- <thead>
- <tr>
- <th>Branch</th>
- <th>Commit message</th>
- <th>Author</th>
- <th>Age</th>
- </tr>
- </thead>
-
- <tbody>
- {% for branch in refs.branch %}
- <tr>
- <td><a href="/{{ repo.display() }}/log/?h={{ branch.name }}">{{ branch.name }}</a></td>
- <td><a href="/{{ repo.display() }}/commit/?id={{ branch.commit.oid() }}">{{ branch.commit.summary() }}</a></td>
- <td>
- <img src="https://www.gravatar.com/avatar/{{ branch.commit.author().email_md5() }}?s=13&d=retro" width="13" height="13">
- {{ branch.commit.author().name() }}
- </td>
- <td>
- <time datetime="{{ branch.commit.author().time() }}" title="{{ branch.commit.author().time() }}">
- {{ branch.commit.author().time()|timeago }}
- </time>
- </td>
- </tr>
- {% endfor %}
- </tbody>
+ {% call refs::branch_table(refs.branch) %}
<tbody>
<tr class="separator">
@@ -38,33 +14,8 @@
<td></td>
<td></td>
</tr>
-
- <tr>
- <th>Tag</th>
- <th>Download</th>
- <th>Author</th>
- <th>Age</th>
- </tr>
-
- {% for tag in refs.tag.iter().rev() %}
- <tr>
- <td><a href="/{{ repo.display() }}/tag/?h={{ tag.name }}">{{ tag.name }}</a></td>
- <td></td>
- <td>
- {% if let Some(tagger) = tag.tagger %}
- <img src="https://www.gravatar.com/avatar/{{ tagger.email_md5() }}?s=13&d=retro" width="13" height="13">
- {{ tagger.name() }}
- {% endif %}
- </td>
- <td>
- {% if let Some(tagger) = tag.tagger %}
- <time datetime="{{ tagger.time() }}" title="{{ tagger.time() }}">
- {{ tagger.time()|timeago }}
- </time>
- {% endif %}
- </td>
- </tr>
- {% endfor %}
</tbody>
+
+ {% call refs::tag_table(refs.tag) %}
</table>
{% endblock %}
\ No newline at end of file
diff --git a/templates/repo/summary.html b/templates/repo/summary.html
@@ -1,6 +1,62 @@
+{% import "macros/refs.html" as refs %}
{% extends "repo/base.html" %}
{% block summary_nav_class %}active{% endblock %}
{% block content %}
+<table class="repositories">
+ {% call refs::branch_table(refs.branch.iter().take(10)) %}
+ {% if refs.branch.len() > 10 %}
+ <tbody>
+ <tr class="no-background">
+ <td><a href="/{{ repo.display() }}/refs" class="no-style">[...]</a></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ </tr>
+ </tbody>
+ {% endif %}
+
+ <tbody>
+ <tr class="separator">
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ </tr>
+ </tbody>
+
+ {% call refs::tag_table(refs.tag.iter().take(10)) %}
+ {% if refs.tag.len() > 10 %}
+ <tbody>
+ <tr class="no-background">
+ <td><a href="/{{ repo.display() }}/refs" class="no-style">[...]</a></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ </tr>
+ </tbody>
+ {% endif %}
+
+ <tbody>
+ <tr class="separator">
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ </tr>
+ </tbody>
+
+ {% call refs::commit_table(commit_list.iter().take(10), true) %}
+ {% if commit_list.len() > 10 %}
+ <tbody>
+ <tr class="no-background">
+ <td><a href="/{{ repo.display() }}/log" class="no-style">[...]</a></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ </tr>
+ </tbody>
+ {% endif %}
+</table>
{% endblock %}
\ No newline at end of file