mirror of
https://seed.radicle.dev/rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt.git
synced 2026-10-25 06:10:32 +08:00
git: Update serialization for copied files
Use the same way of serialization of moved files for copied files
This commit is contained in:
@@ -220,7 +220,7 @@ impl Serialize for Moved {
|
||||
S: Serializer,
|
||||
{
|
||||
if self.old == self.new {
|
||||
let mut state = serializer.serialize_struct("Moved", 2)?;
|
||||
let mut state = serializer.serialize_struct("Moved", 3)?;
|
||||
state.serialize_field("oldPath", &self.old_path)?;
|
||||
state.serialize_field("newPath", &self.new_path)?;
|
||||
state.serialize_field("current", &self.new)?;
|
||||
@@ -238,7 +238,6 @@ impl Serialize for Moved {
|
||||
}
|
||||
|
||||
/// A file that was copied within a [`Diff`].
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "camelCase"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Copied {
|
||||
/// The old path to this file, relative to the repository root.
|
||||
@@ -250,6 +249,30 @@ pub struct Copied {
|
||||
pub diff: DiffContent,
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl Serialize for Copied {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
if self.old == self.new {
|
||||
let mut state = serializer.serialize_struct("Copied", 3)?;
|
||||
state.serialize_field("oldPath", &self.old_path)?;
|
||||
state.serialize_field("newPath", &self.new_path)?;
|
||||
state.serialize_field("current", &self.new)?;
|
||||
state.end()
|
||||
} else {
|
||||
let mut state = serializer.serialize_struct("Copied", 5)?;
|
||||
state.serialize_field("oldPath", &self.old_path)?;
|
||||
state.serialize_field("newPath", &self.new_path)?;
|
||||
state.serialize_field("old", &self.old)?;
|
||||
state.serialize_field("new", &self.new)?;
|
||||
state.serialize_field("diff", &self.diff)?;
|
||||
state.end()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "camelCase"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum EofNewLine {
|
||||
|
||||
@@ -303,24 +303,11 @@ fn test_diff_serde() -> Result<(), Error> {
|
||||
"state": "moved"
|
||||
},
|
||||
{
|
||||
"diff": {
|
||||
"eof": "noneMissing",
|
||||
"hunks": [],
|
||||
"stats": {
|
||||
"additions": 0,
|
||||
"deletions": 0,
|
||||
},
|
||||
"type": "plain",
|
||||
},
|
||||
"new": {
|
||||
"current": {
|
||||
"mode": "blob",
|
||||
"oid": "5e07534cd74a6a9b2ccd2729b181c4ef26173a5e",
|
||||
},
|
||||
"newPath": "file_operations/copied.md",
|
||||
"old": {
|
||||
"mode": "blob",
|
||||
"oid": "5e07534cd74a6a9b2ccd2729b181c4ef26173a5e",
|
||||
},
|
||||
"oldPath": "README.md",
|
||||
"state": "copied"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user