Thanks to visit codestin.com
Credit goes to github.com

Skip to content

commit-graph: Introduce git_commit_list_generation_cmp #5766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/commit_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@
#include "odb.h"
#include "commit.h"

int git_commit_list_generation_cmp(const void *a, const void *b)
{
uint32_t generation_a = ((git_commit_list_node *) a)->generation;
uint32_t generation_b = ((git_commit_list_node *) b)->generation;

if (!generation_a || !generation_b) {
/* Fall back to comparing by timestamps if at least one commit lacks a generation. */
return git_commit_list_time_cmp(a, b);
}

if (generation_a < generation_b)
return 1;
if (generation_a > generation_b)
return -1;

return 0;
}

int git_commit_list_time_cmp(const void *a, const void *b)
{
int64_t time_a = ((git_commit_list_node *) a)->time;
Expand Down
1 change: 1 addition & 0 deletions src/commit_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ typedef struct git_commit_list {
} git_commit_list;

git_commit_list_node *git_commit_list_alloc_node(git_revwalk *walk);
int git_commit_list_generation_cmp(const void *a, const void *b);
int git_commit_list_time_cmp(const void *a, const void *b);
void git_commit_list_free(git_commit_list **list_p);
git_commit_list *git_commit_list_insert(git_commit_list_node *item, git_commit_list **list_p);
Expand Down
2 changes: 1 addition & 1 deletion src/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static int mark_parents(git_revwalk *walk, git_commit_list_node *one,
return 0;
}

if (git_pqueue_init(&list, 0, 2, git_commit_list_time_cmp) < 0)
if (git_pqueue_init(&list, 0, 2, git_commit_list_generation_cmp) < 0)
return -1;

if (git_commit_list_parse(walk, one) < 0)
Expand Down
2 changes: 1 addition & 1 deletion src/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ static int paint_down_to_common(
int error;
unsigned int i;

if (git_pqueue_init(&list, 0, twos->length * 2, git_commit_list_time_cmp) < 0)
if (git_pqueue_init(&list, 0, twos->length * 2, git_commit_list_generation_cmp) < 0)
return -1;

one->flags |= PARENT1;
Expand Down