This is done by stepping through a branch iterator to diff commits to see where they changed. This is somewhat computationally intensive, and also doesn't work well yet because iterator stepping is done internally and there is no API to extend iterators before they are run. That means that histories can only be read from first-parent iterators. Ideally we would do two things here: 1. build an API to let iterators extend themselves, either breadth first, or depth first. But maybe that would be too much complexity for the iterator module? 2. figure out a better way to get the history of a file. At the moment we are stepping through commits and diffing them with parents to find the set of changed paths. I don't _think_ there is a way to simply compare refs, but maybe there is.wip/yesman
parent
9cc32b516d
commit
a2513a72e6
@ -1,5 +1,32 @@ |
|||||||
|
|
||||||
/// A diff between two commits
|
/// 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 { |
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); |
||||||
|
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue