diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-09-21 15:15:25 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-09-21 15:15:25 -0700 |
commit | ee198369950023a49cb383951794e0263b6a8446 (patch) | |
tree | a860d8dda9b2160ed6c7084997e3e65dab6257ae /sha1_file.c | |
parent | 48e1f8ed017295b1ba5e2e26752842a50f5e35cd (diff) | |
parent | c4c6effa9bdb14e65b147e4e96be55860b73df05 (diff) | |
download | git-ee198369950023a49cb383951794e0263b6a8446.tar.gz |
Merge branch 'rs/pack-sort-with-llist-mergesort'
Code cleanup.
* rs/pack-sort-with-llist-mergesort:
sha1_file: use llist_mergesort() for sorting packs
Diffstat (limited to 'sha1_file.c')
-rw-r--r-- | sha1_file.c | 39 |
1 files changed, 15 insertions, 24 deletions
diff --git a/sha1_file.c b/sha1_file.c index 46b25edcb3..b9c1fa3f1a 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -25,6 +25,7 @@ #include "dir.h" #include "mru.h" #include "list.h" +#include "mergesort.h" #ifndef O_NOATIME #if defined(__linux__) && (defined(__i386__) || defined(__PPC__)) @@ -1380,10 +1381,20 @@ static void prepare_packed_git_one(char *objdir, int local) strbuf_release(&path); } +static void *get_next_packed_git(const void *p) +{ + return ((const struct packed_git *)p)->next; +} + +static void set_next_packed_git(void *p, void *next) +{ + ((struct packed_git *)p)->next = next; +} + static int sort_pack(const void *a_, const void *b_) { - struct packed_git *a = *((struct packed_git **)a_); - struct packed_git *b = *((struct packed_git **)b_); + const struct packed_git *a = a_; + const struct packed_git *b = b_; int st; /* @@ -1410,28 +1421,8 @@ static int sort_pack(const void *a_, const void *b_) static void rearrange_packed_git(void) { - struct packed_git **ary, *p; - int i, n; - - for (n = 0, p = packed_git; p; p = p->next) - n++; - if (n < 2) - return; - - /* prepare an array of packed_git for easier sorting */ - ary = xcalloc(n, sizeof(struct packed_git *)); - for (n = 0, p = packed_git; p; p = p->next) - ary[n++] = p; - - qsort(ary, n, sizeof(struct packed_git *), sort_pack); - - /* link them back again */ - for (i = 0; i < n - 1; i++) - ary[i]->next = ary[i + 1]; - ary[n - 1]->next = NULL; - packed_git = ary[0]; - - free(ary); + packed_git = llist_mergesort(packed_git, get_next_packed_git, + set_next_packed_git, sort_pack); } static void prepare_packed_git_mru(void) |