Skip to content

Commit

Permalink
Fix gitweb owner not displaying
Browse files Browse the repository at this point in the history
  • Loading branch information
holly sparkles authored and w4 committed Dec 4, 2023
1 parent ea288c4 commit 5f03e4d
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 3 deletions.
73 changes: 72 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
18 changes: 16 additions & 2 deletions src/database/indexer.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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),
}
Expand Down Expand Up @@ -207,3 +210,14 @@ fn discover_repositories(current: &Path, discovered_repos: &mut Vec<PathBuf>) {
}
}
}

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)
}

0 comments on commit 5f03e4d

Please sign in to comment.