Skip to content

Commit a8e1d71

Browse files
committed
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
2 parents 90e6255 + 0a9136f commit a8e1d71

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

commit.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "mergesort.h"
1111
#include "commit-slab.h"
1212
#include "prio-queue.h"
13+
#include "sha1-lookup.h"
1314

1415
static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **);
1516

@@ -114,23 +115,16 @@ static unsigned long parse_commit_date(const char *buf, const char *tail)
114115
static struct commit_graft **commit_graft;
115116
static int commit_graft_alloc, commit_graft_nr;
116117

118+
static const unsigned char *commit_graft_sha1_access(size_t index, void *table)
119+
{
120+
struct commit_graft **commit_graft_table = table;
121+
return commit_graft_table[index]->sha1;
122+
}
123+
117124
static int commit_graft_pos(const unsigned char *sha1)
118125
{
119-
int lo, hi;
120-
lo = 0;
121-
hi = commit_graft_nr;
122-
while (lo < hi) {
123-
int mi = (lo + hi) / 2;
124-
struct commit_graft *graft = commit_graft[mi];
125-
int cmp = hashcmp(sha1, graft->sha1);
126-
if (!cmp)
127-
return mi;
128-
if (cmp < 0)
129-
hi = mi;
130-
else
131-
lo = mi + 1;
132-
}
133-
return -lo - 1;
126+
return sha1_pos(sha1, commit_graft, commit_graft_nr,
127+
commit_graft_sha1_access);
134128
}
135129

136130
int register_commit_graft(struct commit_graft *graft, int ignore_dups)

0 commit comments

Comments
 (0)