{"thread":{"id":"25017","subject":"[RFC PATCH] tree.c: Nuke match_tree_entry(), it just duplicates tree_entry_interesting()","startedAt":"2010-09-07T01:53:39Z","lastAt":"2010-09-07T01:53:39Z","messageCount":1,"participants":["Elijah Newren"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"150171","messageId":"1283824419-21730-1-git-send-email-newren@gmail.com","threadId":"25017","inReplyTo":null,"subject":"[RFC PATCH] tree.c: Nuke match_tree_entry(), it just duplicates tree_entry_interesting()","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2010-09-07T01:53:39Z","receivedAt":"2010-09-07T01:53:39Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"WARNING: RFC because: This has a minor conflict with my sparse-clone\nseries, and a less minor conflict with Nguyễn Thái Ngọc Duy's updates to\nthe en/object-list-with-pathspec series.  Duy's changes to\nen/object-list-with-pathspec, at least with my additional suggestions,\nshould probably also be applied to en/tree-walk-optim for\nskip_uninteresting.  If all that other stuff is done, this particular patch\ncould be made smaller and we could nuke the FIXME.  That'd make it into a\nsimple code cleanup.  I'm sending right now for comments, before I forget\nabout this simple cleanup.\n\nI'll clean up and resend once Duy is done with his changes.\n\n---\n tree-diff.c |    2 +-\n tree-walk.h |    3 ++\n tree.c      |   77 ++++++++++++++++++----------------------------------------\n 3 files changed, 28 insertions(+), 54 deletions(-)\n\ndiff --git a/tree-diff.c b/tree-diff.c\nindex cd659c6..2fb670b 100644\n--- a/tree-diff.c\n+++ b/tree-diff.c\n@@ -91,7 +91,7 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, const\n  *  - zero for no\n  *  - negative for \"no, and no subsequent entries will be either\"\n  */\n-static int tree_entry_interesting(struct tree_desc *desc, const char *base, int baselen, struct diff_options *opt)\n+int tree_entry_interesting(struct tree_desc *desc, const char *base, int baselen, struct diff_options *opt)\n {\n \tconst char *path;\n \tconst unsigned char *sha1;\ndiff --git a/tree-walk.h b/tree-walk.h\nindex 7e3e0b5..e3e0137 100644\n--- a/tree-walk.h\n+++ b/tree-walk.h\n@@ -60,4 +60,7 @@ static inline int traverse_path_len(const struct traverse_info *info, const stru\n \treturn info->pathlen + tree_entry_len(n->path, n->sha1);\n }\n \n+struct diff_options;\n+extern int tree_entry_interesting(struct tree_desc *desc, const char *base, int baselen, struct diff_options *opt);\n+\n #endif\ndiff --git a/tree.c b/tree.c\nindex 5ab90af..405f56b 100644\n--- a/tree.c\n+++ b/tree.c\n@@ -5,6 +5,13 @@\n #include \"commit.h\"\n #include \"tag.h\"\n #include \"tree-walk.h\"\n+/*\n+ * FIXME: Shouldn't need diff.h, but need it now for skip_uninteresting and\n+ * diff_options; Nguyen's pending update to en/object-list-with-pathspec may\n+ * fix this need, if coupled with my suggestion and a similar fix for\n+ * skip_uninteresting...\n+ */\n+#include \"diff.h\"\n \n const char *tree_type = \"tree\";\n \n@@ -45,71 +52,35 @@ static int read_one_entry_quick(const unsigned char *sha1, const char *base, int\n \t\t\t\t  ADD_CACHE_JUST_APPEND);\n }\n \n-static int match_tree_entry(const char *base, int baselen, const char *path, unsigned int mode, const char **paths)\n-{\n-\tconst char *match;\n-\tint pathlen;\n-\n-\tif (!paths)\n-\t\treturn 1;\n-\tpathlen = strlen(path);\n-\twhile ((match = *paths++) != NULL) {\n-\t\tint matchlen = strlen(match);\n-\n-\t\tif (baselen >= matchlen) {\n-\t\t\t/* If it doesn't match, move along... */\n-\t\t\tif (strncmp(base, match, matchlen))\n-\t\t\t\tcontinue;\n-\t\t\t/* pathspecs match only at the directory boundaries */\n-\t\t\tif (!matchlen ||\n-\t\t\t    baselen == matchlen ||\n-\t\t\t    base[matchlen] == '/' ||\n-\t\t\t    match[matchlen - 1] == '/')\n-\t\t\t\treturn 1;\n-\t\t\tcontinue;\n-\t\t}\n-\n-\t\t/* Does the base match? */\n-\t\tif (strncmp(base, match, baselen))\n-\t\t\tcontinue;\n-\n-\t\tmatch += baselen;\n-\t\tmatchlen -= baselen;\n-\n-\t\tif (pathlen > matchlen)\n-\t\t\tcontinue;\n-\n-\t\tif (matchlen > pathlen) {\n-\t\t\tif (match[pathlen] != '/')\n-\t\t\t\tcontinue;\n-\t\t\tif (!S_ISDIR(mode))\n-\t\t\t\tcontinue;\n-\t\t}\n-\n-\t\tif (strncmp(path, match, pathlen))\n-\t\t\tcontinue;\n-\n-\t\treturn 1;\n-\t}\n-\treturn 0;\n-}\n-\n int read_tree_recursive(struct tree *tree,\n \t\t\tconst char *base, int baselen,\n \t\t\tint stage, const char **match,\n \t\t\tread_tree_fn_t fn, void *context)\n {\n \tstruct tree_desc desc;\n-\tstruct name_entry entry;\n+\tstruct diff_options diff_opts;\n+\tint all_interesting;\n \n \tif (parse_tree(tree))\n \t\treturn -1;\n \n+\tdiff_tree_setup_paths(match, &diff_opts);\n+\tall_interesting = diff_opts.nr_paths == 0;\n+\n \tinit_tree_desc(&desc, tree->buffer, tree->size);\n \n-\twhile (tree_entry(&desc, &entry)) {\n-\t\tif (!match_tree_entry(base, baselen, entry.path, entry.mode, match))\n-\t\t\tcontinue;\n+\tfor (; desc.size; update_tree_entry(&desc)) {\n+\t\tstruct name_entry entry;\n+\t\tif (!all_interesting) {\n+\t\t\tint show = tree_entry_interesting(&desc, base, baselen, &diff_opts);\n+\t\t\tif (show < 0)\n+\t\t\t\treturn 0;\n+\t\t\telse if (!show)\n+\t\t\t\tcontinue;\n+\t\t\telse if (show == 2)\n+\t\t\t\tall_interesting = 1;\n+\t\t}\n+\t\tentry = desc.entry;\n \n \t\tswitch (fn(entry.sha1, base, baselen, entry.path, entry.mode, stage, context)) {\n \t\tcase 0:\n-- \n1.7.3.rc0.1.g43ab\n"}]}