Merge branch 'dd/find-graft-with-sha1-pos'
authorJunio C Hamano <gitster@pobox.com>
Tue, 18 Mar 2014 20:50:11 +0000 (13:50 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 18 Mar 2014 20:50:11 +0000 (13:50 -0700)
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

1  2 
commit.c
diff --combined commit.c
index fa401ae7b06f3c62345ccaec08b89757966687c1,6ceee6acbc0a6c3c44d38e91c9f138a89fb3d075..a2639473833a6d41d8aabb73444cc5ef37b2ea23
+++ b/commit.c
@@@ -10,6 -10,7 +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 +115,16 @@@ static unsigned long parse_commit_date(
  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)
@@@ -548,7 -542,7 +542,7 @@@ define_commit_slab(author_date_slab, un
  static void record_author_date(struct author_date_slab *author_date,
                               struct commit *commit)
  {
 -      const char *buf, *line_end;
 +      const char *buf, *line_end, *ident_line;
        char *buffer = NULL;
        struct ident_split ident;
        char *date_end;
             buf;
             buf = line_end + 1) {
                line_end = strchrnul(buf, '\n');
 -              if (!starts_with(buf, "author ")) {
 +              ident_line = skip_prefix(buf, "author ");
 +              if (!ident_line) {
                        if (!line_end[0] || line_end[1] == '\n')
                                return; /* end of header */
                        continue;
                }
                if (split_ident_line(&ident,
 -                                   buf + strlen("author "),
 -                                   line_end - (buf + strlen("author "))) ||
 +                                   ident_line, line_end - ident_line) ||
                    !ident.date_begin || !ident.date_end)
                        goto fail_exit; /* malformed "author" line */
                break;
@@@ -1193,8 -1187,10 +1187,8 @@@ static void parse_gpg_output(struct sig
        for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
                const char *found, *next;
  
 -              if (starts_with(buf, sigcheck_gpg_status[i].check + 1)) {
 -                      /* At the very beginning of the buffer */
 -                      found = buf + strlen(sigcheck_gpg_status[i].check + 1);
 -              } else {
 +              found = skip_prefix(buf, sigcheck_gpg_status[i].check + 1);
 +              if (!found) {
                        found = strstr(buf, sigcheck_gpg_status[i].check);
                        if (!found)
                                continue;