consolidate git operations into a Repo type

This commit is contained in:
2026-10-03 12:46:44 +07:00
parent 4656f1340b
commit 49d351fe06
21 changed files with 2243 additions and 2203 deletions
+18 -26
View File
@@ -22,10 +22,7 @@ use gpui_component::{
};
use nostr::prelude::*;
use signed_core::{Announcement, RepoAddr};
use signed_git::{
delete_refs_with_prefix, fetch_repo_refs, fork_namespace, merge_base, refs_with_prefix,
worktree_commit_range_commits, worktree_commit_range_diff,
};
use signed_git::{GitCache, Repo};
use signed_state::{
Backend, CheckoutsStore, RepoListStore, RepoStore, ensure_repo_mirror, repo_mirror_path,
};
@@ -399,10 +396,12 @@ impl NewPullRequestView {
.background_spawn({
let path = path.clone();
async move {
let repo = gix::open(Path::new(&path)).ok()?;
let branches =
signed_git::worktree_branches(Path::new(&path)).unwrap_or_default();
let current = signed_git::current_branch(&repo).ok().flatten();
let repo = Repo::try_open(Path::new(&path));
let branches = repo
.as_ref()
.and_then(|repo| repo.branches().ok())
.unwrap_or_default();
let current = repo.as_ref().and_then(|repo| repo.current_branch());
Some((branches, current))
}
})
@@ -533,7 +532,7 @@ impl NewPullRequestView {
return;
};
let mirror_path = repo_mirror_path(&base);
let namespace = fork_namespace(&announcement);
let namespace = GitCache::fork_namespace(&announcement);
let clone_urls = announcement.clone.clone();
let base_clone_urls: Vec<Url> = self
@@ -568,13 +567,13 @@ impl NewPullRequestView {
let mirror_path = mirror_path.clone();
async move {
ensure_repo_mirror(&base, &base_clone_urls)?;
let repo = Repo::open(&mirror_path)?;
// Prune stale imports of any fork. Then import this fork's heads under its namespace.
delete_refs_with_prefix(&mirror_path, "refs/fork")?;
repo.delete_refs_with_prefix("refs/fork")?;
// Fetch the fork's refs and import them under the fork's namespace.
fetch_repo_refs(
&mirror_path,
repo.fetch_refs(
&clone_urls,
&format!("+refs/heads/*:refs/fork/{namespace}/*"),
)?;
@@ -594,12 +593,12 @@ impl NewPullRequestView {
};
let base_branches = strip(
refs_with_prefix(&mirror_path, "refs/remotes/origin")?,
repo.refs_with_prefix("refs/remotes/origin")?,
"refs/remotes/origin",
);
let compare_branches = strip(
refs_with_prefix(&mirror_path, &format!("refs/fork/{namespace}"))?,
repo.refs_with_prefix(&format!("refs/fork/{namespace}"))?,
&format!("refs/fork/{namespace}"),
);
@@ -773,24 +772,17 @@ impl NewPullRequestView {
let base_name = base_name.clone();
let compare_name = compare_name.clone();
async move {
let merge_base = merge_base(Path::new(&repo_path), &base, &compare)?
.ok_or_else(|| {
let repo = Repo::open(Path::new(&repo_path))?;
let merge_base =
repo.merge_base(&base, &compare)?.ok_or_else(|| {
anyhow::anyhow!(
"{base_name} and {compare_name} share no common ancestor"
)
})?;
let commits = worktree_commit_range_commits(
Path::new(&repo_path),
&merge_base,
&compare,
)?;
let commits = repo.commit_range(&merge_base, &compare)?;
let diff = worktree_commit_range_diff(
Path::new(&repo_path),
&merge_base,
&compare,
)?;
let diff = repo.range_diff(&merge_base, &compare)?;
Ok::<_, anyhow::Error>((merge_base, commits, diff))
}