{"thread":{"id":"27045","subject":"[PATCH 0/5] New get_pathspec()","startedAt":"2011-04-09T16:54:15Z","lastAt":"2011-04-10T07:26:31Z","messageCount":11,"participants":["Nguyễn Thái Ngọc Duy","Junio C Hamano","Nguyen Thai Ngoc Duy"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"165489","messageId":"1302368060-23827-1-git-send-email-pclouds@gmail.com","threadId":"27045","inReplyTo":null,"subject":"[PATCH 0/5] New get_pathspec()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-04-09T16:54:15Z","receivedAt":"2011-04-09T16:54:15Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This is on top of jc/magic-pathspec. It implements new get_pathspec().\nRemaining work includes\n\n - implement verify_pathspec() (see notes on 5/5)\n\n - make use of pathspec_item.plain_len introduced in 3/5\n\n - convert the rest to use new get_pathspec(). Can we make it a GSoC\n   project?\n\n - get rid of old pathspec code.\n\n - implement a whole lot more of pathspec magic.\n\nI think that's it. We also need to think if we can use similar syntax\nfor gitattr/gitignore, reuse as much code as possible.\n\n\n[PATCH 1/5] Rename functions in preparation for get_pathspec() restructure\n\n  I figure I cannot bring all commands to the new get_pathspec() at\n  once and remove the old one. So instead I rename the old one so that\n  we can have both implementations running in parallel.\n\n\n[PATCH 2/5] Replace has_wildcard with PATHSPEC_NOGLOB\n\n  This effectively kills Junio's use_wildcard rename patch.\n\n\n[PATCH 3/5] Convert prefix_pathspec() to produce struct pathspec_item\n\n  Also put plain_len field in place for literal matching on prefix.\n  Nobody uses it yet though.\n\n\n[PATCH 4/5] Implement new get_pathspec()\n\n  I don't move prefix_pathspec() to dir.c yet. It may need some\n  updates until things are stablized. It will be moved at latest when\n  get_pathspec_old() is retired.\n\n\n[PATCH 5/5] grep: convert to use the new get_pathspec()\n\n  The first user of the new get_pathspec(), just to make sure I don't\n  introduce too many bugs.\n  The verify_filename() issue remains. I suggest we keep an\n  incarnation of it to catch simple pathspecs, then implement\n  verify_pathspec() for wildcard pathspecs.\n\n archive.c              |    2 +-\n builtin/add.c          |    6 ++--\n builtin/checkout.c     |    8 ++--\n builtin/clean.c        |    4 +-\n builtin/commit.c       |    6 ++--\n builtin/grep.c         |   14 ++------\n builtin/ls-files.c     |    8 ++--\n builtin/ls-tree.c      |    2 +-\n builtin/mv.c           |    2 +-\n builtin/rerere.c       |    2 +-\n builtin/reset.c        |    4 +-\n builtin/rm.c           |    4 +-\n builtin/update-index.c |    2 +-\n cache.h                |   26 +++++++++++++--\n dir.c                  |   81 +++++++++++++++++++++++++++++++++++------------\n dir.h                  |    4 +-\n read-cache.c           |    4 +-\n rerere.c               |    2 +-\n resolve-undo.c         |    2 +-\n revision.c             |    2 +-\n setup.c                |   45 +++++++++++---------------\n tree-walk.c            |   25 +++++++--------\n wt-status.c            |    4 +-\n 23 files changed, 151 insertions(+), 108 deletions(-)\n\n-- \n1.7.4.74.g639db\n"},{"id":"165490","messageId":"1302368060-23827-2-git-send-email-pclouds@gmail.com","threadId":"27045","inReplyTo":"1302368060-23827-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 1/5] Rename functions in preparation for get_pathspec() restructure","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-04-09T16:54:16Z","receivedAt":"2011-04-09T16:54:16Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This renames:\n\n - get_pathspec()         to get_pathspec_old()\n - match_pathspec()       to match_pathspec_old()\n - match_pathspec_depth() to match_pathspec()\n\nThe name get_pathspec() will be used for a new function which produces\nstruct pathspec directly.\n\nBoth get_pathspec implementations will co-exist for a while until\neverything is converted to get_pathspec(). By that point, both\nmatch_pathspec_old() and get_pathspec_old() would be removed.\n\nBecause two get_pathspec impl must provide the same functionality, the\nnew get_pathspec() can't (or shouldn't) implement any magic other than\n'top' and 'icase' already supported by get_pathspec_old().\n---\n archive.c              |    2 +-\n builtin/add.c          |    6 +++---\n builtin/checkout.c     |    8 ++++----\n builtin/clean.c        |    4 ++--\n builtin/commit.c       |    6 +++---\n builtin/grep.c         |    6 +++---\n builtin/ls-files.c     |    8 ++++----\n builtin/ls-tree.c      |    2 +-\n builtin/mv.c           |    2 +-\n builtin/rerere.c       |    2 +-\n builtin/reset.c        |    4 ++--\n builtin/rm.c           |    4 ++--\n builtin/update-index.c |    2 +-\n cache.h                |    2 +-\n dir.c                  |    4 ++--\n dir.h                  |    4 ++--\n read-cache.c           |    4 ++--\n rerere.c               |    2 +-\n resolve-undo.c         |    2 +-\n revision.c             |    2 +-\n setup.c                |    2 +-\n wt-status.c            |    4 ++--\n 22 files changed, 41 insertions(+), 41 deletions(-)\n\ndiff --git a/archive.c b/archive.c\nindex 1944ed4..884bb2f 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -231,7 +231,7 @@ static int path_exists(struct tree *tree, const char *path)\n static void parse_pathspec_arg(const char **pathspec,\n \t\tstruct archiver_args *ar_args)\n {\n-\tar_args->pathspec = pathspec = get_pathspec(\"\", pathspec);\n+\tar_args->pathspec = pathspec = get_pathspec_old(\"\", pathspec);\n \tif (pathspec) {\n \t\twhile (*pathspec) {\n \t\t\tif (!path_exists(ar_args->tree, *pathspec))\ndiff --git a/builtin/add.c b/builtin/add.c\nindex e127d5a..552801a 100644\n--- a/builtin/add.c\n+++ b/builtin/add.c\n@@ -112,7 +112,7 @@ static void fill_pathspec_matches(const char **pathspec, char *seen, int specs)\n \t\treturn;\n \tfor (i = 0; i < active_nr; i++) {\n \t\tstruct cache_entry *ce = active_cache[i];\n-\t\tmatch_pathspec(pathspec, ce->name, ce_namelen(ce), 0, seen);\n+\t\tmatch_pathspec_old(pathspec, ce->name, ce_namelen(ce), 0, seen);\n \t}\n }\n \n@@ -142,7 +142,7 @@ static char *prune_directory(struct dir_struct *dir, const char **pathspec, int\n \ti = dir->nr;\n \twhile (--i >= 0) {\n \t\tstruct dir_entry *entry = *src++;\n-\t\tif (match_pathspec(pathspec, entry->name, entry->len,\n+\t\tif (match_pathspec_old(pathspec, entry->name, entry->len,\n \t\t\t\t   prefix, seen))\n \t\t\t*dst++ = entry;\n \t}\n@@ -197,7 +197,7 @@ static void refresh(int verbose, const char **pathspec)\n \n static const char **validate_pathspec(int argc, const char **argv, const char *prefix)\n {\n-\tconst char **pathspec = get_pathspec(prefix, argv);\n+\tconst char **pathspec = get_pathspec_old(prefix, argv);\n \n \tif (pathspec) {\n \t\tconst char **p;\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 2bf02f2..3bcff35 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -223,7 +223,7 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec,\n \n \tfor (pos = 0; pos < active_nr; pos++) {\n \t\tstruct cache_entry *ce = active_cache[pos];\n-\t\tmatch_pathspec(pathspec, ce->name, ce_namelen(ce), 0, ps_matched);\n+\t\tmatch_pathspec_old(pathspec, ce->name, ce_namelen(ce), 0, ps_matched);\n \t}\n \n \tif (report_path_error(ps_matched, pathspec, 0))\n@@ -236,7 +236,7 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec,\n \t/* Any unmerged paths? */\n \tfor (pos = 0; pos < active_nr; pos++) {\n \t\tstruct cache_entry *ce = active_cache[pos];\n-\t\tif (match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, NULL)) {\n+\t\tif (match_pathspec_old(pathspec, ce->name, ce_namelen(ce), 0, NULL)) {\n \t\t\tif (!ce_stage(ce))\n \t\t\t\tcontinue;\n \t\t\tif (opts->force) {\n@@ -261,7 +261,7 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec,\n \tstate.refresh_cache = 1;\n \tfor (pos = 0; pos < active_nr; pos++) {\n \t\tstruct cache_entry *ce = active_cache[pos];\n-\t\tif (match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, NULL)) {\n+\t\tif (match_pathspec_old(pathspec, ce->name, ce_namelen(ce), 0, NULL)) {\n \t\t\tif (!ce_stage(ce)) {\n \t\t\t\terrs |= checkout_entry(ce, &state, NULL);\n \t\t\t\tcontinue;\n@@ -1005,7 +1005,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)\n \t\topts.track = git_branch_track;\n \n \tif (argc) {\n-\t\tconst char **pathspec = get_pathspec(prefix, argv);\n+\t\tconst char **pathspec = get_pathspec_old(prefix, argv);\n \n \t\tif (!pathspec)\n \t\t\tdie(\"invalid path specification\");\ndiff --git a/builtin/clean.c b/builtin/clean.c\nindex 4a312ab..92889c6 100644\n--- a/builtin/clean.c\n+++ b/builtin/clean.c\n@@ -95,7 +95,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)\n \tfor (i = 0; i < exclude_list.nr; i++)\n \t\tadd_exclude(exclude_list.items[i].string, \"\", 0, dir.exclude_list);\n \n-\tpathspec = get_pathspec(prefix, argv);\n+\tpathspec = get_pathspec_old(prefix, argv);\n \n \tfill_directory(&dir, pathspec);\n \n@@ -137,7 +137,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)\n \n \t\tif (pathspec) {\n \t\t\tmemset(seen, 0, argc > 0 ? argc : 1);\n-\t\t\tmatches = match_pathspec(pathspec, ent->name, len,\n+\t\t\tmatches = match_pathspec_old(pathspec, ent->name, len,\n \t\t\t\t\t\t 0, seen);\n \t\t}\n \ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 3979b82..efdc7ae 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -264,7 +264,7 @@ static int list_paths(struct string_list *list, const char *with_tree,\n \n \t\tif (ce->ce_flags & CE_UPDATE)\n \t\t\tcontinue;\n-\t\tif (!match_pathspec(pattern, ce->name, ce_namelen(ce), 0, m))\n+\t\tif (!match_pathspec_old(pattern, ce->name, ce_namelen(ce), 0, m))\n \t\t\tcontinue;\n \t\titem = string_list_insert(list, ce->name);\n \t\tif (ce_skip_worktree(ce))\n@@ -350,7 +350,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int\n \t}\n \n \tif (*argv)\n-\t\tpathspec = get_pathspec(prefix, argv);\n+\t\tpathspec = get_pathspec_old(prefix, argv);\n \n \tif (read_cache_preload(pathspec) < 0)\n \t\tdie(\"index file corrupt\");\n@@ -1197,7 +1197,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)\n \tif (show_ignored_in_status)\n \t\ts.show_ignored_files = 1;\n \tif (*argv)\n-\t\ts.pathspec = get_pathspec(prefix, argv);\n+\t\ts.pathspec = get_pathspec_old(prefix, argv);\n \n \tread_cache_preload(s.pathspec);\n \trefresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, s.pathspec, NULL, NULL);\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 0bf8c01..2826ca8 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -490,7 +490,7 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int\n \t\tstruct cache_entry *ce = active_cache[nr];\n \t\tif (!S_ISREG(ce->ce_mode))\n \t\t\tcontinue;\n-\t\tif (!match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, NULL))\n+\t\tif (!match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, NULL))\n \t\t\tcontinue;\n \t\t/*\n \t\t * If CE_VALID is on, we assume worktree file and its cache entry\n@@ -627,7 +627,7 @@ static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec)\n \tfor (i = 0; i < dir.nr; i++) {\n \t\tconst char *name = dir.entries[i]->name;\n \t\tint namelen = strlen(name);\n-\t\tif (!match_pathspec_depth(pathspec, name, namelen, 0, NULL))\n+\t\tif (!match_pathspec(pathspec, name, namelen, 0, NULL))\n \t\t\tcontinue;\n \t\thit |= grep_file(opt, dir.entries[i]->name);\n \t\tif (hit && opt->status_only)\n@@ -957,7 +957,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t}\n \n \tif (i < argc)\n-\t\tpaths = get_pathspec(prefix, argv + i);\n+\t\tpaths = get_pathspec_old(prefix, argv + i);\n \telse if (prefix) {\n \t\tpaths = xcalloc(2, sizeof(const char *));\n \t\tpaths[0] = prefix;\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex fb2d5f4..8e39503 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -58,7 +58,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)\n \tif (len >= ent->len)\n \t\tdie(\"git ls-files: internal error - directory entry not superset of prefix\");\n \n-\tif (!match_pathspec(pathspec, ent->name, ent->len, len, ps_matched))\n+\tif (!match_pathspec_old(pathspec, ent->name, ent->len, len, ps_matched))\n \t\treturn;\n \n \tfputs(tag, stdout);\n@@ -133,7 +133,7 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)\n \tif (len >= ce_namelen(ce))\n \t\tdie(\"git ls-files: internal error - cache entry not superset of prefix\");\n \n-\tif (!match_pathspec(pathspec, ce->name, ce_namelen(ce), len, ps_matched))\n+\tif (!match_pathspec_old(pathspec, ce->name, ce_namelen(ce), len, ps_matched))\n \t\treturn;\n \n \tif (tag && *tag && show_valid_bit &&\n@@ -187,7 +187,7 @@ static void show_ru_info(void)\n \t\tlen = strlen(path);\n \t\tif (len < max_prefix_len)\n \t\t\tcontinue; /* outside of the prefix */\n-\t\tif (!match_pathspec(pathspec, path, len, max_prefix_len, ps_matched))\n+\t\tif (!match_pathspec_old(pathspec, path, len, max_prefix_len, ps_matched))\n \t\t\tcontinue; /* uninterested */\n \t\tfor (i = 0; i < 3; i++) {\n \t\t\tif (!ui->mode[i])\n@@ -568,7 +568,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)\n \tif (require_work_tree && !is_inside_work_tree())\n \t\tsetup_work_tree();\n \n-\tpathspec = get_pathspec(prefix, argv);\n+\tpathspec = get_pathspec_old(prefix, argv);\n \n \t/* be nice with submodule paths ending in a slash */\n \tif (pathspec)\ndiff --git a/builtin/ls-tree.c b/builtin/ls-tree.c\nindex f73e6bd..f55dba9 100644\n--- a/builtin/ls-tree.c\n+++ b/builtin/ls-tree.c\n@@ -166,7 +166,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)\n \tif (get_sha1(argv[0], sha1))\n \t\tdie(\"Not a valid object name %s\", argv[0]);\n \n-\tpathspec = get_pathspec(prefix, argv + 1);\n+\tpathspec = get_pathspec_old(prefix, argv + 1);\n \ttree = parse_tree_indirect(sha1);\n \tif (!tree)\n \t\tdie(\"not a tree object\");\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex 93e8995..37a285e 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -32,7 +32,7 @@ static const char **copy_pathspec(const char *prefix, const char **pathspec,\n \t\t\tresult[i] = base_name ? strdup(basename(it)) : it;\n \t\t}\n \t}\n-\treturn get_pathspec(prefix, result);\n+\treturn get_pathspec_old(prefix, result);\n }\n \n static const char *add_slash(const char *path)\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 8235885..d31cc95 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -139,7 +139,7 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)\n \t\tconst char **pathspec;\n \t\tif (argc < 2)\n \t\t\twarning(\"'git rerere forget' without paths is deprecated\");\n-\t\tpathspec = get_pathspec(prefix, argv + 1);\n+\t\tpathspec = get_pathspec_old(prefix, argv + 1);\n \t\treturn rerere_forget(pathspec);\n \t}\n \ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex 5de2bce..7d8a29a 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -182,7 +182,7 @@ static int interactive_reset(const char *revision, const char **argv,\n \tconst char **pathspec = NULL;\n \n \tif (*argv)\n-\t\tpathspec = get_pathspec(prefix, argv);\n+\t\tpathspec = get_pathspec_old(prefix, argv);\n \n \treturn run_add_interactive(revision, \"--patch=reset\", pathspec);\n }\n@@ -195,7 +195,7 @@ static int read_from_tree(const char *prefix, const char **argv,\n \tstruct diff_options opt;\n \n \tmemset(&opt, 0, sizeof(opt));\n-\tdiff_tree_setup_paths(get_pathspec(prefix, (const char **)argv), &opt);\n+\tdiff_tree_setup_paths(get_pathspec_old(prefix, (const char **)argv), &opt);\n \topt.output_format = DIFF_FORMAT_CALLBACK;\n \topt.format_callback = update_index_from_diff;\n \topt.format_callback_data = &index_was_discarded;\ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex ff491d7..65a0e07 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -161,7 +161,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \tif (read_cache() < 0)\n \t\tdie(\"index file corrupt\");\n \n-\tpathspec = get_pathspec(prefix, argv);\n+\tpathspec = get_pathspec_old(prefix, argv);\n \trefresh_index(&the_index, REFRESH_QUIET, pathspec, NULL, NULL);\n \n \tseen = NULL;\n@@ -171,7 +171,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \n \tfor (i = 0; i < active_nr; i++) {\n \t\tstruct cache_entry *ce = active_cache[i];\n-\t\tif (!match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, seen))\n+\t\tif (!match_pathspec_old(pathspec, ce->name, ce_namelen(ce), 0, seen))\n \t\t\tcontinue;\n \t\tALLOC_GROW(list.name, list.nr + 1, list.alloc);\n \t\tlist.name[list.nr++] = ce->name;\ndiff --git a/builtin/update-index.c b/builtin/update-index.c\nindex d7850c6..4ac72cf 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -546,7 +546,7 @@ static int do_reupdate(int ac, const char **av,\n \t */\n \tint pos;\n \tint has_head = 1;\n-\tconst char **paths = get_pathspec(prefix, av + 1);\n+\tconst char **paths = get_pathspec_old(prefix, av + 1);\n \tstruct pathspec pathspec;\n \n \tinit_pathspec(&pathspec, paths);\ndiff --git a/cache.h b/cache.h\nindex be6ce72..27ac8a7 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -425,7 +425,7 @@ extern void set_git_work_tree(const char *tree);\n \n #define ALTERNATE_DB_ENVIRONMENT \"GIT_ALTERNATE_OBJECT_DIRECTORIES\"\n \n-extern const char **get_pathspec(const char *prefix, const char **pathspec);\n+extern const char **get_pathspec_old(const char *prefix, const char **pathspec);\n extern void setup_work_tree(void);\n extern const char *setup_git_directory_gently(int *);\n extern const char *setup_git_directory(void);\ndiff --git a/dir.c b/dir.c\nindex 325fb56..6eb04ea 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -172,7 +172,7 @@ static int match_one(const char *match, const char *name, int namelen)\n  * and a mark is left in seen[] array for pathspec element that\n  * actually matched anything.\n  */\n-int match_pathspec(const char **pathspec, const char *name, int namelen,\n+int match_pathspec_old(const char **pathspec, const char *name, int namelen,\n \t\tint prefix, char *seen)\n {\n \tint i, retval = 0;\n@@ -244,7 +244,7 @@ static int match_pathspec_item(const struct pathspec_item *item, int prefix,\n  * and a mark is left in seen[] array for pathspec element that\n  * actually matched anything.\n  */\n-int match_pathspec_depth(const struct pathspec *ps,\n+int match_pathspec(const struct pathspec *ps,\n \t\t\t const char *name, int namelen,\n \t\t\t int prefix, char *seen)\n {\ndiff --git a/dir.h b/dir.h\nindex aa511da..758ab6c 100644\n--- a/dir.h\n+++ b/dir.h\n@@ -64,8 +64,8 @@ struct dir_struct {\n #define MATCHED_RECURSIVELY 1\n #define MATCHED_FNMATCH 2\n #define MATCHED_EXACTLY 3\n-extern int match_pathspec(const char **pathspec, const char *name, int namelen, int prefix, char *seen);\n-extern int match_pathspec_depth(const struct pathspec *pathspec,\n+extern int match_pathspec_old(const char **pathspec, const char *name, int namelen, int prefix, char *seen);\n+extern int match_pathspec(const struct pathspec *pathspec,\n \t\t\t\tconst char *name, int namelen,\n \t\t\t\tint prefix, char *seen);\n extern int within_depth(const char *name, int namelen, int depth, int max_depth);\ndiff --git a/read-cache.c b/read-cache.c\nindex 98d526b..6644869 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -708,7 +708,7 @@ int ce_same_name(struct cache_entry *a, struct cache_entry *b)\n \n int ce_path_match(const struct cache_entry *ce, const struct pathspec *pathspec)\n {\n-\treturn match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, NULL);\n+\treturn match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, NULL);\n }\n \n /*\n@@ -1130,7 +1130,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p\n \t\t\tcontinue;\n \t\t}\n \n-\t\tif (pathspec && !match_pathspec(pathspec, ce->name, strlen(ce->name), 0, seen))\n+\t\tif (pathspec && !match_pathspec_old(pathspec, ce->name, strlen(ce->name), 0, seen))\n \t\t\tcontinue;\n \n \t\tnew = refresh_cache_ent(istate, ce, options, &cache_errno);\ndiff --git a/rerere.c b/rerere.c\nindex 22996bd..af42948 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -665,7 +665,7 @@ int rerere_forget(const char **pathspec)\n \tfind_conflict(&conflict);\n \tfor (i = 0; i < conflict.nr; i++) {\n \t\tstruct string_list_item *it = &conflict.items[i];\n-\t\tif (!match_pathspec(pathspec, it->string, strlen(it->string),\n+\t\tif (!match_pathspec_old(pathspec, it->string, strlen(it->string),\n \t\t\t\t    0, NULL))\n \t\t\tcontinue;\n \t\trerere_forget_one_path(it->string, &merge_rr);\ndiff --git a/resolve-undo.c b/resolve-undo.c\nindex 72b4612..8400db6 100644\n--- a/resolve-undo.c\n+++ b/resolve-undo.c\n@@ -165,7 +165,7 @@ void unmerge_index(struct index_state *istate, const char **pathspec)\n \n \tfor (i = 0; i < istate->cache_nr; i++) {\n \t\tstruct cache_entry *ce = istate->cache[i];\n-\t\tif (!match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, NULL))\n+\t\tif (!match_pathspec_old(pathspec, ce->name, ce_namelen(ce), 0, NULL))\n \t\t\tcontinue;\n \t\ti = unmerge_index_entry_at(istate, i);\n \t}\ndiff --git a/revision.c b/revision.c\nindex 86d2470..b1edc2f 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1617,7 +1617,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s\n \t}\n \n \tif (prune_data)\n-\t\tinit_pathspec(&revs->prune_data, get_pathspec(revs->prefix, prune_data));\n+\t\tinit_pathspec(&revs->prune_data, get_pathspec_old(revs->prefix, prune_data));\n \n \tif (revs->def == NULL)\n \t\trevs->def = opt ? opt->def : NULL;\ndiff --git a/setup.c b/setup.c\nindex 51e354c..4e5ac5e 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -251,7 +251,7 @@ const char *prefix_pathspec(const char *prefix, int prefixlen, const char *elt)\n \treturn retval;\n }\n \n-const char **get_pathspec(const char *prefix, const char **pathspec)\n+const char **get_pathspec_old(const char *prefix, const char **pathspec)\n {\n \tconst char *entry = *pathspec;\n \tconst char **src, **dst;\ndiff --git a/wt-status.c b/wt-status.c\nindex 53558d7..2785bc3 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -472,7 +472,7 @@ static void wt_status_collect_untracked(struct wt_status *s)\n \tfor (i = 0; i < dir.nr; i++) {\n \t\tstruct dir_entry *ent = dir.entries[i];\n \t\tif (cache_name_is_other(ent->name, ent->len) &&\n-\t\t    match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL))\n+\t\t    match_pathspec_old(s->pathspec, ent->name, ent->len, 0, NULL))\n \t\t\tstring_list_insert(&s->untracked, ent->name);\n \t\tfree(ent);\n \t}\n@@ -484,7 +484,7 @@ static void wt_status_collect_untracked(struct wt_status *s)\n \t\tfor (i = 0; i < dir.nr; i++) {\n \t\t\tstruct dir_entry *ent = dir.entries[i];\n \t\t\tif (cache_name_is_other(ent->name, ent->len) &&\n-\t\t\t    match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL))\n+\t\t\t    match_pathspec_old(s->pathspec, ent->name, ent->len, 0, NULL))\n \t\t\t\tstring_list_insert(&s->ignored, ent->name);\n \t\t\tfree(ent);\n \t\t}\n-- \n1.7.4.74.g639db\n"},{"id":"165491","messageId":"1302368060-23827-3-git-send-email-pclouds@gmail.com","threadId":"27045","inReplyTo":"1302368060-23827-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 2/5] Replace has_wildcard with PATHSPEC_NOGLOB","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-04-09T16:54:17Z","receivedAt":"2011-04-09T16:54:17Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"---\n cache.h     |   22 ++++++++++++++++++++--\n dir.c       |   11 +++++++----\n setup.c     |   17 -----------------\n tree-walk.c |   25 ++++++++++++-------------\n 4 files changed, 39 insertions(+), 36 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 27ac8a7..da1a46c 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -501,16 +501,34 @@ extern int index_name_is_other(const struct index_state *, const char *, int);\n extern int ie_match_stat(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);\n extern int ie_modified(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);\n \n+/*\n+ * Magic pathspec\n+ *\n+ * NEEDSWORK: These need to be moved to dir.h or even to a new\n+ * pathspec.h when we restructure get_pathspec() users to use the\n+ * \"struct pathspec\" interface.\n+ *\n+ * Possible future magic semantics include stuff like:\n+ *\n+ *\t{ PATHSPEC_NOGLOB, '!', \"noglob\" },\n+ *\t{ PATHSPEC_RECURSIVE, '*', \"recursive\" },\n+ *\t{ PATHSPEC_REGEXP, '\\0', \"regexp\" },\n+ *\n+ */\n+#define PATHSPEC_FROMTOP    (1<<0)\n+#define PATHSPEC_ICASE      (1<<1)\n+#define PATHSPEC_NOGLOB     (1<<2)\n+\n struct pathspec {\n \tconst char **raw; /* get_pathspec() result, not freed by free_pathspec() */\n \tint nr;\n-\tunsigned int has_wildcard:1;\n+\tunsigned int use_wildcard:1;\n \tunsigned int recursive:1;\n \tint max_depth;\n \tstruct pathspec_item {\n \t\tconst char *match;\n \t\tint len;\n-\t\tunsigned int has_wildcard:1;\n+\t\tunsigned magic;\n \t} *items;\n };\n \ndiff --git a/dir.c b/dir.c\nindex 6eb04ea..58cedd3 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -230,7 +230,8 @@ static int match_pathspec_item(const struct pathspec_item *item, int prefix,\n \t\t\treturn MATCHED_RECURSIVELY;\n \t}\n \n-\tif (item->has_wildcard && !fnmatch(match, name, 0))\n+\tif (!(item->magic & PATHSPEC_NOGLOB) &&\n+\t    !fnmatch(match, name, 0))\n \t\treturn MATCHED_FNMATCH;\n \n \treturn 0;\n@@ -1280,15 +1281,17 @@ int init_pathspec(struct pathspec *pathspec, const char **paths)\n \t\treturn 0;\n \n \tpathspec->items = xmalloc(sizeof(struct pathspec_item)*pathspec->nr);\n+\tmemset(pathspec->items, 0, sizeof(struct pathspec_item)*pathspec->nr);\n \tfor (i = 0; i < pathspec->nr; i++) {\n \t\tstruct pathspec_item *item = pathspec->items+i;\n \t\tconst char *path = paths[i];\n \n \t\titem->match = path;\n \t\titem->len = strlen(path);\n-\t\titem->has_wildcard = !no_wildcard(path);\n-\t\tif (item->has_wildcard)\n-\t\t\tpathspec->has_wildcard = 1;\n+\t\tif (no_wildcard(path))\n+\t\t\titem->magic |= PATHSPEC_NOGLOB;\n+\t\telse\n+\t\t\tpathspec->use_wildcard = 1;\n \t}\n \n \tqsort(pathspec->items, pathspec->nr,\ndiff --git a/setup.c b/setup.c\nindex 4e5ac5e..1e7dfb1 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -126,23 +126,6 @@ void verify_non_filename(const char *prefix, const char *arg)\n \t    \"Use '--' to separate filenames from revisions\", arg);\n }\n \n-/*\n- * Magic pathspec\n- *\n- * NEEDSWORK: These need to be moved to dir.h or even to a new\n- * pathspec.h when we restructure get_pathspec() users to use the\n- * \"struct pathspec\" interface.\n- *\n- * Possible future magic semantics include stuff like:\n- *\n- *\t{ PATHSPEC_NOGLOB, '!', \"noglob\" },\n- *\t{ PATHSPEC_RECURSIVE, '*', \"recursive\" },\n- *\t{ PATHSPEC_REGEXP, '\\0', \"regexp\" },\n- *\n- */\n-#define PATHSPEC_FROMTOP    (1<<0)\n-#define PATHSPEC_ICASE      (1<<1)\n-\n struct pathspec_magic {\n \tunsigned bit;\n \tchar mnemonic; /* this cannot be ':'! */\ndiff --git a/tree-walk.c b/tree-walk.c\nindex 322becc..026d88e 100644\n--- a/tree-walk.c\n+++ b/tree-walk.c\n@@ -559,7 +559,7 @@ int tree_entry_interesting(const struct name_entry *entry,\n {\n \tint i;\n \tint pathlen, baselen = base->len - base_offset;\n-\tint never_interesting = ps->has_wildcard ? 0 : -1;\n+\tint never_interesting = ps->use_wildcard ? 0 : -1;\n \n \tif (!ps->nr) {\n \t\tif (!ps->recursive || ps->max_depth == -1)\n@@ -598,23 +598,22 @@ int tree_entry_interesting(const struct name_entry *entry,\n \t\t\t\t\t&never_interesting))\n \t\t\t\treturn 1;\n \n-\t\t\tif (ps->items[i].has_wildcard) {\n-\t\t\t\tif (!fnmatch(match + baselen, entry->path, 0))\n-\t\t\t\t\treturn 1;\n+\t\t\tif (ps->items[i].magic & PATHSPEC_NOGLOB)\n+\t\t\t\tcontinue;\n \n-\t\t\t\t/*\n-\t\t\t\t * Match all directories. We'll try to\n-\t\t\t\t * match files later on.\n-\t\t\t\t */\n-\t\t\t\tif (ps->recursive && S_ISDIR(entry->mode))\n-\t\t\t\t\treturn 1;\n-\t\t\t}\n+\t\t\tif (!fnmatch(match + baselen, entry->path, 0))\n+\t\t\t\treturn 1;\n \n-\t\t\tcontinue;\n+\t\t\t/*\n+\t\t\t * Match all directories. We'll try to match\n+\t\t\t * files later on.\n+\t\t\t */\n+\t\t\tif (ps->recursive && S_ISDIR(entry->mode))\n+\t\t\t\treturn 1;\n \t\t}\n \n match_wildcards:\n-\t\tif (!ps->items[i].has_wildcard)\n+\t\tif (ps->items[i].magic & PATHSPEC_NOGLOB)\n \t\t\tcontinue;\n \n \t\t/*\n-- \n1.7.4.74.g639db\n"},{"id":"165492","messageId":"1302368060-23827-4-git-send-email-pclouds@gmail.com","threadId":"27045","inReplyTo":"1302368060-23827-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 3/5] Convert prefix_pathspec() to produce struct pathspec_item","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-04-09T16:54:18Z","receivedAt":"2011-04-09T16:54:18Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"New field plain_len is used to mark the first part of 'match' where no\nmagic can be applied.\n---\n cache.h |    1 +\n setup.c |   26 ++++++++++++++++++--------\n 2 files changed, 19 insertions(+), 8 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex da1a46c..08b4633 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -528,6 +528,7 @@ struct pathspec {\n \tstruct pathspec_item {\n \t\tconst char *match;\n \t\tint len;\n+\t\tint plain_len;\t/* match[0..plain_len-1] does not have any kind of magic*/\n \t\tunsigned magic;\n \t} *items;\n };\ndiff --git a/setup.c b/setup.c\nindex 1e7dfb1..8a4a9d0 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -148,11 +148,12 @@ struct pathspec_magic {\n  * the prefix part must always match literally, and a single stupid\n  * string cannot express such a case.\n  */\n-const char *prefix_pathspec(const char *prefix, int prefixlen, const char *elt)\n+int prefix_pathspec(struct pathspec_item *item,\n+\t\t    const char *prefix, int prefixlen,\n+\t\t    const char *elt)\n {\n \tunsigned magic = 0;\n \tconst char *copyfrom = elt;\n-\tconst char *retval;\n \tint i, free_source = 0;\n \n \tif (elt[0] != ':') {\n@@ -184,7 +185,8 @@ const char *prefix_pathspec(const char *prefix, int prefixlen, const char *elt)\n \t\t\tcopyfrom++;\n \t} else if (!elt[1]) {\n \t\t/* Just ':' -- no element! */\n-\t\treturn NULL;\n+\t\tmemset(item, 0, sizeof(*item));\n+\t\treturn -1;\n \t} else {\n \t\t/* shorthand */\n \t\tfor (copyfrom = elt + 1;\n@@ -225,13 +227,19 @@ const char *prefix_pathspec(const char *prefix, int prefixlen, const char *elt)\n \t\t}\n \t}\n \n+\tmemset(item, 0, sizeof(*item));\n+\titem->magic = magic;\n+\n \tif (magic & PATHSPEC_FROMTOP)\n-\t\tretval = xstrdup(copyfrom);\n-\telse\n-\t\tretval = prefix_path(prefix, prefixlen, copyfrom);\n+\t\titem->match = xstrdup(copyfrom);\n+\telse {\n+\t\titem->match = prefix_path(prefix, prefixlen, copyfrom);\n+\t\titem->plain_len = prefixlen;\n+\t}\n+\titem->len = strlen(item->match);\n \tif (free_source)\n \t\tfree((char *)copyfrom);\n-\treturn retval;\n+\treturn 0;\n }\n \n const char **get_pathspec_old(const char *prefix, const char **pathspec)\n@@ -255,7 +263,9 @@ const char **get_pathspec_old(const char *prefix, const char **pathspec)\n \tdst = pathspec;\n \tprefixlen = prefix ? strlen(prefix) : 0;\n \twhile (*src) {\n-\t\t*(dst++) = prefix_pathspec(prefix, prefixlen, *src);\n+\t\tstruct pathspec_item item;\n+\t\tprefix_pathspec(&item, prefix, prefixlen, *src);\n+\t\t*(dst++) = item.match;\n \t\tsrc++;\n \t}\n \t*dst = NULL;\n-- \n1.7.4.74.g639db\n"},{"id":"165493","messageId":"1302368060-23827-5-git-send-email-pclouds@gmail.com","threadId":"27045","inReplyTo":"1302368060-23827-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 4/5] Implement new get_pathspec()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-04-09T16:54:19Z","receivedAt":"2011-04-09T16:54:19Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This function is as same as get_pathspec_old() except that it produces\nstruct pathspec directly.\n\nno_prefix code path is necessary because init_pathspec() can be called\nwithout get_pathspec_old() in \"diff --no-index\" case. Without this\nexception, prefix_path() will be eventually called and die because\nthere is not worktree.\n---\n cache.h |    1 +\n dir.c   |   74 ++++++++++++++++++++++++++++++++++++++++++++++----------------\n 2 files changed, 56 insertions(+), 19 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 08b4633..de57dff 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -534,6 +534,7 @@ struct pathspec {\n };\n \n extern int init_pathspec(struct pathspec *, const char **);\n+extern int get_pathspec(struct pathspec *, const char *, int, const char **);\n extern void free_pathspec(struct pathspec *);\n extern int ce_path_match(const struct cache_entry *ce, const struct pathspec *pathspec);\n extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path, int format_check);\ndiff --git a/dir.c b/dir.c\nindex 58cedd3..64348a1 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -1265,33 +1265,59 @@ static int pathspec_item_cmp(const void *a_, const void *b_)\n \treturn strcmp(a->match, b->match);\n }\n \n-int init_pathspec(struct pathspec *pathspec, const char **paths)\n+extern int prefix_pathspec(struct pathspec_item *item, const char *prefix,\n+\t\t\t   int prefixlen, const char *elt);\n+const char *no_prefix = \"We do not want outside repository check.\";\n+int get_pathspec(struct pathspec *pathspec, const char *prefix,\n+\t\t int argc, const char **argv)\n {\n-\tconst char **p = paths;\n-\tint i;\n+\tstruct pathspec_item *pitem;\n+\tconst char **dst;\n+\tint prefixlen;\n \n \tmemset(pathspec, 0, sizeof(*pathspec));\n-\tif (!p)\n+\n+\tif ((!prefix || prefix == no_prefix) && !argc)\n \t\treturn 0;\n-\twhile (*p)\n-\t\tp++;\n-\tpathspec->raw = paths;\n-\tpathspec->nr = p - paths;\n-\tif (!pathspec->nr)\n+\n+\tif (!argc) {\n+\t\tstatic const char *spec[2];\n+\t\tspec[0] = prefix;\n+\t\tspec[1] = NULL;\n+\t\tinit_pathspec(pathspec, spec);\n+\t\tpathspec->items[0].plain_len = pathspec->items[0].len;\n \t\treturn 0;\n+\t}\n \n-\tpathspec->items = xmalloc(sizeof(struct pathspec_item)*pathspec->nr);\n-\tmemset(pathspec->items, 0, sizeof(struct pathspec_item)*pathspec->nr);\n-\tfor (i = 0; i < pathspec->nr; i++) {\n-\t\tstruct pathspec_item *item = pathspec->items+i;\n-\t\tconst char *path = paths[i];\n+\tif (!strcmp(*argv, \":\"))\n+\t\treturn 0;\n \n-\t\titem->match = path;\n-\t\titem->len = strlen(path);\n-\t\tif (no_wildcard(path))\n-\t\t\titem->magic |= PATHSPEC_NOGLOB;\n+\tprefixlen = prefix && prefix != no_prefix ? strlen(prefix) : 0;\n+\tpathspec->nr = argc; /* be optimistic, lower it later if necessary */\n+\tpathspec->items = xmalloc(sizeof(struct pathspec_item) * argc);\n+\tpathspec->raw = argv;\n+\tpitem = pathspec->items;\n+\tdst = argv;\n+\n+\twhile (*argv) {\n+\t\tif (prefix == no_prefix) {\n+\t\t\tmemset(pitem, 0, sizeof(*pitem));\n+\t\t\tpitem->match = *argv;\n+\t\t\tpitem->len = strlen(pitem->match);\n+\t\t}\n+\t\telse\n+\t\t\tprefix_pathspec(pitem, prefix, prefixlen, *argv);\n+\t\t*dst = *argv++;\n+\t\tif (pitem->match) {\n+\t\t\tif (no_wildcard(pitem->match + pitem->plain_len))\n+\t\t\t\tpitem->magic |= PATHSPEC_NOGLOB;\n+\t\t\telse\n+\t\t\t\tpathspec->use_wildcard = 1;\n+\t\t\tpitem++;\n+\t\t\tdst++;\n+\t\t}\n \t\telse\n-\t\t\tpathspec->use_wildcard = 1;\n+\t\t\tpathspec->nr--;\n \t}\n \n \tqsort(pathspec->items, pathspec->nr,\n@@ -1300,6 +1326,16 @@ int init_pathspec(struct pathspec *pathspec, const char **paths)\n \treturn 0;\n }\n \n+int init_pathspec(struct pathspec *pathspec, const char **paths)\n+{\n+\tconst char **p = paths;\n+\n+\twhile (p && *p)\n+\t\tp++;\n+\n+\treturn get_pathspec(pathspec, no_prefix, p - paths, paths);\n+}\n+\n void free_pathspec(struct pathspec *pathspec)\n {\n \tfree(pathspec->items);\n-- \n1.7.4.74.g639db\n"},{"id":"165494","messageId":"1302368060-23827-6-git-send-email-pclouds@gmail.com","threadId":"27045","inReplyTo":"1302368060-23827-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 5/5] grep: convert to use the new get_pathspec()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-04-09T16:54:20Z","receivedAt":"2011-04-09T16:54:20Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"---\n builtin/grep.c |   10 +---------\n 1 files changed, 1 insertions(+), 9 deletions(-)\n\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 2826ca8..af16deb 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -734,7 +734,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \tconst char *show_in_pager = NULL, *default_pager = \"dummy\";\n \tstruct grep_opt opt;\n \tstruct object_array list = OBJECT_ARRAY_INIT;\n-\tconst char **paths = NULL;\n \tstruct pathspec pathspec;\n \tstruct string_list path_list = STRING_LIST_INIT_NODUP;\n \tint i;\n@@ -956,14 +955,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t\tverify_filename(prefix, argv[j]);\n \t}\n \n-\tif (i < argc)\n-\t\tpaths = get_pathspec_old(prefix, argv + i);\n-\telse if (prefix) {\n-\t\tpaths = xcalloc(2, sizeof(const char *));\n-\t\tpaths[0] = prefix;\n-\t\tpaths[1] = NULL;\n-\t}\n-\tinit_pathspec(&pathspec, paths);\n+\tget_pathspec(&pathspec, prefix, argc - i, argv + i);\n \tpathspec.max_depth = opt.max_depth;\n \tpathspec.recursive = 1;\n \n-- \n1.7.4.74.g639db\n"},{"id":"165503","messageId":"7vfwpryuey.fsf@alter.siamese.dyndns.org","threadId":"27045","inReplyTo":"1302368060-23827-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH 0/5] New get_pathspec()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-04-09T21:41:25Z","receivedAt":"2011-04-09T21:41:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:\n\n> [PATCH 1/5] Rename functions in preparation for get_pathspec() restructure\n>\n>   I figure I cannot bring all commands to the new get_pathspec() at\n>   once and remove the old one. So instead I rename the old one so that\n>   we can have both implementations running in parallel.\n\nHorribly bad move.  Keep the old one running under the same name, and keep\nthe unconverted ones working the same way without new features.  Introduce\na new infrastructure under a new API function name.\n\nOtherwise you cannot merge in new calles that expect the old\nget_pathspec() behaviour.\n"},{"id":"165520","messageId":"7vbp0fylox.fsf@alter.siamese.dyndns.org","threadId":"27045","inReplyTo":"1302368060-23827-3-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH 2/5] Replace has_wildcard with PATHSPEC_NOGLOB","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-04-10T00:49:50Z","receivedAt":"2011-04-10T00:49:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:\n\n> ---\n>  cache.h     |   22 ++++++++++++++++++++--\n>  dir.c       |   11 +++++++----\n>  setup.c     |   17 -----------------\n>  tree-walk.c |   25 ++++++++++++-------------\n>  4 files changed, 39 insertions(+), 36 deletions(-)\n>\n> diff --git a/cache.h b/cache.h\n> index 27ac8a7..da1a46c 100644\n> --- a/cache.h\n> +++ b/cache.h\n> @@ -501,16 +501,34 @@ extern int index_name_is_other(const struct index_state *, const char *, int);\n>  extern int ie_match_stat(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);\n>  extern int ie_modified(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);\n>  \n> +/*\n> + * Magic pathspec\n> + *\n> + * NEEDSWORK: These need to be moved to dir.h or even to a new\n> + * pathspec.h when we restructure get_pathspec() users to use the\n> + * \"struct pathspec\" interface.\n> + *\n> + * Possible future magic semantics include stuff like:\n> + *\n> + *\t{ PATHSPEC_NOGLOB, '!', \"noglob\" },\n> + *\t{ PATHSPEC_RECURSIVE, '*', \"recursive\" },\n> + *\t{ PATHSPEC_REGEXP, '\\0', \"regexp\" },\n> + *\n> + */\n\nGaah, why did you butcher this to heve only the whole comment and struct\ntype declaration here, without moving the \"Possible future magic\" comment\nthat clearly belongs to the structure definition you still have in dir.c\nto where it belongs?  Also if NOGLOB is no longer \"Possible future\", why\nis it still here?\n"},{"id":"165521","messageId":"7v7hb2zzxp.fsf@alter.siamese.dyndns.org","threadId":"27045","inReplyTo":"1302368060-23827-6-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH 5/5] grep: convert to use the new get_pathspec()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-04-10T00:56:50Z","receivedAt":"2011-04-10T00:56:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:\n\n> ---\n>  builtin/grep.c |   10 +---------\n>  1 files changed, 1 insertions(+), 9 deletions(-)\n>\n> diff --git a/builtin/grep.c b/builtin/grep.c\n> index 2826ca8..af16deb 100644\n> --- a/builtin/grep.c\n> +++ b/builtin/grep.c\n> @@ -734,7 +734,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n>  \tconst char *show_in_pager = NULL, *default_pager = \"dummy\";\n>  \tstruct grep_opt opt;\n>  \tstruct object_array list = OBJECT_ARRAY_INIT;\n> -\tconst char **paths = NULL;\n>  \tstruct pathspec pathspec;\n>  \tstruct string_list path_list = STRING_LIST_INIT_NODUP;\n>  \tint i;\n> @@ -956,14 +955,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n>  \t\t\tverify_filename(prefix, argv[j]);\n>  \t}\n>  \n> -\tif (i < argc)\n> -\t\tpaths = get_pathspec_old(prefix, argv + i);\n> -\telse if (prefix) {\n> -\t\tpaths = xcalloc(2, sizeof(const char *));\n> -\t\tpaths[0] = prefix;\n> -\t\tpaths[1] = NULL;\n> -\t}\n> -\tinit_pathspec(&pathspec, paths);\n> +\tget_pathspec(&pathspec, prefix, argc - i, argv + i);\n\nThis assumes that the new API function will default to \"if run without\npathspec, the calling command wants to limit to cwd\", doesn't it?\n\nThat is why I mentioned that the caller would need to pass a hint as to\nwhat should happen in that case in my earlier message.  Probably the new\nAPI function should be something like:\n\n    setup_pathspec(&pathspec, prefix, argc, argv, opts)\n\nwhere opts is a bitmask to carry that hint (or a pointer to a structure\nthat caller to carry a set of hints richer than a bitmask can express),\nand \"add -u\" and \"grep\" should set PATHSPEC_DEFAULT_LOCAL in the bitmask.\nThe call to setup_pathspec() from the log family would not want \"no user\nspecified pathspec means limited to local\" semantics.\n\nThen when somebody wants to flip the \"add -u\" default in future versions,\nthe call from \"add -u\" codepath can instead use PATHSPEC_DEFAULT_TREEWIDE\n(or perhaps the lack of PATHSPEC_DEFAULT_LOCAL bit may mean tree-wide)\nthere.\n"},{"id":"165532","messageId":"BANLkTikT7pz_nSJRAOb3rtYePBuVc2YX0Q@mail.gmail.com","threadId":"27045","inReplyTo":"7vbp0fylox.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 2/5] Replace has_wildcard with PATHSPEC_NOGLOB","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-04-10T07:23:21Z","receivedAt":"2011-04-10T07:23:21Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"2011/4/10 Junio C Hamano <gitster@pobox.com>:\n>> +/*\n>> + * Magic pathspec\n>> + *\n>> + * NEEDSWORK: These need to be moved to dir.h or even to a new\n>> + * pathspec.h when we restructure get_pathspec() users to use the\n>> + * \"struct pathspec\" interface.\n>> + *\n>> + * Possible future magic semantics include stuff like:\n>> + *\n>> + *   { PATHSPEC_NOGLOB, '!', \"noglob\" },\n>> + *   { PATHSPEC_RECURSIVE, '*', \"recursive\" },\n>> + *   { PATHSPEC_REGEXP, '\\0', \"regexp\" },\n>> + *\n>> + */\n>\n> Gaah, why did you butcher this to heve only the whole comment and struct\n> type declaration here, without moving the \"Possible future magic\" comment\n> that clearly belongs to the structure definition you still have in dir.c\n> to where it belongs?  Also if NOGLOB is no longer \"Possible future\", why\n> is it still here?\n\nCarelessness, I guess. Will move it (with the NOGLOB future line\nremoved) to dir.c, close to get_pathspec().\n-- \nDuy\n"},{"id":"165533","messageId":"BANLkTim1u2gpcjwyg-kDp=oxC_3SzApNWg@mail.gmail.com","threadId":"27045","inReplyTo":"7v7hb2zzxp.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 5/5] grep: convert to use the new get_pathspec()","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-04-10T07:26:31Z","receivedAt":"2011-04-10T07:26:31Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"2011/4/10 Junio C Hamano <gitster@pobox.com>:\n> Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:\n> This assumes that the new API function will default to \"if run without\n> pathspec, the calling command wants to limit to cwd\", doesn't it?\n\nYes, I was blindly reimplementing get_pathspec() behavior...\n\n> That is why I mentioned that the caller would need to pass a hint as to\n> what should happen in that case in my earlier message.  Probably the new\n> API function should be something like:\n>\n>    setup_pathspec(&pathspec, prefix, argc, argv, opts)\n>\n> where opts is a bitmask to carry that hint (or a pointer to a structure\n> that caller to carry a set of hints richer than a bitmask can express),\n> and \"add -u\" and \"grep\" should set PATHSPEC_DEFAULT_LOCAL in the bitmask.\n> The call to setup_pathspec() from the log family would not want \"no user\n> specified pathspec means limited to local\" semantics.\n>\n> Then when somebody wants to flip the \"add -u\" default in future versions,\n> the call from \"add -u\" codepath can instead use PATHSPEC_DEFAULT_TREEWIDE\n> (or perhaps the lack of PATHSPEC_DEFAULT_LOCAL bit may mean tree-wide)\n> there.\n\n... and forgot about this.\n-- \nDuy\n"}]}