index : gitrs
A lightweight web interface for browsing Git repositories, implemented in Rust
about summary refs log tree commit diff

Diffstat (limited to 'src/routes/repository/commit.rs')

-rw-r--r-- src/routes/repository/commit.rs 48
 1 file changed, 8 insertions(+), 40 deletions(-)

diff --git a/src/routes/repository/commit.rs b/src/routes/repository/commit.rs
index 8a00ab3..6357188 100644
--- a/src/routes/repository/commit.rs
+++ b/src/routes/repository/commit.rs
@@ -20,53 +20,21 @@
    path: web::Path<String>,
    query: web::Query<PageQuery>,
    data: web::Data<App>,
) -> ActixResult<HttpResponse> {
    let name = path.into_inner();
    let repo = match data.find_repo(name) {
        Some(r) => r,
        None => return Ok(HttpResponse::NotFound().body("Repo not found")),
    };
) -> Result<HttpResponse, Error> {
    let repo = data.get_repo(&path)?;
    let gix_repo = repo.gix();

    let current_ref = match Ref::resolve(&repo, &query) {
        Ok(r) => r,
        Err(e) => return Ok(HttpResponse::InternalServerError().body(e.to_string())),
    };
    let branch_names = match repo.branch_names() {
        Ok(b) => b,
        Err(e) => return Ok(HttpResponse::InternalServerError().body(e.to_string())),
    };
    let commit: Commit = if let Some(id) = query.clone().into_inner().id {
        match repo.find_commit(&gix_repo, &id) {
            Ok(c) => c,
            Err(e) => return Ok(HttpResponse::InternalServerError().body(e.to_string())),
        }
    } else {
        match gix_repo.find_reference(&current_ref.name.to_string()) {
            Ok(mut r) => match r.peel_to_commit() {
                Ok(c) => Commit::from_gix(c).unwrap(),
                Err(e) => return Ok(HttpResponse::InternalServerError().body(e.to_string())),
            },
            Err(e) => return Ok(HttpResponse::InternalServerError().body(e.to_string())),
        }
    };
    let current_ref = Ref::resolve(&repo, &query)?;
    let branch_names = repo.branch_names()?;
    let commit = repo.resolve_commit(&gix_repo, query.id.as_deref(), &current_ref)?;
    let diff = commit.diff(&repo, None, DiffFormat::Plain)?;

    let diff: Diff = match commit.diff(&repo, None, DiffFormat::Plain) {
        Ok(d) => d,
        Err(e) => return Ok(HttpResponse::InternalServerError().body(e.to_string())),
    };

    let rendered = CommitPage {
    render_html(&CommitPage {
        repo: &repo,
        branch_names,
        current_ref,
        commit,
        diff,
        query,
    }
    .render();
    match rendered {
        Ok(html) => Ok(HttpResponse::Ok().content_type("text/html").body(html)),
        Err(e) => Ok(HttpResponse::InternalServerError().body(e.to_string())),
    }
    })
}