blob: e83903cf6ebc0b294ddab0d0b2def379751439cb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
/// A diff between two commits
///
/// At the moment this type doesn't properly express a Diff, and is
/// only used to compute the change set between commits to generate a
/// file history.
pub struct Diff {
paths: Vec<String>,
}
impl Diff {
/// Generate a new Diff from a git2::Diff
pub(crate) fn from(d: git2::Diff) -> Self {
Self {
paths: d.deltas().fold(vec![], |mut vec, delta| {
append(&mut vec, delta.old_file());
append(&mut vec, delta.new_file());
vec
}),
}
}
/// Get all paths touched by a diff
pub fn get_paths(&self) -> Vec<String> {
self.paths.clone()
}
}
fn append(vec: &mut Vec<String>, f: git2::DiffFile) {
if let Some(path) = f.path().map(|p| p.to_str().unwrap().into()) {
vec.push(path);
}
}
|