diff options
author | Dmitry S. Dolzhenko <dmitrys.dolzhenko@yandex.ru> | 2014-02-26 22:49:22 +0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-02-27 10:55:27 -0800 |
commit | 0a9136f32758a785fe552adc58bba5824f85e5b7 (patch) | |
tree | c95cd5e054e86eba8adcb918e0bf11db180110ac /commit.c | |
parent | 5f95c9f850b19b368c43ae399cc831b17a26a5ac (diff) | |
download | git-0a9136f32758a785fe552adc58bba5824f85e5b7.tar.gz |
commit.c: use the generic "sha1_pos" function for lookupdd/find-graft-with-sha1-pos
Refactor binary search in "commit_graft_pos" function: use
generic "sha1_pos" function.
Signed-off-by: Dmitry S. Dolzhenko <dmitrys.dolzhenko@yandex.ru>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'commit.c')
-rw-r--r-- | commit.c | 24 |
1 files changed, 9 insertions, 15 deletions
@@ -10,6 +10,7 @@ #include "mergesort.h" #include "commit-slab.h" #include "prio-queue.h" +#include "sha1-lookup.h" static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **); @@ -114,23 +115,16 @@ static unsigned long parse_commit_date(const char *buf, const char *tail) static struct commit_graft **commit_graft; static int commit_graft_alloc, commit_graft_nr; +static const unsigned char *commit_graft_sha1_access(size_t index, void *table) +{ + struct commit_graft **commit_graft_table = table; + return commit_graft_table[index]->sha1; +} + static int commit_graft_pos(const unsigned char *sha1) { - int lo, hi; - lo = 0; - hi = commit_graft_nr; - while (lo < hi) { - int mi = (lo + hi) / 2; - struct commit_graft *graft = commit_graft[mi]; - int cmp = hashcmp(sha1, graft->sha1); - if (!cmp) - return mi; - if (cmp < 0) - hi = mi; - else - lo = mi + 1; - } - return -lo - 1; + return sha1_pos(sha1, commit_graft, commit_graft_nr, + commit_graft_sha1_access); } int register_commit_graft(struct commit_graft *graft, int ignore_dups) |