From 84d0e868537c1597fbd0830b5201696f677c1484 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Fri, 03 Jan 2025 20:32:25 +0700 Subject: [PATCH] Add clone URL display Adapted from https://git.holly.sh/sparkle-git.git/commit/?id=3f19c49c63ed70bd50001f07c180d1b4595737dc --- Cargo.lock | 16 ++++++---------- src/database/indexer.rs | 1 + templates/repo/summary.html | 24 ++++++++++++++++++++++++ src/database/schema/mod.rs | 2 +- src/database/schema/repository.rs | 4 ++++ src/methods/repo/summary.rs | 7 ++++++- 6 files changed, 41 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6c91cdb..5ed9c71 100644 --- a/Cargo.lock +++ a/Cargo.lock @@ -154,7 +154,7 @@ "rustversion", "serde", "serde_urlencoded", - "sync_wrapper 1.0.1", + "sync_wrapper", "tokio", "tower", "tower-layer", @@ -176,7 +176,7 @@ "mime", "pin-project-lite", "rustversion", - "sync_wrapper 1.0.1", + "sync_wrapper", "tower-layer", "tower-service", ] @@ -2892,12 +2892,6 @@ [[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" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" @@ -3128,14 +3122,14 @@ [[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 +++ a/src/database/indexer.rs @@ -93,6 +93,7 @@ (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/templates/repo/summary.html b/templates/repo/summary.html index 64e0a4d..ad058f2 100644 --- a/templates/repo/summary.html +++ a/templates/repo/summary.html @@ -61,6 +61,30 @@ {%- endif %} + + {% if exported %} + + + + + + + + + Clone + + + + + + + + https://{{ host }}/{{ repo.display() }} + + + + + {%- endif %} {% endblock %} diff --git a/src/database/schema/mod.rs b/src/database/schema/mod.rs index a1fe2b8..3e6f177 100644 --- a/src/database/schema/mod.rs +++ a/src/database/schema/mod.rs @@ -9,4 +9,4 @@ 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 +++ a/src/database/schema/repository.rs @@ -28,6 +28,10 @@ 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 +++ a/src/methods/repo/summary.rs @@ -1,8 +1,8 @@ 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 @@ 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 @@ refs: Refs { heads, tags }, commit_list: commits, branch: None, + exported: repository.get().exported, + host, })) }) .await -- rgit 0.1.4