{"thread":{"id":"27522","subject":"[PATCH] commit: use generic sha1_pos()","startedAt":"2011-06-01T13:20:16Z","lastAt":"2011-06-01T13:20:16Z","messageCount":1,"participants":["Felipe Balbi"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"169113","messageId":"1306934416-4205-1-git-send-email-balbi@ti.com","threadId":"27522","inReplyTo":null,"subject":"[PATCH] commit: use generic sha1_pos()","fromName":"Felipe Balbi","fromEmail":"balbi@ti.com","sentAt":"2011-06-01T13:20:16Z","receivedAt":"2011-06-01T13:20:16Z","isPatch":true,"sender":{"key":"balbi@ti.com","avatar":null},"body":"instead of reimplementing the binary search,\nuse the generic sha1_pos().\n\nSigned-off-by: Felipe Balbi <balbi@ti.com>\n---\n commit.c |   25 ++++++++++---------------\n 1 files changed, 10 insertions(+), 15 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex ac337c7..ee8788f 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -6,6 +6,7 @@\n #include \"diff.h\"\n #include \"revision.h\"\n #include \"notes.h\"\n+#include \"sha1-lookup.h\"\n \n int save_commit_buffer = 1;\n \n@@ -92,23 +93,17 @@ static unsigned long parse_commit_date(const char *buf, const char *tail)\n static struct commit_graft **commit_graft;\n static int commit_graft_alloc, commit_graft_nr;\n \n+static const unsigned char *commit_graft_access(size_t index, void *table)\n+{\n+\tstruct commit_graft **graft = table;\n+\n+\treturn graft[index]->sha1;\n+}\n+\n static int commit_graft_pos(const unsigned char *sha1)\n {\n-\tint lo, hi;\n-\tlo = 0;\n-\thi = commit_graft_nr;\n-\twhile (lo < hi) {\n-\t\tint mi = (lo + hi) / 2;\n-\t\tstruct commit_graft *graft = commit_graft[mi];\n-\t\tint cmp = hashcmp(sha1, graft->sha1);\n-\t\tif (!cmp)\n-\t\t\treturn mi;\n-\t\tif (cmp < 0)\n-\t\t\thi = mi;\n-\t\telse\n-\t\t\tlo = mi + 1;\n-\t}\n-\treturn -lo - 1;\n+\treturn sha1_pos(sha1, commit_graft, commit_graft_nr,\n+\t\t\tcommit_graft_access);\n }\n \n int register_commit_graft(struct commit_graft *graft, int ignore_dups)\n-- \n1.7.5.1.300.gc565c\n"}]}