Skip to content

Commit d56f260

Browse files
codexByron
andcommitted
repo: make merge commit creation gix-first
Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
1 parent 53f3827 commit d56f260

4 files changed

Lines changed: 11 additions & 80 deletions

File tree

crates/gitbutler-repo/src/config.rs

Lines changed: 0 additions & 23 deletions
This file was deleted.

crates/gitbutler-repo/src/lib.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use gix::date::parse::TimeBuf;
2-
31
pub mod rebase;
42

53
mod commands;
@@ -32,17 +30,13 @@ mod repository_ext;
3230
pub use repository_ext::{RepositoryExt, commit_with_signature_gix, commit_without_signature_gix};
3331

3432
pub mod credentials;
35-
36-
mod config;
37-
use config::Config;
3833
pub mod hooks;
3934
pub mod managed_hooks;
4035
mod remote;
4136
pub mod staging;
4237

4338
pub mod commit_message;
4439

45-
use but_oxidize::gix_to_git2_signature;
4640
pub const GITBUTLER_COMMIT_AUTHOR_NAME: &str = "GitButler";
4741
pub const GITBUTLER_COMMIT_AUTHOR_EMAIL: &str = "gitbutler@gitbutler.com";
4842

@@ -51,13 +45,6 @@ pub enum SignaturePurpose {
5145
Committer,
5246
}
5347

54-
/// Provide a signature with the GitButler author, and the current time or the time overridden
55-
/// depending on the value for `purpose`.
56-
pub fn signature(purpose: SignaturePurpose) -> anyhow::Result<git2::Signature<'static>> {
57-
let signature = signature_gix(purpose);
58-
gix_to_git2_signature(signature.to_ref(&mut TimeBuf::default()))
59-
}
60-
6148
/// Provide a `gix` signature with the GitButler author and the current or overridden time.
6249
pub fn signature_gix(purpose: SignaturePurpose) -> gix::actor::Signature {
6350
gix::actor::Signature {

crates/gitbutler-repo/src/rebase.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
use std::path::PathBuf;
22

33
use anyhow::{Context as _, Result};
4+
use bstr::ByteSlice;
45
use but_core::{
56
RepositoryExt,
67
commit::{ConflictEntries, Headers},
78
};
89
use but_oxidize::{ObjectIdExt as _, OidExt as _};
910
use gitbutler_cherry_pick::{ConflictedTreeKey, GixRepositoryExt as _};
1011

11-
use crate::RepositoryExt as _;
12-
1312
fn extract_conflicted_files(
1413
merged_tree_id: gix::Id<'_>,
1514
merge_result: gix::merge::tree::Outcome<'_>,
@@ -166,22 +165,20 @@ pub fn merge_commits(
166165
Headers::new_with_random_change_id()
167166
};
168167

169-
let (author, committer) = repo.signatures()?;
170-
let target_commit = repo.find_commit(target_commit.id.to_git2())?;
171-
let incoming_commit = repo.find_commit(incoming_commit.id.to_git2())?;
172-
let commit_oid = crate::RepositoryExt::commit_with_signature(
173-
&repo,
168+
let (author, committer) = gix_repository.commit_signatures()?;
169+
let commit_oid = crate::commit_with_signature_gix(
170+
gix_repository,
174171
None,
175-
&author,
176-
&committer,
177-
resulting_name,
178-
&repo.find_tree(tree_oid).context("failed to find tree")?,
179-
&[&target_commit, &incoming_commit],
172+
author,
173+
committer,
174+
resulting_name.into(),
175+
tree_oid.to_gix(),
176+
&[target_commit.id, incoming_commit.id],
180177
Some(commit_headers),
181178
)
182179
.context("failed to create commit")?;
183180

184-
Ok(commit_oid.to_gix())
181+
Ok(commit_oid)
185182
}
186183
pub fn gitbutler_merge_commits<'repo>(
187184
repo: &'repo git2::Repository,

crates/gitbutler-repo/src/repository_ext.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@ use but_core::{
66
RepositoryExt as RepositoryExtGix,
77
commit::{Headers, SignCommit},
88
};
9-
use but_error::Code;
10-
use but_oxidize::{
11-
ObjectIdExt as _, OidExt, git2_signature_to_gix_signature, gix_to_git2_signature,
12-
};
9+
use but_oxidize::{ObjectIdExt as _, OidExt, git2_signature_to_gix_signature};
1310
use gitbutler_reference::{Refname, RemoteRefname};
1411

15-
use crate::{Config, SignaturePurpose};
16-
1712
/// Extension trait for `git2::Repository`.
1813
///
1914
/// For now, it collects useful methods from `gitbutler-core::git::Repository`
@@ -27,7 +22,6 @@ pub trait RepositoryExt {
2722
/// conflict with the libgit2 binding I upstreamed when it eventually
2823
/// gets merged.
2924
fn merge_base_octopussy(&self, ids: &[git2::Oid]) -> Result<git2::Oid>;
30-
fn signatures(&self) -> Result<(git2::Signature<'_>, git2::Signature<'_>)>;
3125

3226
fn remote_branches(&self) -> Result<Vec<RemoteRefname>>;
3327
fn remotes_as_string(&self) -> Result<Vec<String>>;
@@ -255,30 +249,6 @@ impl RepositoryExt for git2::Repository {
255249
.collect()
256250
}
257251

258-
fn signatures(&self) -> Result<(git2::Signature<'_>, git2::Signature<'_>)> {
259-
let repo = gix::open(self.path())?;
260-
261-
let author = repo
262-
.author()
263-
.transpose()?
264-
.map(gix_to_git2_signature)
265-
.transpose()?
266-
.context("No author is configured in Git")
267-
.context(Code::AuthorMissing)?;
268-
269-
let config: Config = (&repo).into();
270-
let committer = if config.user_real_comitter()? {
271-
repo.committer()
272-
.transpose()?
273-
.map(gix_to_git2_signature)
274-
.unwrap_or_else(|| crate::signature(SignaturePurpose::Committer))
275-
} else {
276-
crate::signature(SignaturePurpose::Committer)
277-
}?;
278-
279-
Ok((author, committer))
280-
}
281-
282252
fn merge_base_octopussy(&self, ids: &[git2::Oid]) -> Result<git2::Oid> {
283253
if ids.len() < 2 {
284254
bail!("Merge base octopussy requires at least two commit ids to operate on");

0 commit comments

Comments
 (0)