Implement diff view
Diff
src/methods/repo.rs | 22 +++++++++++++++++++++-
templates/repo/diff.html | 7 +++++++
2 files changed, 27 insertions(+), 2 deletions(-)
@@ -242,14 +242,32 @@
}
#[allow(clippy::unused_async)]
pub async fn handle_diff(Extension(repo): Extension<Repository>) -> Html<String> {
pub async fn handle_diff(
Extension(repo): Extension<Repository>,
Extension(RepositoryPath(repository_path)): Extension<RepositoryPath>,
Extension(git): Extension<Git>,
Extension(syntax_set): Extension<Arc<SyntaxSet>>,
Query(query): Query<CommitQuery>,
) -> Html<String> {
#[derive(Template)]
#[template(path = "repo/diff.html")]
pub struct View {
pub repo: Repository,
pub commit: Arc<Commit>,
}
Html(View { repo }.render().unwrap())
Html(
View {
repo,
commit: if let Some(commit) = query.id {
git.get_commit(repository_path, &commit, syntax_set).await
} else {
Arc::new(git.get_latest_commit(repository_path, syntax_set).await)
},
}
.render()
.unwrap(),
)
}
#[allow(clippy::unused_async)]
@@ -1,6 +1,13 @@
{% extends "repo/base.html" %}
{% block head %}
<link rel="stylesheet" type="text/css" href="/highlight.css" />
{% endblock %}
{% block diff_nav_class %}active{% endblock %}
{% block content %}
<h2>Diff</h2>
<pre>{{ commit.diff_stats|safe }}
{{ commit.diff|safe }}</pre>
{% endblock %}