{"thread":{"id":"2193","subject":"[PATCH 1/4] git-upload-pack: More efficient usage of the has_sha1 array","startedAt":"2005-10-23T01:36:06Z","lastAt":"2005-10-23T01:36:06Z","messageCount":1,"participants":["Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"10473","messageId":"Pine.LNX.4.63.0510230335280.21239@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2193","inReplyTo":null,"subject":"[PATCH 1/4] git-upload-pack: More efficient usage of the has_sha1 array","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-10-23T01:36:06Z","receivedAt":"2005-10-23T01:36:06Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"This patch is based on Junio's proposal. It marks parents of common revs \nso that they do not clutter up the has_sha1 array.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n upload-pack.c |   25 ++++++++++++++++++++-----\n 1 files changed, 20 insertions(+), 5 deletions(-)\n\napplies-to: ccef5ac580c68a9714f37dcd8ee433e9691b640a\n69e13cda85a74200b25ed48ed81909d848a7b9cb\ndiff --git a/upload-pack.c b/upload-pack.c\nindex accdba6..ab1981c 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -3,9 +3,11 @@\n #include \"pkt-line.h\"\n #include \"tag.h\"\n #include \"object.h\"\n+#include \"commit.h\"\n \n static const char upload_pack_usage[] = \"git-upload-pack [--strict] [--timeout=nn] <dir>\";\n \n+#define THEY_HAVE (1U << 0)\n #define MAX_HAS 256\n #define MAX_NEEDS 256\n static int nr_has = 0, nr_needs = 0;\n@@ -85,15 +87,25 @@ static void create_pack_file(void)\n \n static int got_sha1(char *hex, unsigned char *sha1)\n {\n-\tint nr;\n \tif (get_sha1_hex(hex, sha1))\n \t\tdie(\"git-upload-pack: expected SHA1 object, got '%s'\", hex);\n \tif (!has_sha1_file(sha1))\n \t\treturn 0;\n-\tnr = nr_has;\n-\tif (nr < MAX_HAS) {\n-\t\tmemcpy(has_sha1[nr], sha1, 20);\n-\t\tnr_has = nr+1;\n+\tif (nr_has < MAX_HAS) {\n+\t\tstruct object *o = lookup_object(sha1);\n+\t\tif (!o || (!o->parsed && !parse_object(sha1)))\n+\t\t\tdie(\"oops (%s)\", sha1_to_hex(sha1));\n+\t\tif (o->type == commit_type) {\n+\t\t\tstruct commit_list *parents;\n+\t\t\tif (o->flags & THEY_HAVE)\n+\t\t\t\treturn 0;\n+\t\t\to->flags |= THEY_HAVE;\n+\t\t\tfor (parents = ((struct commit*)o)->parents;\n+\t\t\t     parents;\n+\t\t\t     parents = parents->next)\n+\t\t\t\tparents->item->object.flags |= THEY_HAVE;\n+\t\t}\n+\t\tmemcpy(has_sha1[nr_has++], sha1, 20);\n \t}\n \treturn 1;\n }\n@@ -104,6 +116,9 @@ static int get_common_commits(void)\n \tunsigned char sha1[20];\n \tint len;\n \n+\ttrack_object_refs = 0;\n+\tsave_commit_buffer = 0;\n+\n \tfor(;;) {\n \t\tlen = packet_read_line(0, line, sizeof(line));\n \t\treset_timeout();\n---\n0.99.8.GIT\n"}]}