git2-rs
git2-rs copied to clipboard
[Documentation] Improve revwalk examples. Finding last change to file?
The revwalk documentation is unclear about how to find the last commit changing a file (a pretty basic usage).
Example:
fn recipe_modified(path: PathBuf) -> Result<i32, Box<dyn Error>> {
let repo = git2::Repository::discover(path)?;
let mut revwalk = repo.revwalk()?;
revwalk.push_head()?;
revwalk.set_sorting(git2::Sort::TIME)?;
for rev in revwalk {
let commit = repo.find_commit(rev?)?;
let message = commit.summary_bytes().unwrap_or_else(|| commit.message_bytes());
println!("{}\t{}", commit.id(), String::from_utf8_lossy(message));
}
Ok(0)
}
Here, provided a git repo, we pull all of the commits for it.. but I don't see a clear way to:
- Check the files included in a commit.
- Revwalk only on commits impacting a file.
This seems like a really common usage scenario, but little documentation on it,