🏡 index : ~doyle/rgit.git

author Jordan Doyle <jordan@doyle.la> 2022-07-06 22:49:26.0 +01:00:00
committer Jordan Doyle <jordan@doyle.la> 2022-07-06 22:49:26.0 +01:00:00
commit
1d986bce8b7cbd2ffb06b3fae0e6666710dcceaf [patch]
tree
7d5d25024746a32081aa8732e829e367f4beb01b
parent
2a9edba83a90889a5003203a7b63d9a239719a16
download
1d986bce8b7cbd2ffb06b3fae0e6666710dcceaf.tar.gz

Implement diff view



Diff

 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<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)]
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 %}
<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 %}