Skip to content

Commit

Permalink
surf: Add DiffFile to FileDiff::Copied and FileDiff::Moved
Browse files Browse the repository at this point in the history
This allows us to know the blob oid of a moved or copied file, even when
no diff is available.

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
  • Loading branch information
sebastinez committed Sep 21, 2023
1 parent 1872717 commit e4454d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion radicle-surf/src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,12 @@ impl Diff {
self.files.push(diff);
}

pub fn insert_copied(&mut self, old_path: PathBuf, new_path: PathBuf) {
pub fn insert_copied(&mut self, old_path: PathBuf, new_path: PathBuf, copy: DiffFile) {
self.update_stats(&DiffContent::Empty);
let diff = FileDiff::Copied(Copied {
old_path,
new_path,
copy,
diff: DiffContent::Empty,
});
self.files.push(diff);
Expand Down Expand Up @@ -213,6 +214,7 @@ impl Serialize for Moved {
let mut state = serializer.serialize_struct("Moved", 2)?;
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("Moved", 5)?;
Expand All @@ -234,6 +236,7 @@ pub struct Copied {
pub old_path: PathBuf,
/// The new path to this file, relative to the repository root.
pub new_path: PathBuf,
pub copy: DiffFile,
pub diff: DiffContent,
}

Expand Down
3 changes: 2 additions & 1 deletion radicle-surf/src/diff/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ fn copied(diff: &mut Diff, delta: &git2::DiffDelta<'_>) -> Result<(), error::Dif
.new_file()
.path()
.ok_or(error::Diff::PathUnavailable)?;
let copy = DiffFile::try_from(delta.new_file())?;

diff.insert_copied(old.to_path_buf(), new.to_path_buf());
diff.insert_copied(old.to_path_buf(), new.to_path_buf(), copy);
Ok(())
}

0 comments on commit e4454d1

Please sign in to comment.