{"thread":{"id":"3202","subject":"[PATCH 1/2] Make the \"struct tree_desc\" operations available to others","startedAt":"2006-01-31T22:10:56Z","lastAt":"2006-01-31T22:13:40Z","messageCount":2,"participants":["Linus Torvalds"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"15338","messageId":"Pine.LNX.4.64.0601311407460.7301@g5.osdl.org","threadId":"3202","inReplyTo":null,"subject":"[PATCH 1/2] Make the \"struct tree_desc\" operations available to others","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-01-31T22:10:56Z","receivedAt":"2006-01-31T22:10:56Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nWe have operations to \"extract\" and \"update\" a \"struct tree_desc\", but we \nonly used them in tree-diff.c and they were static to that file.\n\nBut other tree traversal functions can use them to their advantage\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\n\nThis is just infrastructure. No real changes, except for the renaming of \nthe \"extract()\" function to make it have a more palatable name when it's\nglobally visible.\n\ndiff --git a/diff.h b/diff.h\nindex 9a0169c..32134d7 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -13,6 +13,9 @@ struct tree_desc {\n \tunsigned long size;\n };\n \n+extern void update_tree_entry(struct tree_desc *);\n+extern const unsigned char *tree_entry_extract(struct tree_desc *, const char **, unsigned int *);\n+\n struct diff_options;\n \n typedef void (*change_fn_t)(struct diff_options *options,\ndiff --git a/tree-diff.c b/tree-diff.c\nindex 382092b..d978428 100644\n--- a/tree-diff.c\n+++ b/tree-diff.c\n@@ -9,7 +9,7 @@ static int nr_paths = 0;\n static const char **paths = NULL;\n static int *pathlens = NULL;\n \n-static void update_tree_entry(struct tree_desc *desc)\n+void update_tree_entry(struct tree_desc *desc)\n {\n \tvoid *buf = desc->buf;\n \tunsigned long size = desc->size;\n@@ -21,7 +21,7 @@ static void update_tree_entry(struct tre\n \tdesc->size = size - len;\n }\n \n-static const unsigned char *extract(struct tree_desc *desc, const char **pathp, unsigned int *modep)\n+const unsigned char *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned int *modep)\n {\n \tvoid *tree = desc->buf;\n \tunsigned long size = desc->size;\n@@ -56,8 +56,8 @@ static int compare_tree_entry(struct tre\n \tconst unsigned char *sha1, *sha2;\n \tint cmp, pathlen1, pathlen2;\n \n-\tsha1 = extract(t1, &path1, &mode1);\n-\tsha2 = extract(t2, &path2, &mode2);\n+\tsha1 = tree_entry_extract(t1, &path1, &mode1);\n+\tsha2 = tree_entry_extract(t2, &path2, &mode2);\n \n \tpathlen1 = strlen(path1);\n \tpathlen2 = strlen(path2);\n@@ -109,7 +109,7 @@ static int interesting(struct tree_desc \n \tif (!nr_paths)\n \t\treturn 1;\n \n-\t(void)extract(desc, &path, &mode);\n+\t(void)tree_entry_extract(desc, &path, &mode);\n \n \tpathlen = strlen(path);\n \tbaselen = strlen(base);\n@@ -167,7 +167,7 @@ static int show_entry(struct diff_option\n {\n \tunsigned mode;\n \tconst char *path;\n-\tconst unsigned char *sha1 = extract(desc, &path, &mode);\n+\tconst unsigned char *sha1 = tree_entry_extract(desc, &path, &mode);\n \n \tif (opt->recursive && S_ISDIR(mode)) {\n \t\tchar type[20];\n"},{"id":"15339","messageId":"Pine.LNX.4.64.0601311411080.7301@g5.osdl.org","threadId":"3202","inReplyTo":"Pine.LNX.4.64.0601311407460.7301@g5.osdl.org","subject":"[PATCH 2/2] Make git-tar-tree use the tree_desc abstractions","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-01-31T22:13:40Z","receivedAt":"2006-01-31T22:13:40Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\n\nThis is a first try at making git-tar-tree use the \"struct tree_desc\" \ninfrastructure. I actually did test it by creating a tar-file of Linux \nv2.6.15, and it _seemed_ to work, and it passes all the git testsuite, but \nhey, that was all very superficial.\n\nIt was a pretty straightforward change from \"struct tree\" to \"struct \ntree_desc\", though, so it should all be fine. Daniel had already cleaned \nup the code by his original conversion.\n\ndiff --git a/tar-tree.c b/tar-tree.c\nindex d36baed..e85a1ed 100644\n--- a/tar-tree.c\n+++ b/tar-tree.c\n@@ -3,7 +3,7 @@\n  */\n #include <time.h>\n #include \"cache.h\"\n-#include \"tree.h\"\n+#include \"diff.h\"\n #include \"commit.h\"\n \n #define RECORDSIZE\t(512)\n@@ -336,37 +336,38 @@ static void write_header(const unsigned \n \twrite_if_needed();\n }\n \n-static void traverse_tree(struct tree *tree,\n+static void traverse_tree(struct tree_desc *tree,\n \t\t\t  struct path_prefix *prefix)\n {\n \tstruct path_prefix this_prefix;\n-\tstruct tree_entry_list *item;\n \tthis_prefix.prev = prefix;\n \n-\tparse_tree(tree);\n-\titem = tree->entries;\n-\n-\twhile (item) {\n+\twhile (tree->size) {\n+\t\tconst char *name;\n+\t\tconst unsigned char *sha1;\n+\t\tunsigned mode;\n \t\tvoid *eltbuf;\n \t\tchar elttype[20];\n \t\tunsigned long eltsize;\n \n-\t\teltbuf = read_sha1_file(item->item.any->sha1, \n-\t\t\t\t\telttype, &eltsize);\n+\t\tsha1 = tree_entry_extract(tree, &name, &mode);\n+\t\tupdate_tree_entry(tree);\n+\n+\t\teltbuf = read_sha1_file(sha1, elttype, &eltsize);\n \t\tif (!eltbuf)\n-\t\t\tdie(\"cannot read %s\", \n-\t\t\t    sha1_to_hex(item->item.any->sha1));\n-\t\twrite_header(item->item.any->sha1, TYPEFLAG_AUTO, basedir, \n-\t\t\t     prefix, item->name,\n-\t\t             item->mode, eltbuf, eltsize);\n-\t\tif (item->directory) {\n-\t\t\tthis_prefix.name = item->name;\n-\t\t\ttraverse_tree(item->item.tree, &this_prefix);\n-\t\t} else if (!item->symlink) {\n+\t\t\tdie(\"cannot read %s\", sha1_to_hex(sha1));\n+\t\twrite_header(sha1, TYPEFLAG_AUTO, basedir, \n+\t\t\t     prefix, name, mode, eltbuf, eltsize);\n+\t\tif (S_ISDIR(mode)) {\n+\t\t\tstruct tree_desc subtree;\n+\t\t\tsubtree.buf = eltbuf;\n+\t\t\tsubtree.size = eltsize;\n+\t\t\tthis_prefix.name = name;\n+\t\t\ttraverse_tree(&subtree, &this_prefix);\n+\t\t} else if (!S_ISLNK(mode)) {\n \t\t\twrite_blocked(eltbuf, eltsize);\n \t\t}\n \t\tfree(eltbuf);\n-\t\titem = item->next;\n \t}\n }\n \n@@ -374,7 +375,7 @@ int main(int argc, char **argv)\n {\n \tunsigned char sha1[20];\n \tstruct commit *commit;\n-\tstruct tree *tree;\n+\tstruct tree_desc tree;\n \n \tsetup_git_directory();\n \n@@ -395,8 +396,8 @@ int main(int argc, char **argv)\n \t\twrite_global_extended_header(commit->object.sha1);\n \t\tarchive_time = commit->date;\n \t}\n-\ttree = parse_tree_indirect(sha1);\n-\tif (!tree)\n+\ttree.buf = read_object_with_reference(sha1, \"tree\", &tree.size, NULL);\n+\tif (!tree.buf)\n \t\tdie(\"not a reference to a tag, commit or tree object: %s\",\n \t\t    sha1_to_hex(sha1));\n \tif (!archive_time)\n@@ -404,7 +405,7 @@ int main(int argc, char **argv)\n \tif (basedir)\n \t\twrite_header((unsigned char *)\"0\", TYPEFLAG_DIR, NULL, NULL,\n \t\t\tbasedir, 040777, NULL, 0);\n-\ttraverse_tree(tree, NULL);\n+\ttraverse_tree(&tree, NULL);\n \twrite_trailer();\n \treturn 0;\n }\n"}]}