wayver's git archive


a simple self-hosted git server
git clone https://git.wayver.dev/bile

src/handlers/repo_refs.rs@7e0330303eec590c92eb6194f83f04d0e8fb2ea0

raw
Date Commit Message Author Files + -
2026-02-19 17:51 large refactoring wayverd 53 2153 1683
...

1use axum::{
2    extract::{Path, State},
3    http::StatusCode,
4    response::{IntoResponse as _, Response},
5};
6
7use crate::{
8    BileState,
9    config::Config,
10    error::Context as _,
11    git::{Repository, TagEntry},
12    http::{
13        extractor::RepoName,
14        response::{ErrorPage, Html, Redirect, Result},
15    },
16    utils::filters,
17};
18
19#[derive(askama::Template)]
20#[template(path = "refs.html")]
21struct RepoRefTemplate<'a> {
22    config: &'a Config,
23    repo: &'a Repository,
24    branches: Vec<git2::Reference<'a>>,
25    tags: Vec<TagEntry>,
26}
27
28#[tracing::instrument(skip_all)]
29pub(crate) async fn get(state: State<BileState>, Path(repo_name): Path<RepoName>) -> Response {
30    state.spawn(move |state| inner(&state, &repo_name)).await
31}
32
33#[tracing::instrument(skip_all)]
34fn inner(state: &BileState, repo_name: &RepoName) -> Result<Response> {
35    let Some(repo) = Repository::open(&state.config, repo_name).context("opening repository")?
36    else {
37        return Ok(ErrorPage::new(&state.config)
38            .with_status(StatusCode::NOT_FOUND)
39            .into_response());
40    };
41
42    if repo.is_empty()? {
43        return Ok(Redirect::permanent(&format!("/{repo_name}"))
44            .unwrap_or(Redirect::PERMANENT_ROOT)
45            .into_response());
46    }
47
48    let branches = repo.branches()?;
49
50    let mut tags = repo.tag_entries()?;
51
52    // sort so that newest tags are at the top
53    tags.sort_unstable_by(|a, b| a.signature.when().cmp(&b.signature.when()).reverse());
54
55    Ok(Html(RepoRefTemplate {
56        config: &state.config,
57        repo: &repo,
58        branches,
59        tags,
60    })
61    .into_response())
62}
63