Replace gix with configurable libgit2 diffs

This commit is contained in:
Georg Bauer
2026-07-28 18:25:24 +02:00
parent ed2226bc60
commit 31f6426eef
9 changed files with 410 additions and 1295 deletions

View File

@@ -368,31 +368,31 @@ impl App {
}
fn read_git_state(path: &Path) -> Option<GitState> {
let repository = gix::discover(path).ok()?;
let repository = git2::Repository::discover(path).ok()?;
let mut branches = repository
.references()
.branches(Some(git2::BranchType::Local))
.ok()?
.local_branches()
.ok()?
.map(|reference| {
reference
.map(|reference| String::from_utf8_lossy(reference.name().shorten()).into_owned())
.map(|branch| {
branch.and_then(|(branch, _)| {
branch
.name_bytes()
.map(|name| String::from_utf8_lossy(name).into_owned())
})
})
.collect::<Result<Vec<_>, _>>()
.ok()?;
branches.sort();
branches.dedup();
let current = repository
.head_name()
.ok()?
.map(|name| String::from_utf8_lossy(name.shorten()).into_owned());
let head = repository.find_reference("HEAD").ok()?;
let current = head.symbolic_target_bytes().and_then(|target| {
target
.strip_prefix(b"refs/heads/")
.map(|name| String::from_utf8_lossy(name).into_owned())
});
let label = current.clone().unwrap_or_else(|| {
repository
.head_id()
.ok()
.and_then(|id| id.shorten().ok())
.map(|id| format!("detached @ {id}"))
head.target()
.map(|id| format!("detached @ {}", &id.to_string()[..7]))
.unwrap_or_else(|| "No branch".to_owned())
});
Some(GitState {