mirror of
https://seed.radicle.dev/rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt.git
synced 2026-10-18 19:10:31 +08:00
Merge remote-tracking branch 'diff-pub'
* diff-pub: surf: Open Diff to custom construction Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
This commit is contained in:
@@ -97,17 +97,40 @@ impl Diff {
|
|||||||
&self.stats
|
&self.stats
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_modified(&mut self, path: PathBuf, diff: DiffContent, old: DiffFile, new: DiffFile) {
|
fn update_stats(&mut self, diff: &DiffContent) {
|
||||||
|
self.stats.files_changed += 1;
|
||||||
|
if let DiffContent::Plain { hunks, .. } = diff {
|
||||||
|
for h in hunks.iter() {
|
||||||
|
for l in &h.lines {
|
||||||
|
match l {
|
||||||
|
Modification::Addition(_) => self.stats.insertions += 1,
|
||||||
|
Modification::Deletion(_) => self.stats.deletions += 1,
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn insert_modified(
|
||||||
|
&mut self,
|
||||||
|
path: PathBuf,
|
||||||
|
diff: DiffContent,
|
||||||
|
old: DiffFile,
|
||||||
|
new: DiffFile,
|
||||||
|
) {
|
||||||
|
self.update_stats(&diff);
|
||||||
let diff = FileDiff::Modified(Modified {
|
let diff = FileDiff::Modified(Modified {
|
||||||
path,
|
path,
|
||||||
diff,
|
diff,
|
||||||
old,
|
old,
|
||||||
new,
|
new,
|
||||||
});
|
});
|
||||||
self.files.push(diff)
|
self.files.push(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_moved(&mut self, old_path: PathBuf, new_path: PathBuf) {
|
pub fn insert_moved(&mut self, old_path: PathBuf, new_path: PathBuf) {
|
||||||
|
self.update_stats(&DiffContent::Empty);
|
||||||
let diff = FileDiff::Moved(Moved {
|
let diff = FileDiff::Moved(Moved {
|
||||||
old_path,
|
old_path,
|
||||||
new_path,
|
new_path,
|
||||||
@@ -116,7 +139,8 @@ impl Diff {
|
|||||||
self.files.push(diff);
|
self.files.push(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_copied(&mut self, old_path: PathBuf, new_path: PathBuf) {
|
pub fn insert_copied(&mut self, old_path: PathBuf, new_path: PathBuf) {
|
||||||
|
self.update_stats(&DiffContent::Empty);
|
||||||
let diff = FileDiff::Copied(Copied {
|
let diff = FileDiff::Copied(Copied {
|
||||||
old_path,
|
old_path,
|
||||||
new_path,
|
new_path,
|
||||||
@@ -125,12 +149,14 @@ impl Diff {
|
|||||||
self.files.push(diff);
|
self.files.push(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_added(&mut self, path: PathBuf, diff: DiffContent, new: DiffFile) {
|
pub fn insert_added(&mut self, path: PathBuf, diff: DiffContent, new: DiffFile) {
|
||||||
|
self.update_stats(&diff);
|
||||||
let diff = FileDiff::Added(Added { path, diff, new });
|
let diff = FileDiff::Added(Added { path, diff, new });
|
||||||
self.files.push(diff);
|
self.files.push(diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_deleted(&mut self, path: PathBuf, diff: DiffContent, old: DiffFile) {
|
pub fn insert_deleted(&mut self, path: PathBuf, diff: DiffContent, old: DiffFile) {
|
||||||
|
self.update_stats(&diff);
|
||||||
let diff = FileDiff::Deleted(Deleted { path, diff, old });
|
let diff = FileDiff::Deleted(Deleted { path, diff, old });
|
||||||
self.files.push(diff);
|
self.files.push(diff);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -229,7 +229,6 @@ impl<'a> TryFrom<git2::Diff<'a>> for Diff {
|
|||||||
use git2::Delta;
|
use git2::Delta;
|
||||||
|
|
||||||
let mut diff = Diff::new();
|
let mut diff = Diff::new();
|
||||||
diff.stats = git_diff.stats()?.into();
|
|
||||||
|
|
||||||
for (idx, delta) in git_diff.deltas().enumerate() {
|
for (idx, delta) in git_diff.deltas().enumerate() {
|
||||||
match delta.status() {
|
match delta.status() {
|
||||||
|
|||||||
Reference in New Issue
Block a user