Skip to content

Commit 731218c

Browse files
committed
Merge branch 'jc/maint-log-first-parent-pathspec'
* jc/maint-log-first-parent-pathspec: Making pathspec limited log play nicer with --first-parent
2 parents a734e7e + 36ed191 commit 731218c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

revision.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ static int rev_same_tree_as_empty(struct rev_info *revs, struct commit *commit)
416416
static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
417417
{
418418
struct commit_list **pp, *parent;
419-
int tree_changed = 0, tree_same = 0;
419+
int tree_changed = 0, tree_same = 0, nth_parent = 0;
420420

421421
/*
422422
* If we don't do pruning, everything is interesting
@@ -444,6 +444,14 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
444444
while ((parent = *pp) != NULL) {
445445
struct commit *p = parent->item;
446446

447+
/*
448+
* Do not compare with later parents when we care only about
449+
* the first parent chain, in order to avoid derailing the
450+
* traversal to follow a side branch that brought everything
451+
* in the path we are limited to by the pathspec.
452+
*/
453+
if (revs->first_parent_only && nth_parent++)
454+
break;
447455
if (parse_commit(p) < 0)
448456
die("cannot simplify commit %s (because of %s)",
449457
sha1_to_hex(commit->object.sha1),

t/t6012-rev-list-simplify.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,6 @@ check_result 'I H E C B A' --full-history --date-order -- file
8686
check_result 'I E C B A' --simplify-merges -- file
8787
check_result 'I B A' -- file
8888
check_result 'I B A' --topo-order -- file
89+
check_result 'H' --first-parent -- another-file
8990

9091
test_done

0 commit comments

Comments
 (0)