{"thread":{"id":"23106","subject":"[PATCH] commit: use the generic \"sha1_pos\" function to lookup sha1","startedAt":"2010-03-20T09:51:27Z","lastAt":"2010-03-20T09:51:27Z","messageCount":1,"participants":["Bo Yang"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"137322","messageId":"1269078687-14541-1-git-send-email-struggleyb.nku@gmail.com","threadId":"23106","inReplyTo":null,"subject":"[PATCH] commit: use the generic \"sha1_pos\" function to lookup sha1","fromName":"Bo Yang","fromEmail":"struggleyb.nku@gmail.com","sentAt":"2010-03-20T09:51:27Z","receivedAt":"2010-03-20T09:51:27Z","isPatch":true,"sender":{"key":"struggleyb.nku@gmail.com","avatar":"https://avatars.githubusercontent.com/u/233030?v=4"},"body":"Replace different binary search function with a generic one.\n\n\nSigned-off-by: Bo Yang <struggleyb.nku@gmail.com>\n---\n commit.c |   24 +++++++++---------------\n 1 files changed, 9 insertions(+), 15 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex 731191e..dba67d5 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@@ -79,23 +80,16 @@ 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_sha1_access(size_t index, void *table)\n+{\n+\tstruct commit_graft **graft = table;\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\tcommit_sha1_access);\n }\n \n int register_commit_graft(struct commit_graft *graft, int ignore_dups)\n-- \n1.7.0.2.273.gc2413.dirty\n"}]}