Merge branch 'dd/find-graft-with-sha1-pos'

Replace a hand-rolled binary search with a call to our generic
binary search helper function.

* dd/find-graft-with-sha1-pos:
  commit.c: use the generic "sha1_pos" function for lookup
This commit is contained in:
Junio C Hamano 2014-03-18 13:50:11 -07:00
commit a8e1d711cc

View File

@ -10,6 +10,7 @@
#include "mergesort.h" #include "mergesort.h"
#include "commit-slab.h" #include "commit-slab.h"
#include "prio-queue.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 **); 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 struct commit_graft **commit_graft;
static int commit_graft_alloc, commit_graft_nr; 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) static int commit_graft_pos(const unsigned char *sha1)
{ {
int lo, hi; return sha1_pos(sha1, commit_graft, commit_graft_nr,
lo = 0; commit_graft_sha1_access);
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;
} }
int register_commit_graft(struct commit_graft *graft, int ignore_dups) int register_commit_graft(struct commit_graft *graft, int ignore_dups)