Skip to content

Commit f216f1f

Browse files
codexByron
andcommitted
repo: drop dead git2 repo extension methods
Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
1 parent 9a8a654 commit f216f1f

1 file changed

Lines changed: 3 additions & 74 deletions

File tree

crates/gitbutler-repo/src/repository_ext.rs

Lines changed: 3 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
use std::str;
22

3-
use anyhow::{Context as _, Result, anyhow, bail};
4-
use bstr::{BStr, BString};
3+
use anyhow::{Context as _, Result, bail};
4+
use bstr::BStr;
55
use but_core::{
66
RepositoryExt as RepositoryExtGix,
77
commit::{Headers, SignCommit},
88
};
99
use but_oxidize::{ObjectIdExt as _, OidExt, git2_signature_to_gix_signature};
10-
use gitbutler_reference::{Refname, RemoteRefname};
10+
use gitbutler_reference::Refname;
1111

1212
/// Extension trait for `git2::Repository`.
1313
///
1414
/// For now, it collects useful methods from `gitbutler-core::git::Repository`
1515
pub trait RepositoryExt {
16-
fn find_branch_by_refname(&self, name: &Refname) -> Result<git2::Branch<'_>>;
1716
/// Returns the common ancestor of the given commit Oids.
1817
///
1918
/// This is like `git merge-base --octopus`.
@@ -22,20 +21,8 @@ pub trait RepositoryExt {
2221
/// conflict with the libgit2 binding I upstreamed when it eventually
2322
/// gets merged.
2423
fn merge_base_octopussy(&self, ids: &[git2::Oid]) -> Result<git2::Oid>;
25-
26-
fn remote_branches(&self) -> Result<Vec<RemoteRefname>>;
27-
fn remotes_as_string(&self) -> Result<Vec<String>>;
28-
/// `buffer` is the commit object to sign, but in theory could be anything to compute the signature for.
29-
/// Returns the computed signature.
30-
fn sign_buffer(&self, buffer: &[u8]) -> Result<BString>;
3124
fn checkout_tree_builder<'a>(&'a self, tree: &'a git2::Tree<'a>) -> CheckoutTreeBuidler<'a>;
3225
fn maybe_find_branch_by_refname(&self, name: &Refname) -> Result<Option<git2::Branch<'_>>>;
33-
/// Returns the `gitbutler/workspace` branch if the head currently points to it, or fail otherwise.
34-
/// Use it before any modification to the repository, or extra defensively each time the
35-
/// workspace is needed.
36-
///
37-
/// This is for safety to assure the repository actually is in 'gitbutler mode'.
38-
fn workspace_ref_from_head(&self) -> Result<git2::Reference<'_>>;
3926

4027
#[expect(clippy::too_many_arguments)]
4128
fn commit_with_signature(
@@ -164,31 +151,6 @@ impl RepositoryExt for git2::Repository {
164151
}
165152
}
166153

167-
fn find_branch_by_refname(&self, name: &Refname) -> Result<git2::Branch<'_>> {
168-
let branch = self.find_branch(
169-
&name.simple_name(),
170-
match name {
171-
Refname::Virtual(_) | Refname::Local(_) | Refname::Other(_) => {
172-
git2::BranchType::Local
173-
}
174-
Refname::Remote(_) => git2::BranchType::Remote,
175-
},
176-
)?;
177-
178-
Ok(branch)
179-
}
180-
181-
fn workspace_ref_from_head(&self) -> Result<git2::Reference<'_>> {
182-
let head_ref = self.head().context("BUG: head must point to a reference")?;
183-
if head_ref.name_bytes() == b"refs/heads/gitbutler/workspace" {
184-
Ok(head_ref)
185-
} else {
186-
Err(anyhow!(
187-
"Unexpected state: cannot perform operation on non-workspace branch"
188-
))
189-
}
190-
}
191-
192154
fn commit_with_signature(
193155
&self,
194156
update_ref: Option<&Refname>,
@@ -216,39 +178,6 @@ impl RepositoryExt for git2::Repository {
216178
.map(|oid| oid.to_git2())
217179
}
218180

219-
fn sign_buffer(&self, buffer: &[u8]) -> Result<BString> {
220-
but_core::commit::sign_buffer(&gix::open(self.path())?, buffer)
221-
}
222-
223-
fn remotes_as_string(&self) -> Result<Vec<String>> {
224-
Ok(gix::open(self.path())?
225-
.remote_names()
226-
.iter()
227-
.map(|name| name.to_string())
228-
.collect())
229-
}
230-
231-
fn remote_branches(&self) -> Result<Vec<RemoteRefname>> {
232-
use bstr::ByteSlice;
233-
234-
let repo = gix::open_opts(self.path(), gix::open::Options::isolated())?;
235-
repo.references()?
236-
.remote_branches()?
237-
.filter_map(Result::ok)
238-
// TODO: the question is if we really need this? Probably not, but it's part
239-
// of the `gix` migration and we'd rather play it safe. Goal is for `gitbutler-` crates
240-
// to not exist anyway.
241-
.filter(|reference| !reference.name().as_bstr().ends_with_str("/HEAD"))
242-
.map(|reference| {
243-
reference
244-
.name()
245-
.to_string()
246-
.parse()
247-
.context("failed to convert branch to remote name")
248-
})
249-
.collect()
250-
}
251-
252181
fn merge_base_octopussy(&self, ids: &[git2::Oid]) -> Result<git2::Oid> {
253182
if ids.len() < 2 {
254183
bail!("Merge base octopussy requires at least two commit ids to operate on");

0 commit comments

Comments
 (0)