{"thread":{"id":"446","subject":"[PATCH] Make git-*-pull say who wants it for missing objects.","startedAt":"2005-05-03T00:13:52Z","lastAt":"2005-05-03T00:13:52Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"2419","messageId":"7voebtnp33.fsf@assigned-by-dhcp.cox.net","threadId":"446","inReplyTo":null,"subject":"[PATCH] Make git-*-pull say who wants it for missing objects.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-03T00:13:52Z","receivedAt":"2005-05-03T00:13:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This patch updates pull.c, the engine that decides what object is needed\ngiven a commit to traverse from, to report which commit was calling for\nthe object that cannot be retrieved from the remote side.  This complements\ngit-fsck-cache in that it checks the consistency of the remote repository\nfor reachability.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\npull.c |   37 ++++++++++++++++++++++++++++++-------\n1 files changed, 30 insertions(+), 7 deletions(-)\n\n--- a/pull.c\n+++ b/pull.c\n@@ -7,12 +7,31 @@\n int get_tree = 0;\n int get_history = 0;\n int get_all = 0;\n+static unsigned char current_commit_sha1[20];\n \n-static int make_sure_we_have_it(unsigned char *sha1)\n+static const char commitS[] = \"commit\";\n+static const char treeS[] = \"tree\";\n+static const char blobS[] = \"blob\";\n+\n+static void report_missing(const char *what, const unsigned char *missing)\n+{\n+\tchar missing_hex[41];\n+\n+\tstrcpy(missing_hex, sha1_to_hex(missing));;\n+\tfprintf(stderr,\n+\t\t\"Cannot obtain needed %s %s\\nwhile processing commit %s.\\n\",\n+\t\twhat, missing_hex, sha1_to_hex(current_commit_sha1));\n+}\n+\n+static int make_sure_we_have_it(const char *what, unsigned char *sha1)\n {\n+\tint status;\n \tif (has_sha1_file(sha1))\n \t\treturn 0;\n-\treturn fetch(sha1);\t\n+\tstatus = fetch(sha1);\n+\tif (status && what)\n+\t\treport_missing(what, sha1);\n+\treturn status;\n }\n \n static int process_tree(unsigned char *sha1)\n@@ -24,7 +43,8 @@ static int process_tree(unsigned char *s\n \t\treturn -1;\n \n \tfor (entries = tree->entries; entries; entries = entries->next) {\n-\t\tif (make_sure_we_have_it(entries->item.tree->object.sha1))\n+\t\tconst char *what = entries->directory ? treeS : blobS;\n+\t\tif (make_sure_we_have_it(what, 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@@ -38,14 +58,14 @@ static int process_commit(unsigned char \n {\n \tstruct commit *obj = lookup_commit(sha1);\n \n-\tif (make_sure_we_have_it(sha1))\n+\tif (make_sure_we_have_it(commitS, sha1))\n \t\treturn -1;\n \n \tif (parse_commit(obj))\n \t\treturn -1;\n \n \tif (get_tree) {\n-\t\tif (make_sure_we_have_it(obj->tree->object.sha1))\n+\t\tif (make_sure_we_have_it(treeS, obj->tree->object.sha1))\n \t\t\treturn -1;\n \t\tif (process_tree(obj->tree->object.sha1))\n \t\t\treturn -1;\n@@ -57,7 +77,8 @@ 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 (make_sure_we_have_it(parents->item->object.sha1)) {\n+\t\t\tif (make_sure_we_have_it(NULL,\n+\t\t\t\t\t\t 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@@ -65,6 +86,7 @@ static int process_commit(unsigned char \n \t\t\t}\n \t\t\tif (process_commit(parents->item->object.sha1))\n \t\t\t\treturn -1;\n+\t\t\tmemcpy(current_commit_sha1, sha1, 20);\n \t\t}\n \t}\n \treturn 0;\n@@ -77,8 +99,9 @@ int pull(char *target)\n \tretval = get_sha1_hex(target, sha1);\n \tif (retval)\n \t\treturn retval;\n-\tretval = make_sure_we_have_it(sha1);\n+\tretval = make_sure_we_have_it(commitS, sha1);\n \tif (retval)\n \t\treturn retval;\n+\tmemcpy(current_commit_sha1, sha1, 20);\n \treturn process_commit(sha1);\n }\n\n"}]}