Skip to content

Commit b806433

Browse files
committed
Use gix::remote::Name for type-safety.
1 parent 74990e9 commit b806433

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,10 @@ fn branch_group_to_branch(
204204
});
205205

206206
// TODO(ST): keep the type alive, don't reduce to BString
207-
let mut remotes: Vec<BString> = Vec::new();
207+
let mut remotes: Vec<gix::remote::Name<'static>> = Vec::new();
208208
for branch in remote_branches.iter() {
209209
if let Some(remote_name) = branch.remote_name(gix::remote::Direction::Fetch) {
210-
remotes.push(remote_name.as_bstr().into());
210+
remotes.push(remote_name.to_owned());
211211
}
212212
}
213213

@@ -347,8 +347,8 @@ pub struct BranchListing {
347347
pub name: BranchIdentity,
348348
/// This is a list of remotes that this branch can be found on (e.g. `origin`, `upstream` etc.),
349349
/// by collecting remotes from all local branches with the same identity that have a tracking setup.
350-
#[serde(serialize_with = "gitbutler_serde::as_string_lossy_vec")]
351-
pub remotes: Vec<BString>,
350+
#[serde(serialize_with = "gitbutler_serde::as_string_lossy_vec_remote_name")]
351+
pub remotes: Vec<gix::remote::Name<'static>>,
352352
/// The branch may or may not have a virtual branch associated with it.
353353
pub virtual_branch: Option<VirtualBranchReference>,
354354
/// Timestamp in milliseconds since the branch was last updated.

crates/gitbutler-serde/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ publish = false
77

88
[dependencies]
99
git2.workspace = true
10+
gix.workspace = true
1011
serde = { workspace = true, features = ["std"]}
1112
bstr = "1.10.0"

crates/gitbutler-serde/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ where
1616
vec.serialize(s)
1717
}
1818

19+
pub fn as_string_lossy_vec_remote_name<S>(
20+
v: &[gix::remote::Name<'static>],
21+
s: S,
22+
) -> Result<S::Ok, S::Error>
23+
where
24+
S: serde::Serializer,
25+
{
26+
let vec: Vec<String> = v.iter().map(|v| v.as_bstr().to_string()).collect();
27+
vec.serialize(s)
28+
}
29+
1930
pub fn as_time_seconds_from_unix_epoch<S>(v: &git2::Time, s: S) -> Result<S::Ok, S::Error>
2031
where
2132
S: serde::Serializer,

0 commit comments

Comments
 (0)