Skip to content

Commit 53454be

Browse files
authored
Merge pull request libgit2#4157 from adamniedzielski/4099-git-sort-time-uninteresting
Skip uninteresting commits in revwalk timesort iterator
2 parents 0b3623a + c11c08a commit 53454be

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/revwalk.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,12 @@ static int revwalk_next_timesort(git_commit_list_node **object_out, git_revwalk
231231
{
232232
git_commit_list_node *next;
233233

234-
if ((next = git_pqueue_pop(&walk->iterator_time)) != NULL) {
235-
*object_out = next;
236-
return 0;
234+
while ((next = git_pqueue_pop(&walk->iterator_time)) != NULL) {
235+
/* Some commits might become uninteresting after being added to the list */
236+
if (!next->uninteresting) {
237+
*object_out = next;
238+
return 0;
239+
}
237240
}
238241

239242
giterr_clear();

tests/revwalk/basic.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,26 @@ void test_revwalk_basic__topo_crash(void)
345345
git_revwalk_next(&oid, _walk);
346346
}
347347

348+
void test_revwalk_basic__from_new_to_old(void)
349+
{
350+
git_oid from_oid, to_oid, oid;
351+
int i = 0;
352+
353+
revwalk_basic_setup_walk(NULL);
354+
git_revwalk_sorting(_walk, GIT_SORT_TIME);
355+
356+
cl_git_pass(git_oid_fromstr(&to_oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644"));
357+
cl_git_pass(git_oid_fromstr(&from_oid, "a4a7dce85cf63874e984719f4fdd239f5145052f"));
358+
359+
cl_git_pass(git_revwalk_push(_walk, &to_oid));
360+
cl_git_pass(git_revwalk_hide(_walk, &from_oid));
361+
362+
while (git_revwalk_next(&oid, _walk) == 0)
363+
i++;
364+
365+
cl_assert_equal_i(i, 0);
366+
}
367+
348368
void test_revwalk_basic__push_range(void)
349369
{
350370
revwalk_basic_setup_walk(NULL);

0 commit comments

Comments
 (0)