🏡 index : ~doyle/rgit.git

author holly sparkles <sparkles@holly.sh> 2023-12-03 19:35:42.0 +01:00:00
committer Jordan Doyle <jordan@doyle.la> 2023-12-04 17:33:12.0 +00:00:00
commit
5f03e4d71acda2d7b8e9eb9619ec838432bf5f59 [patch]
tree
9bfc4460e35c81f0a905670e39778d947327c4c4
parent
ea288c4a8a0245793144b621e1ce317aaf3e0d5e
download
5f03e4d71acda2d7b8e9eb9619ec838432bf5f59.tar.gz

Fix gitweb owner not displaying



Diff

 Cargo.lock              | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 Cargo.toml              |  1 +
 src/database/indexer.rs | 18 ++++++++++++++++++
 3 files changed, 89 insertions(+), 3 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 9e7e207..69639a6 100644
--- a/Cargo.lock
+++ a/Cargo.lock
@@ -518,6 +518,26 @@
]

[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -575,6 +595,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"
@@ -630,6 +656,15 @@
 "option-ext",
 "redox_users",
 "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]]
@@ -961,6 +996,12 @@
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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1097,7 +1138,7 @@
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
dependencies = [
 "autocfg",
 "hashbrown",
 "hashbrown 0.12.3",
]

[[package]]
@@ -1471,6 +1512,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"
@@ -1754,6 +1805,7 @@
 "parking_lot 0.12.1",
 "path-clean",
 "rsass",
 "rust-ini",
 "serde",
 "sha2",
 "sled",
@@ -1791,6 +1843,16 @@
]

[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2208,6 +2270,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"
diff --git a/Cargo.toml b/Cargo.toml
index 7987ccb..c4f0279 100644
--- a/Cargo.toml
+++ a/Cargo.toml
@@ -22,6 +22,7 @@
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
+++ a/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 @@
        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),
        }
@@ -206,4 +209,15 @@
            discover_repositories(&dir, discovered_repos);
        }
    }
}

fn find_gitweb_owner(repository_path: &Path) -> Option<Cow<'_, str>> {
    // 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)
}