Skip to content

Commit dd28abc

Browse files
committed
Merge branch 'jk/fetch-pack-many-refs'
Fetching between repositories with many refs employed O(n^2) algorithm to match up the common objects, which has been corrected. * jk/fetch-pack-many-refs: fetch-pack: avoid quadratic behavior in rev_list_push commit.c: make compare_commits_by_commit_date global fetch-pack: avoid quadratic list insertion in mark_complete
2 parents 0da7a53 + 099327b commit dd28abc

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ static int compare_commits_by_author_date(const void *a_, const void *b_,
581581
return 0;
582582
}
583583

584-
static int compare_commits_by_commit_date(const void *a_, const void *b_, void *unused)
584+
int compare_commits_by_commit_date(const void *a_, const void *b_, void *unused)
585585
{
586586
const struct commit *a = a_, *b = b_;
587587
/* newer commits with larger date first */

commit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,6 @@ extern void print_commit_list(struct commit_list *list,
254254
*/
255255
extern void check_commit_signature(const struct commit* commit, struct signature_check *sigc);
256256

257+
int compare_commits_by_commit_date(const void *a_, const void *b_, void *unused);
258+
257259
#endif /* COMMIT_H */

fetch-pack.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "run-command.h"
1212
#include "transport.h"
1313
#include "version.h"
14+
#include "prio-queue.h"
1415

1516
static int transfer_unpack_limit = -1;
1617
static int fetch_unpack_limit = -1;
@@ -37,7 +38,7 @@ static int marked;
3738
*/
3839
#define MAX_IN_VAIN 256
3940

40-
static struct commit_list *rev_list;
41+
static struct prio_queue rev_list = { compare_commits_by_commit_date };
4142
static int non_common_revs, multi_ack, use_sideband, allow_tip_sha1_in_want;
4243

4344
static void rev_list_push(struct commit *commit, int mark)
@@ -49,7 +50,7 @@ static void rev_list_push(struct commit *commit, int mark)
4950
if (parse_commit(commit))
5051
return;
5152

52-
commit_list_insert_by_date(commit, &rev_list);
53+
prio_queue_put(&rev_list, commit);
5354

5455
if (!(commit->object.flags & COMMON))
5556
non_common_revs++;
@@ -122,10 +123,10 @@ static const unsigned char *get_rev(void)
122123
unsigned int mark;
123124
struct commit_list *parents;
124125

125-
if (rev_list == NULL || non_common_revs == 0)
126+
if (rev_list.nr == 0 || non_common_revs == 0)
126127
return NULL;
127128

128-
commit = rev_list->item;
129+
commit = prio_queue_get(&rev_list);
129130
if (!commit->object.parsed)
130131
parse_commit(commit);
131132
parents = commit->parents;
@@ -152,8 +153,6 @@ static const unsigned char *get_rev(void)
152153
mark_common(parents->item, 1, 0);
153154
parents = parents->next;
154155
}
155-
156-
rev_list = rev_list->next;
157156
}
158157

159158
return commit->object.sha1;
@@ -442,7 +441,7 @@ static int find_common(struct fetch_pack_args *args,
442441
in_vain = 0;
443442
got_continue = 1;
444443
if (ack == ACK_ready) {
445-
rev_list = NULL;
444+
clear_prio_queue(&rev_list);
446445
got_ready = 1;
447446
}
448447
break;
@@ -505,7 +504,7 @@ static int mark_complete(const char *refname, const unsigned char *sha1, int fla
505504
struct commit *commit = (struct commit *)o;
506505
if (!(commit->object.flags & COMPLETE)) {
507506
commit->object.flags |= COMPLETE;
508-
commit_list_insert_by_date(commit, &complete);
507+
commit_list_insert(commit, &complete);
509508
}
510509
}
511510
return 0;
@@ -622,6 +621,7 @@ static int everything_local(struct fetch_pack_args *args,
622621
if (!args->depth) {
623622
for_each_ref(mark_complete, NULL);
624623
for_each_alternate_ref(mark_alternate_complete, NULL);
624+
commit_list_sort_by_date(&complete);
625625
if (cutoff)
626626
mark_recent_complete_commits(args, cutoff);
627627
}

0 commit comments

Comments
 (0)