diff --git a/Cargo.lock b/Cargo.lock index 9e7e207..69639a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -517,6 +517,26 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "const-random" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aaf16c9c2c612020bcfd042e170f6e32de9b9d75adb5277cdbbd2e2c8c8299a" +dependencies = [ + "const-random-macro", +] + +[[package]] +name = "const-random-macro" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" +dependencies = [ + "getrandom", + "once_cell", + "tiny-keccak", +] + [[package]] name = "content_inspector" version = "0.2.4" @@ -576,6 +596,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + [[package]] name = "crypto-common" version = "0.1.6" @@ -632,6 +658,15 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "dlv-list" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "442039f5147480ba31067cb00ada1adae6892028e40e45fc5de7b7df6dcc1b5f" +dependencies = [ + "const-random", +] + [[package]] name = "encode_unicode" version = "0.3.6" @@ -960,6 +995,12 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + [[package]] name = "headers" version = "0.3.9" @@ -1097,7 +1138,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.12.3", ] [[package]] @@ -1472,6 +1513,16 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" +[[package]] +name = "ordered-multimap" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4d6a8c22fc714f0c2373e6091bf6f5e9b37b1bc0b1184874b7e0a4e303d318f" +dependencies = [ + "dlv-list", + "hashbrown 0.14.3", +] + [[package]] name = "overload" version = "0.1.1" @@ -1754,6 +1805,7 @@ dependencies = [ "parking_lot 0.12.1", "path-clean", "rsass", + "rust-ini", "serde", "sha2", "sled", @@ -1790,6 +1842,16 @@ dependencies = [ "tracing", ] +[[package]] +name = "rust-ini" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e0698206bcb8882bf2a9ecb4c1e7785db57ff052297085a6efd4fe42302068a" +dependencies = [ + "cfg-if", + "ordered-multimap", +] + [[package]] name = "rustc-demangle" version = "0.1.23" @@ -2209,6 +2271,15 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1710e589de0a76aaf295cd47a6699f6405737dbfd3cf2b75c92d000b548d0e6" +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + [[package]] name = "tinyvec" version = "1.6.0" diff --git a/Cargo.toml b/Cargo.toml index 7987ccb..c4f0279 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ futures = "0.3" git2 = "0.18.0" hex = "0.4" humantime = "2.1" +rust-ini = "0.20" nom = "7.1" md5 = "0.7" moka = { version = "0.12.0", features = ["future"] } diff --git a/src/database/indexer.rs b/src/database/indexer.rs index 8ea240f..f66dbb8 100644 --- a/src/database/indexer.rs +++ b/src/database/indexer.rs @@ -1,9 +1,11 @@ use std::{ + borrow::Cow, collections::HashSet, path::{Path, PathBuf}, }; use git2::Sort; +use ini::Ini; use time::OffsetDateTime; use tracing::{info, info_span}; @@ -44,13 +46,14 @@ fn update_repository_metadata(scan_path: &Path, db: &sled::Db) { let description = std::fs::read(repository.join("description")).unwrap_or_default(); let description = Some(String::from_utf8_lossy(&description)).filter(|v| !v.is_empty()); - let git_repository = git2::Repository::open(scan_path.join(relative)).unwrap(); + let repository_path = scan_path.join(relative); + let git_repository = git2::Repository::open(repository_path.clone()).unwrap(); Repository { id, name, description, - owner: None, // TODO read this from config + owner: find_gitweb_owner(repository_path.as_path()), last_modified: find_last_committed_time(&git_repository) .unwrap_or(OffsetDateTime::UNIX_EPOCH), } @@ -207,3 +210,14 @@ fn discover_repositories(current: &Path, discovered_repos: &mut Vec) { } } } + +fn find_gitweb_owner(repository_path: &Path) -> Option> { + // Load the Git config file and attempt to extract the owner from the "gitweb" section. + // If the owner is not found, an empty string is returned. + Ini::load_from_file(repository_path.join("config")) + .ok()? + .section(Some("gitweb")) + .and_then(|section| section.get("owner")) + .map(String::from) + .map(Cow::Owned) +}