From 1d986bce8b7cbd2ffb06b3fae0e6666710dcceaf Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Wed, 06 Jul 2022 22:49:26 +0100 Subject: [PATCH] Implement diff view --- src/methods/repo.rs | 22 +++++++++++++++++++++- templates/repo/diff.html | 7 +++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/methods/repo.rs b/src/methods/repo.rs index a04fd75..8753160 100644 --- a/src/methods/repo.rs +++ a/src/methods/repo.rs @@ -242,14 +242,32 @@ } #[allow(clippy::unused_async)] -pub async fn handle_diff(Extension(repo): Extension) -> Html { +pub async fn handle_diff( + Extension(repo): Extension, + Extension(RepositoryPath(repository_path)): Extension, + Extension(git): Extension, + Extension(syntax_set): Extension>, + Query(query): Query, +) -> Html { #[derive(Template)] #[template(path = "repo/diff.html")] pub struct View { pub repo: Repository, + pub commit: Arc, } - 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)] diff --git a/templates/repo/diff.html b/templates/repo/diff.html index aa0b72d..e09ff1b 100644 --- a/templates/repo/diff.html +++ a/templates/repo/diff.html @@ -1,6 +1,13 @@ {% extends "repo/base.html" %} +{% block head %} + +{% endblock %} + {% block diff_nav_class %}active{% endblock %} {% block content %} +

Diff

+
{{ commit.diff_stats|safe }}
+{{ commit.diff|safe }}
{% endblock %}-- rgit 0.1.3