Skip to content

Commit

Permalink
Merge remote-tracking branch 'seb/sebastinez/fileDiff-path'
Browse files Browse the repository at this point in the history
* seb/sebastinez/fileDiff-path:
  surf: Add `FileDiff::path` method

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
  • Loading branch information
FintanH committed Jul 24, 2023
2 parents f9360d8 + 43c3564 commit b1984bd
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion radicle-surf/src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@

//! Types that represent diff(s) in a Git repo.

use std::{borrow::Cow, ops::Range, path::PathBuf, string::FromUtf8Error};
use std::{
borrow::Cow,
ops::Range,
path::{Path, PathBuf},
string::FromUtf8Error,
};

#[cfg(feature = "serde")]
use serde::{ser, ser::SerializeStruct, Serialize, Serializer};
Expand Down Expand Up @@ -287,6 +292,18 @@ pub enum FileDiff {
Copied(Copied),
}

impl FileDiff {
pub fn path(&self) -> &Path {
match self {
FileDiff::Added(x) => x.path.as_path(),
FileDiff::Deleted(x) => x.path.as_path(),
FileDiff::Modified(x) => x.path.as_path(),
FileDiff::Moved(x) => x.new_path.as_path(),
FileDiff::Copied(x) => x.new_path.as_path(),
}
}
}

#[cfg(feature = "serde")]
impl Serialize for FileDiff {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
Expand Down

0 comments on commit b1984bd

Please sign in to comment.