{"thread":{"id":"185","subject":"(rework) [PATCH 5/5] Accept commit in some places when tree is needed.","startedAt":"2005-04-21T00:24:24Z","lastAt":"2005-04-21T00:24:24Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"1070","messageId":"7vr7h5geo7.fsf@assigned-by-dhcp.cox.net","threadId":"185","inReplyTo":null,"subject":"(rework) [PATCH 5/5] Accept commit in some places when tree is needed.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-04-21T00:24:24Z","receivedAt":"2005-04-21T00:24:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Updates read-tree to use read_tree_with_tree_or_commit_sha1()\nfunction.  The command can take either tree or commit IDs with\nthis patch.\n\nThe change involves a slight modification of how it recurses down\nthe tree.  Earlier the caller only supplied SHA1 and the recurser\nread the object using it, but now it is the caller's responsibility\nto read the object and give it to the recurser.  This matches the\nway recursive behaviour is done in other tree- related commands.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n read-tree.c |   34 ++++++++++++++++++++++++----------\n 1 files changed, 24 insertions(+), 10 deletions(-)\n\nread-tree.c: 46747b5e99b102ed547e87f55a8ee734c9ddb074\n--- a/read-tree.c\n+++ b/read-tree.c\n@@ -23,16 +23,11 @@ static int read_one_entry(unsigned char \n \treturn add_cache_entry(ce, 1);\n }\n \n-static int read_tree(unsigned char *sha1, const char *base, int baselen)\n+static int read_tree_recursive(void *buffer, const char *type,\n+\t\t\t       unsigned long size,\n+\t\t\t       const char *base, int baselen)\n {\n-\tvoid *buffer;\n-\tunsigned long size;\n-\tchar type[20];\n-\n-\tbuffer = read_sha1_file(sha1, type, &size);\n-\tif (!buffer)\n-\t\treturn -1;\n-\tif (strcmp(type, \"tree\"))\n+\tif (!buffer || strcmp(type, \"tree\"))\n \t\treturn -1;\n \twhile (size) {\n \t\tint len = strlen(buffer)+1;\n@@ -50,10 +45,20 @@ static int read_tree(unsigned char *sha1\n \t\t\tint retval;\n \t\t\tint pathlen = strlen(path);\n \t\t\tchar *newbase = malloc(baselen + 1 + pathlen);\n+\t\t\tvoid *eltbuf;\n+\t\t\tchar elttype[20];\n+\t\t\tunsigned long eltsize;\n+\n+\t\t\teltbuf = read_sha1_file(sha1, elttype, &eltsize);\n+\t\t\tif (!eltbuf)\n+\t\t\t\treturn -1;\n \t\t\tmemcpy(newbase, base, baselen);\n \t\t\tmemcpy(newbase + baselen, path, pathlen);\n \t\t\tnewbase[baselen + pathlen] = '/';\n-\t\t\tretval = read_tree(sha1, newbase, baselen + pathlen + 1);\n+\t\t\tretval = read_tree_recursive(eltbuf, elttype, eltsize,\n+\t\t\t\t\t\t     newbase,\n+\t\t\t\t\t\t     baselen + pathlen + 1);\n+\t\t\tfree(eltbuf);\n \t\t\tfree(newbase);\n \t\t\tif (retval)\n \t\t\t\treturn -1;\n@@ -65,6 +70,15 @@ static int read_tree(unsigned char *sha1\n \treturn 0;\n }\n \n+static int read_tree(unsigned char *sha1, const char *base, int baselen)\n+{\n+\tvoid *buffer;\n+\tunsigned long size;\n+\n+\tbuffer = read_tree_with_tree_or_commit_sha1(sha1, &size, 0);\n+\treturn read_tree_recursive(buffer, \"tree\", size, base, baselen);\n+}\n+\n static int remove_lock = 0;\n \n static void remove_lock_file(void)\n\n"}]}