diff --git a/Cargo.lock b/Cargo.lock index 6c91cdb..5ed9c71 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -154,7 +154,7 @@ dependencies = [ "rustversion", "serde", "serde_urlencoded", - "sync_wrapper 1.0.1", + "sync_wrapper", "tokio", "tower", "tower-layer", @@ -176,7 +176,7 @@ dependencies = [ "mime", "pin-project-lite", "rustversion", - "sync_wrapper 1.0.1", + "sync_wrapper", "tower-layer", "tower-service", ] @@ -2890,12 +2890,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "sync_wrapper" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" - [[package]] name = "sync_wrapper" version = "1.0.1" @@ -3128,14 +3122,14 @@ dependencies = [ [[package]] name = "tower" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2873938d487c3cfb9aed7546dc9f2711d867c9f90c46b889989a2cb84eba6b4f" +checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" dependencies = [ "futures-core", "futures-util", "pin-project-lite", - "sync_wrapper 0.1.2", + "sync_wrapper", "tokio", "tower-layer", "tower-service", diff --git a/src/database/indexer.rs b/src/database/indexer.rs index 4e9887e..c6a80a9 100644 --- a/src/database/indexer.rs +++ b/src/database/indexer.rs @@ -93,6 +93,7 @@ fn update_repository_metadata(scan_path: &Path, db: &rocksdb::DB) { (r.unix_timestamp(), r.offset().whole_seconds()) }, default_branch: find_default_branch(&git_repository).ok().flatten(), + exported: repository_path.join("git-daemon-export-ok").exists(), } .insert(db, relative); diff --git a/src/database/schema/mod.rs b/src/database/schema/mod.rs index a1fe2b8..3e6f177 100644 --- a/src/database/schema/mod.rs +++ b/src/database/schema/mod.rs @@ -9,4 +9,4 @@ pub mod tag; pub type Yoked = Yoke>; -pub const SCHEMA_VERSION: &str = "2"; +pub const SCHEMA_VERSION: &str = "3"; diff --git a/src/database/schema/repository.rs b/src/database/schema/repository.rs index 5733a38..8092c1c 100644 --- a/src/database/schema/repository.rs +++ b/src/database/schema/repository.rs @@ -28,6 +28,10 @@ pub struct Repository { pub last_modified: (i64, i32), /// The default branch for Git operations pub default_branch: Option, + /// Whether the repository is available for HTTP(s) cloning + /// + /// This is set to `true` based on the presence of `git-daemon-export-ok` in the repository + pub exported: bool, } pub type YokedRepository = Yoked<&'static ::Archived>; diff --git a/src/methods/repo/summary.rs b/src/methods/repo/summary.rs index 688690a..bed632a 100644 --- a/src/methods/repo/summary.rs +++ b/src/methods/repo/summary.rs @@ -2,7 +2,7 @@ use std::{collections::BTreeMap, sync::Arc}; use anyhow::Context; use askama::Template; -use axum::{response::IntoResponse, Extension}; +use axum::{extract::Host, response::IntoResponse, Extension}; use rkyv::string::ArchivedString; use crate::{ @@ -21,11 +21,14 @@ pub struct View { refs: Refs, commit_list: Vec, branch: Option>, + exported: bool, + host: String, } pub async fn handle( Extension(repo): Extension, Extension(db): Extension>, + Host(host): Host, ) -> Result { tokio::task::spawn_blocking(move || { let repository = crate::database::schema::repository::Repository::open(&db, &*repo)? @@ -57,6 +60,8 @@ pub async fn handle( refs: Refs { heads, tags }, commit_list: commits, branch: None, + exported: repository.get().exported, + host, })) }) .await diff --git a/templates/repo/summary.html b/templates/repo/summary.html index 64e0a4d..ad058f2 100644 --- a/templates/repo/summary.html +++ b/templates/repo/summary.html @@ -61,6 +61,30 @@ {%- endif %} + + {% if exported %} + + + + + + + + + Clone + + + + + + + + https://{{ host }}/{{ repo.display() }} + + + + + {%- endif %} {% endblock %}