Revert "remove unnecessary BString-related serde functions."

This reverts commit 3043f099b7.

We actually need this - me removing it just means it wasn't properly
documented and clarified in the type-system as to why this is needed.
This commit is contained in:
Sebastian Thiel 2024-08-09 10:37:23 +02:00
parent 4c76e2a6ee
commit acbd42fce3
No known key found for this signature in database
GPG Key ID: 9CB5EE7895E8268B
7 changed files with 22 additions and 2 deletions

View File

@ -33,7 +33,7 @@ members = [
resolver = "2"
[workspace.dependencies]
bstr = { version = "1.10.0", features = ["serde"] }
bstr = "1.10.0"
# Add the `tracing` or `tracing-detail` features to see more of gitoxide in the logs. Useful to see which programs it invokes.
gix = { git = "https://github.com/Byron/gitoxide", rev = "7dff44754e0fdc369f92221468fb953bad9be60a", default-features = false, features = ["serde"] }
git2 = { version = "0.18.3", features = [

View File

@ -557,6 +557,7 @@ pub struct CommitEntry {
/// If the commit is referencing a specific change, this is its change id
pub change_id: Option<String>,
/// The commit message
#[serde(serialize_with = "gitbutler_serde::as_string_lossy")]
pub description: BString,
/// The timestamp of the commit in milliseconds
pub created_at: u128,

View File

@ -23,6 +23,7 @@ use crate::{
pub struct VirtualBranchCommit {
#[serde(with = "gitbutler_serde::oid")]
pub id: git2::Oid,
#[serde(serialize_with = "gitbutler_serde::as_string_lossy")]
pub description: BString,
pub created_at: u128,
pub author: Author,

View File

@ -24,6 +24,7 @@ use serde::Serialize;
#[serde(rename_all = "camelCase")]
pub struct VirtualBranchHunk {
pub id: String,
#[serde(serialize_with = "gitbutler_serde::as_string_lossy")]
pub diff: BString,
pub modified_at: u128,
pub file_path: PathBuf,

View File

@ -50,6 +50,7 @@ pub struct RemoteBranchData {
#[serde(rename_all = "camelCase")]
pub struct RemoteCommit {
pub id: String,
#[serde(serialize_with = "gitbutler_serde::as_string_lossy")]
pub description: BString,
pub created_at: u128,
pub author: Author,

View File

@ -49,7 +49,7 @@ pub struct GitHunk {
pub new_start: u32,
pub new_lines: u32,
/// The `+`, `-` or ` ` prefixed lines of the diff produced by `git2`, along with their line separator.
#[serde(rename = "diff")]
#[serde(rename = "diff", serialize_with = "gitbutler_serde::as_string_lossy")]
pub diff_lines: BString,
pub binary: bool,
pub change_type: ChangeType,

View File

@ -1,5 +1,21 @@
use bstr::{BString, ByteSlice};
use serde::Serialize;
pub fn as_string_lossy<S>(v: &BString, s: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
v.to_str_lossy().serialize(s)
}
pub fn as_string_lossy_vec<S>(v: &[BString], s: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let vec: Vec<String> = v.iter().map(|v| v.to_string()).collect();
vec.serialize(s)
}
pub fn as_string_lossy_vec_remote_name<S>(
v: &[gix::remote::Name<'static>],
s: S,