{"thread":{"id":"425","subject":"[PATCH] Do not call fetch() when we have it.","startedAt":"2005-05-02T00:10:40Z","lastAt":"2005-05-02T00:10:40Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"2339","messageId":"7voebuqygv.fsf@assigned-by-dhcp.cox.net","threadId":"425","inReplyTo":null,"subject":"[PATCH] Do not call fetch() when we have it.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-02T00:10:40Z","receivedAt":"2005-05-02T00:10:40Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Currently pull() calls fetch() without checking whether we have\nthe wanted object but all of the existing fetch()\nimplementations perform this check and return success\nthemselves.  This patch moves the check to the caller.\n\nI will be sending a trivial git-local-pull which depends on\nthis in the next message.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\nhttp-pull.c |    4 ----\npull.c      |   17 ++++++++++++-----\nrpull.c     |    2 --\n3 files changed, 12 insertions(+), 11 deletions(-)\n\n# - date handling: handle \"AM\"/\"PM\" on time\n# + working-tree\n--- k/http-pull.c\n+++ l/http-pull.c\n@@ -53,10 +53,6 @@ int fetch(unsigned char *sha1)\n \tchar *url;\n \tchar *posn;\n \n-\tif (has_sha1_file(sha1)) {\n-\t\treturn 0;\n-\t}\n-\n \tlocal = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0666);\n \n \tif (local < 0)\n--- k/pull.c\n+++ l/pull.c\n@@ -8,6 +8,13 @@ int get_tree = 0;\n int get_history = 0;\n int get_all = 0;\n \n+static int make_sure_we_have_it(unsigned char *sha1)\n+{\n+\tif (has_sha1_file(sha1))\n+\t\treturn 0;\n+\treturn fetch(sha1);\t\n+}\n+\n static int process_tree(unsigned char *sha1)\n {\n \tstruct tree *tree = lookup_tree(sha1);\n@@ -17,7 +24,7 @@ static int process_tree(unsigned char *s\n \t\treturn -1;\n \n \tfor (entries = tree->entries; entries; entries = entries->next) {\n-\t\tif (fetch(entries->item.tree->object.sha1))\n+\t\tif (make_sure_we_have_it(entries->item.tree->object.sha1))\n \t\t\treturn -1;\n \t\tif (entries->directory) {\n \t\t\tif (process_tree(entries->item.tree->object.sha1))\n@@ -31,14 +38,14 @@ static int process_commit(unsigned char \n {\n \tstruct commit *obj = lookup_commit(sha1);\n \n-\tif (fetch(sha1))\n+\tif (make_sure_we_have_it(sha1))\n \t\treturn -1;\n \n \tif (parse_commit(obj))\n \t\treturn -1;\n \n \tif (get_tree) {\n-\t\tif (fetch(obj->tree->object.sha1))\n+\t\tif (make_sure_we_have_it(obj->tree->object.sha1))\n \t\t\treturn -1;\n \t\tif (process_tree(obj->tree->object.sha1))\n \t\t\treturn -1;\n@@ -50,7 +57,7 @@ static int process_commit(unsigned char \n \t\tfor (; parents; parents = parents->next) {\n \t\t\tif (has_sha1_file(parents->item->object.sha1))\n \t\t\t\tcontinue;\n-\t\t\tif (fetch(parents->item->object.sha1)) {\n+\t\t\tif (make_sure_we_have_it(parents->item->object.sha1)) {\n \t\t\t\t/* The server might not have it, and\n \t\t\t\t * we don't mind. \n \t\t\t\t */\n@@ -70,7 +77,7 @@ int pull(char *target)\n \tretval = get_sha1_hex(target, sha1);\n \tif (retval)\n \t\treturn retval;\n-\tretval = fetch(sha1);\n+\tretval = make_sure_we_have_it(sha1);\n \tif (retval)\n \t\treturn retval;\n \treturn process_commit(sha1);\n--- k/rpull.c\n+++ l/rpull.c\n@@ -14,8 +14,6 @@ static int fd_out;\n \n int fetch(unsigned char *sha1)\n {\n-\tif (has_sha1_file(sha1))\n-\t\treturn 0;\n \twrite(fd_out, sha1, 20);\n \treturn write_sha1_from_fd(sha1, fd_in);\n }\n\n"}]}