Skip to content

Commit eebdae6

Browse files
authored
Merge pull request #4657 from gitbutlerapp/rev-something
Revert "Merge pull request #4652 from gitbutlerapp/git2-to-gix"
2 parents 9a4b86a + 88496e6 commit eebdae6

File tree

28 files changed

+410
-532
lines changed

28 files changed

+410
-532
lines changed

Cargo.lock

Lines changed: 195 additions & 292 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ members = [
3333
resolver = "2"
3434

3535
[workspace.dependencies]
36-
bstr = { version = "1.10.0", features = ["serde"] }
3736
# Add the `tracing` or `tracing-detail` features to see more of gitoxide in the logs. Useful to see which programs it invokes.
38-
gix = { git = "https://github.com/Byron/gitoxide", rev = "7dff44754e0fdc369f92221468fb953bad9be60a", default-features = false, features = ["serde"] }
37+
gix = { git = "https://github.com/Byron/gitoxide", rev = "29898e3010bd3332418c683f2ac96aff5c8e72fa", default-features = false, features = [] }
3938
git2 = { version = "0.18.3", features = [
4039
"vendored-openssl",
4140
"vendored-libgit2",

crates/gitbutler-branch-actions/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ gitbutler-fs.workspace = true
2626
gitbutler-diff.workspace = true
2727
gitbutler-operating-modes.workspace = true
2828
serde = { workspace = true, features = ["std"] }
29-
bstr.workspace = true
29+
bstr = "1.10.0"
3030
diffy = "0.4.0"
3131
hex = "0.4.3"
3232
regex = "1.10"

crates/gitbutler-branch-actions/src/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ pub struct BaseBranch {
3131
pub remote_url: String,
3232
pub push_remote_name: Option<String>,
3333
pub push_remote_url: String,
34-
#[serde(with = "gitbutler_serde::oid")]
34+
#[serde(with = "gitbutler_serde::serde::oid")]
3535
pub base_sha: git2::Oid,
36-
#[serde(with = "gitbutler_serde::oid")]
36+
#[serde(with = "gitbutler_serde::serde::oid")]
3737
pub current_sha: git2::Oid,
3838
pub behind: usize,
3939
pub upstream_commits: Vec<RemoteCommit>,

crates/gitbutler-branch-actions/src/branch.rs

Lines changed: 63 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ use crate::VirtualBranchesExt;
22
use anyhow::{Context, Result};
33
use bstr::{BStr, BString, ByteSlice};
44
use core::fmt;
5-
use gitbutler_branch::{
6-
Branch as GitButlerBranch, BranchId, BranchIdentity, ReferenceExtGix, Target,
7-
};
5+
use gitbutler_branch::{Branch as GitButlerBranch, BranchId, ReferenceExtGix, Target};
86
use gitbutler_command_context::CommandContext;
97
use gitbutler_reference::normalize_branch_name;
108
use gix::prelude::ObjectIdExt;
@@ -35,12 +33,9 @@ pub fn list_branches(
3533
for reference in platform.all()?.filter_map(Result::ok) {
3634
// Loosely match on branch names
3735
if let Some(branch_names) = &filter_branch_names {
38-
let has_matching_name = branch_names.iter().any(|branch_name| {
39-
reference
40-
.name()
41-
.as_bstr()
42-
.ends_with_str(branch_name.as_bstr())
43-
});
36+
let has_matching_name = branch_names
37+
.iter()
38+
.any(|branch_name| reference.name().as_bstr().ends_with_str(&branch_name.0));
4439

4540
if !has_matching_name {
4641
continue;
@@ -194,13 +189,9 @@ fn branch_group_to_branch(
194189
};
195190

196191
if virtual_branch.is_none()
197-
&& local_branches.iter().any(|b| {
198-
b.name()
199-
.identity(remotes)
200-
.as_deref()
201-
.ok()
202-
.map_or(false, |identity| identity == target.branch.branch())
203-
})
192+
&& local_branches
193+
.iter()
194+
.any(|b| b.name().given_name(remotes).as_deref().ok() == Some(target.branch.branch()))
204195
{
205196
return Ok(None);
206197
}
@@ -212,10 +203,11 @@ fn branch_group_to_branch(
212203
in_workspace: branch.in_workspace,
213204
});
214205

215-
let mut remotes: Vec<gix::remote::Name<'static>> = Vec::new();
206+
// TODO(ST): keep the type alive, don't reduce to BString
207+
let mut remotes: Vec<BString> = Vec::new();
216208
for branch in remote_branches.iter() {
217209
if let Some(remote_name) = branch.remote_name(gix::remote::Direction::Fetch) {
218-
remotes.push(remote_name.to_owned());
210+
remotes.push(remote_name.as_bstr().into());
219211
}
220212
}
221213

@@ -301,7 +293,7 @@ impl GroupBranch<'_> {
301293
fn identity(&self, remotes: &BTreeSet<Cow<'_, BStr>>) -> Option<BranchIdentity> {
302294
match self {
303295
GroupBranch::Local(branch) | GroupBranch::Remote(branch) => {
304-
branch.name().identity(remotes).ok()
296+
branch.name().given_name(remotes).ok()
305297
}
306298
// The identity of a Virtual branch is derived from the source refname, upstream or the branch given name, in that order
307299
GroupBranch::Virtual(branch) => {
@@ -310,24 +302,25 @@ impl GroupBranch<'_> {
310302
let rich_name = branch.name.clone();
311303
let rich_name = normalize_branch_name(&rich_name).ok()?;
312304
let identity = name_from_source.unwrap_or(name_from_upstream.unwrap_or(&rich_name));
313-
Some(identity.into())
305+
Some(identity.to_string())
314306
}
315307
}
316-
.map(BranchIdentity::from)
308+
.map(BranchIdentity)
317309
}
318310
}
319311

320312
/// Determines if a branch should be listed in the UI.
321313
/// This excludes the target branch as well as gitbutler specific branches.
322314
fn should_list_git_branch(identity: &BranchIdentity) -> bool {
323315
// Exclude gitbutler technical branches (not useful for the user)
324-
const TECHNICAL_IDENTITIES: &[&[u8]] = &[
325-
b"gitbutler/integration",
326-
b"gitbutler/target",
327-
b"gitbutler/oplog",
328-
b"HEAD",
329-
];
330-
!TECHNICAL_IDENTITIES.contains(&identity.as_bytes())
316+
let is_technical = [
317+
"gitbutler/integration",
318+
"gitbutler/target",
319+
"gitbutler/oplog",
320+
"HEAD",
321+
]
322+
.contains(&&*identity.0);
323+
!is_technical
331324
}
332325

333326
/// A filter that can be applied to the branch listing
@@ -354,8 +347,8 @@ pub struct BranchListing {
354347
pub name: BranchIdentity,
355348
/// This is a list of remotes that this branch can be found on (e.g. `origin`, `upstream` etc.),
356349
/// by collecting remotes from all local branches with the same identity that have a tracking setup.
357-
#[serde(serialize_with = "gitbutler_serde::as_string_lossy_vec_remote_name")]
358-
pub remotes: Vec<gix::remote::Name<'static>>,
350+
#[serde(serialize_with = "gitbutler_serde::serde::as_string_lossy_vec")]
351+
pub remotes: Vec<BString>,
359352
/// The branch may or may not have a virtual branch associated with it.
360353
pub virtual_branch: Option<VirtualBranchReference>,
361354
/// Timestamp in milliseconds since the branch was last updated.
@@ -377,25 +370,52 @@ pub struct BranchListing {
377370
/// Represents a "commit author" or "signature", based on the data from the git history
378371
#[derive(Debug, Clone, Serialize, PartialEq, Eq, Hash)]
379372
pub struct Author {
373+
// TODO(ST): use `BString` here to not degenerate information
380374
/// The name of the author as configured in the git config
381-
pub name: Option<BString>,
375+
pub name: Option<String>,
382376
/// The email of the author as configured in the git config
383-
pub email: Option<BString>,
377+
pub email: Option<String>,
378+
}
379+
380+
/// The identity of a branch as to allow to group similar branches together.
381+
///
382+
/// * For *local* branches, it is what's left without the standard prefix, like `refs/heads`, e.g. `main`
383+
/// for `refs/heads/main` or `feat/one` for `refs/heads/feat/one`.
384+
/// * For *remote* branches, it is what's without the prefix and remote name, like `main` for `refs/remotes/origin/main`.
385+
/// or `feat/one` for `refs/remotes/my/special/remote/feat/one`.
386+
/// * For virtual branches, it's either the above if there is a `source_refname` or an `upstream`, or it's the normalized
387+
/// name of the virtual branch.
388+
#[derive(Debug, Clone, Serialize, PartialEq, Eq, Hash, Ord, PartialOrd)]
389+
pub struct BranchIdentity(String);
390+
391+
/// Facilitate obtaining this type from the UI - otherwise it would be better not to have it as it should be
392+
/// a particular thing, not any string.
393+
impl From<String> for BranchIdentity {
394+
fn from(value: String) -> Self {
395+
BranchIdentity(value)
396+
}
397+
}
398+
399+
/// Also not for testing.
400+
impl From<&str> for BranchIdentity {
401+
fn from(value: &str) -> Self {
402+
BranchIdentity(value.into())
403+
}
384404
}
385405

386406
impl From<git2::Signature<'_>> for Author {
387407
fn from(value: git2::Signature) -> Self {
388-
let name = value.name().map(str::to_string).map(Into::into);
389-
let email = value.email().map(str::to_string).map(Into::into);
408+
let name = value.name().map(str::to_string);
409+
let email = value.email().map(str::to_string);
390410
Author { name, email }
391411
}
392412
}
393413

394414
impl From<gix::actor::SignatureRef<'_>> for Author {
395415
fn from(value: gix::actor::SignatureRef<'_>) -> Self {
396416
Author {
397-
name: Some(value.name.to_owned()),
398-
email: Some(value.email.to_owned()),
417+
name: Some(value.name.to_string()),
418+
email: Some(value.email.to_string()),
399419
}
400420
}
401421
}
@@ -416,13 +436,9 @@ pub struct VirtualBranchReference {
416436
/// a list of enriched branch data in the form of `BranchData`.
417437
pub fn get_branch_listing_details(
418438
ctx: &CommandContext,
419-
branch_names: impl IntoIterator<Item = impl TryInto<BranchIdentity>>,
439+
branch_names: impl IntoIterator<Item = impl Into<BranchIdentity>>,
420440
) -> Result<Vec<BranchListingDetails>> {
421-
let branch_names: Vec<_> = branch_names
422-
.into_iter()
423-
.map(TryInto::try_into)
424-
.filter_map(Result::ok)
425-
.collect();
441+
let branch_names: Vec<_> = branch_names.into_iter().map(Into::into).collect();
426442
let repo = ctx.repository();
427443
let branches = list_branches(ctx, None, Some(branch_names.clone()))?;
428444
let default_target = ctx
@@ -520,10 +536,10 @@ pub struct BranchEntry {
520536
/// The name of the branch (e.g. `main`, `feature/branch`)
521537
pub name: String,
522538
/// The head commit of the branch
523-
#[serde(with = "gitbutler_serde::oid")]
539+
#[serde(with = "gitbutler_serde::serde::oid")]
524540
head: git2::Oid,
525541
/// The commit base of the branch
526-
#[serde(with = "gitbutler_serde::oid")]
542+
#[serde(with = "gitbutler_serde::serde::oid")]
527543
base: git2::Oid,
528544
/// The list of commits associated with the branch
529545
pub commits: Vec<CommitEntry>,
@@ -552,17 +568,18 @@ pub struct RemoteBranchEntry {
552568
#[serde(rename_all = "camelCase")]
553569
pub struct CommitEntry {
554570
/// The commit sha that it can be referenced by
555-
#[serde(with = "gitbutler_serde::oid")]
571+
#[serde(with = "gitbutler_serde::serde::oid")]
556572
pub id: git2::Oid,
557573
/// If the commit is referencing a specific change, this is its change id
558574
pub change_id: Option<String>,
559575
/// The commit message
576+
#[serde(serialize_with = "gitbutler_serde::serde::as_string_lossy")]
560577
pub description: BString,
561578
/// The timestamp of the commit in milliseconds
562579
pub created_at: u128,
563580
/// The author of the commit
564581
pub authors: Vec<Author>,
565582
/// The parent commits of the commit
566-
#[serde(with = "gitbutler_serde::oid_vec")]
583+
#[serde(with = "gitbutler_serde::serde::oid_vec")]
567584
pub parent_ids: Vec<git2::Oid>,
568585
}

crates/gitbutler-branch-actions/src/commit.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ use crate::{
2121
#[derive(Debug, PartialEq, Clone, Serialize)]
2222
#[serde(rename_all = "camelCase")]
2323
pub struct VirtualBranchCommit {
24-
#[serde(with = "gitbutler_serde::oid")]
24+
#[serde(with = "gitbutler_serde::serde::oid")]
2525
pub id: git2::Oid,
26+
#[serde(serialize_with = "gitbutler_serde::serde::as_string_lossy")]
2627
pub description: BString,
2728
pub created_at: u128,
2829
pub author: Author,
2930
pub is_remote: bool,
3031
pub files: Vec<VirtualBranchFile>,
3132
pub is_integrated: bool,
32-
#[serde(with = "gitbutler_serde::oid_vec")]
33+
#[serde(with = "gitbutler_serde::serde::oid_vec")]
3334
pub parent_ids: Vec<git2::Oid>,
3435
pub branch_id: BranchId,
3536
pub change_id: Option<String>,

crates/gitbutler-branch-actions/src/hunk.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use serde::Serialize;
2424
#[serde(rename_all = "camelCase")]
2525
pub struct VirtualBranchHunk {
2626
pub id: String,
27+
#[serde(serialize_with = "gitbutler_serde::serde::as_string_lossy")]
2728
pub diff: BString,
2829
pub modified_at: u128,
2930
pub file_path: PathBuf,
@@ -49,7 +50,7 @@ pub struct VirtualBranchHunk {
4950
#[serde(rename_all = "camelCase")]
5051
pub struct HunkLock {
5152
pub branch_id: BranchId,
52-
#[serde(with = "gitbutler_serde::oid")]
53+
#[serde(with = "gitbutler_serde::serde::oid")]
5354
pub commit_id: git2::Oid,
5455
}
5556

crates/gitbutler-branch-actions/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ mod commit;
4141
mod hunk;
4242

4343
pub use branch::{
44-
get_branch_listing_details, list_branches, Author, BranchListing, BranchListingDetails,
45-
BranchListingFilter,
44+
get_branch_listing_details, list_branches, Author, BranchIdentity, BranchListing,
45+
BranchListingDetails, BranchListingFilter,
4646
};

crates/gitbutler-branch-actions/src/remote.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::author::Author;
2323
#[derive(Debug, Clone, Serialize, PartialEq)]
2424
#[serde(rename_all = "camelCase")]
2525
pub struct RemoteBranch {
26-
#[serde(with = "gitbutler_serde::oid")]
26+
#[serde(with = "gitbutler_serde::serde::oid")]
2727
pub sha: git2::Oid,
2828
pub name: Refname,
2929
pub upstream: Option<RemoteRefname>,
@@ -36,25 +36,26 @@ pub struct RemoteBranch {
3636
#[derive(Debug, Clone, Serialize, PartialEq)]
3737
#[serde(rename_all = "camelCase")]
3838
pub struct RemoteBranchData {
39-
#[serde(with = "gitbutler_serde::oid")]
39+
#[serde(with = "gitbutler_serde::serde::oid")]
4040
pub sha: git2::Oid,
4141
pub name: Refname,
4242
pub upstream: Option<RemoteRefname>,
4343
pub behind: u32,
4444
pub commits: Vec<RemoteCommit>,
45-
#[serde(with = "gitbutler_serde::oid_opt", default)]
45+
#[serde(with = "gitbutler_serde::serde::oid_opt", default)]
4646
pub fork_point: Option<git2::Oid>,
4747
}
4848

4949
#[derive(Debug, Clone, PartialEq, Serialize)]
5050
#[serde(rename_all = "camelCase")]
5151
pub struct RemoteCommit {
5252
pub id: String,
53+
#[serde(serialize_with = "gitbutler_serde::serde::as_string_lossy")]
5354
pub description: BString,
5455
pub created_at: u128,
5556
pub author: Author,
5657
pub change_id: Option<String>,
57-
#[serde(with = "gitbutler_serde::oid_vec")]
58+
#[serde(with = "gitbutler_serde::serde::oid_vec")]
5859
pub parent_ids: Vec<git2::Oid>,
5960
}
6061

crates/gitbutler-branch-actions/src/virtual.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ pub struct VirtualBranch {
6868
pub updated_at: u128,
6969
pub selected_for_changes: bool,
7070
pub allow_rebasing: bool,
71-
#[serde(with = "gitbutler_serde::oid")]
71+
#[serde(with = "gitbutler_serde::serde::oid")]
7272
pub head: git2::Oid,
7373
/// The merge base between the target branch and the virtual branch
74-
#[serde(with = "gitbutler_serde::oid")]
74+
#[serde(with = "gitbutler_serde::serde::oid")]
7575
pub merge_base: git2::Oid,
7676
/// The fork point between the target branch and the virtual branch
77-
#[serde(with = "gitbutler_serde::oid_opt", default)]
77+
#[serde(with = "gitbutler_serde::serde::oid_opt", default)]
7878
pub fork_point: Option<git2::Oid>,
7979
}
8080

0 commit comments

Comments
 (0)