Skip to content

Commit

Permalink
git log example include empty parents and paths
Browse files Browse the repository at this point in the history
- Also remember to test for empty list of paths and permit that through
  the filter as `any()` returns false on empty - likewise this applies
  to the check on list of parent_ids.
  • Loading branch information
metatoaster committed Jul 16, 2023
1 parent 0df9f70 commit bd59bbe
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions gix/examples/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ fn run(args: &Args) -> anyhow::Result<()> {
.map_or(true, |info| {
info.parent_ids.len() <= max_parents &&
info.parent_ids.len() >= min_parents &&
// if the list of paths is empty the filter passes.
// if paths are provided check that any one of them are
// in fact relevant for the current commit.
args.paths.iter().map(|path| {
(args.paths.is_empty() || args.paths.iter().map(|path| {
// TODO should make use of the `git2::DiffOptions`
// counterpart in gix for a set of files and also to
// generate diffs.
Expand All @@ -107,7 +108,11 @@ fn run(args: &Args) -> anyhow::Result<()> {
// commit's parents; if any pairs don't match,
// this indicates this path was changed in this
// commit thus should be included in output.
Ok(oid) => info.parent_ids
// naturally, root commits have no parents and
// by definition whatever paths in there must
// have been introduced there, so include them.
Ok(oid) => info.parent_ids.is_empty() || info
.parent_ids
.iter()
.any(|id| {
repo.rev_parse_single(
Expand All @@ -119,7 +124,7 @@ fn run(args: &Args) -> anyhow::Result<()> {
Err(_) => false,
}
})
.any(|r| r)
.any(|r| r))
})
)
.map(|info| {
Expand Down

0 comments on commit bd59bbe

Please sign in to comment.