Skip to content

Commit 45dc219

Browse files
author
Edward Thomson
authored
Merge pull request libgit2#3921 from libgit2/cmn/walk-limit-enough
Improve revision walk preparation logic
2 parents d11fcf8 + fedc05c commit 45dc219

28 files changed

+407
-205
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ v0.24 + 1
1515

1616
* Support for reading and writing git index v4 files
1717

18+
* Improve the performance of the revwalk and bring us closer to git's code.
19+
1820
### API additions
1921

2022
* You can now get the user-agent used by libgit2 using the

include/git2/revwalk.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,15 @@ GIT_BEGIN_DECL
2525
*/
2626
typedef enum {
2727
/**
28-
* Sort the repository contents in no particular ordering;
29-
* this sorting is arbitrary, implementation-specific
30-
* and subject to change at any time.
28+
* Sort the output with the same default time-order method from git.
3129
* This is the default sorting for new walkers.
3230
*/
3331
GIT_SORT_NONE = 0,
3432

3533
/**
36-
* Sort the repository contents in topological order
37-
* (parents before children); this sorting mode
38-
* can be combined with time sorting.
34+
* Sort the repository contents in topological order (parents before
35+
* children); this sorting mode can be combined with time sorting to
36+
* produce git's "time-order".
3937
*/
4038
GIT_SORT_TOPOLOGICAL = 1 << 0,
4139

src/commit_list.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@
1313

1414
int git_commit_list_time_cmp(const void *a, const void *b)
1515
{
16-
const git_commit_list_node *commit_a = a;
17-
const git_commit_list_node *commit_b = b;
16+
int64_t time_a = ((git_commit_list_node *) a)->time;
17+
int64_t time_b = ((git_commit_list_node *) b)->time;
1818

19-
return (commit_a->time < commit_b->time);
19+
if (time_a < time_b)
20+
return 1;
21+
if (time_a > time_b)
22+
return -1;
23+
24+
return 0;
2025
}
2126

2227
git_commit_list *git_commit_list_insert(git_commit_list_node *item, git_commit_list **list_p)

src/commit_list.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ typedef struct git_commit_list_node {
2828
uninteresting:1,
2929
topo_delay:1,
3030
parsed:1,
31+
added:1,
3132
flags : FLAG_BITS;
3233

3334
unsigned short in_degree;

src/pqueue.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,23 @@ int git_pqueue_insert(git_pqueue *pq, void *item)
9393
(void)git_pqueue_pop(pq);
9494
}
9595

96-
if (!(error = git_vector_insert(pq, item)))
96+
if (!(error = git_vector_insert(pq, item)) && pq->_cmp)
9797
pqueue_up(pq, pq->length - 1);
9898

9999
return error;
100100
}
101101

102102
void *git_pqueue_pop(git_pqueue *pq)
103103
{
104-
void *rval = git_pqueue_get(pq, 0);
104+
void *rval;
105105

106-
if (git_pqueue_size(pq) > 1) {
106+
if (!pq->_cmp) {
107+
rval = git_vector_last(pq);
108+
} else {
109+
rval = git_pqueue_get(pq, 0);
110+
}
111+
112+
if (git_pqueue_size(pq) > 1 && pq->_cmp) {
107113
/* move last item to top of heap, shrink, and push item down */
108114
pq->contents[0] = git_vector_last(pq);
109115
git_vector_pop(pq);

src/pqueue.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ extern int git_pqueue_init(
3535
#define git_pqueue_clear git_vector_clear
3636
#define git_pqueue_size git_vector_length
3737
#define git_pqueue_get git_vector_get
38+
#define git_pqueue_reverse git_vector_reverse
3839

3940
/**
4041
* Insert a new item into the queue

src/rebase.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ static int rebase_init_operations(
586586
(error = git_revwalk_hide(revwalk, git_annotated_commit_id(upstream))) < 0)
587587
goto done;
588588

589-
git_revwalk_sorting(revwalk, GIT_SORT_REVERSE | GIT_SORT_TIME);
589+
git_revwalk_sorting(revwalk, GIT_SORT_REVERSE);
590590

591591
while ((error = git_revwalk_next(&id, revwalk)) == 0) {
592592
if ((error = git_commit_lookup(&commit, repo, &id)) < 0)

0 commit comments

Comments
 (0)