rust-lang / rust-lang/git2-rs

[Documentation] Improve revwalk examples. Finding last change to file?

Open
#537 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.1k
Forks
450
Avg merge
11m
Merged PRs (30d)
1

Description

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,

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the revwalk documentation and the shown Repository::revwalk, push_head, set_sorting, and find_commit example. Check the git2-rs API for inspecting commit trees and restricting traversal, then update the documentation with clear examples for finding changed files and the last commit affecting a file; done means both common workflows are explained accurately.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, rust
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.