nd/parse-pathspec
v3 cover nd/parse-pathspec
Changes from v2 (it's hard to keep track of after the rebase, so I may be missing something here):
- rebased on top of recent master, incorporate changes in init_pathspec from jk/pathspec-literal and nd/pathspec-wildcard to parse_pathspec
- kill strip_trailing_slash_from_submodules and treat_gitlinks (pretty sure it'll cause conflicts with as/check-ignore)
- kill init_pathspec, match_pathspec, diff_tree_setup_paths and diff_tree_release_paths
- check points for future pathspec development
As far as I understand the "pathspec unification", I'd say we are there, with a few exceptions like "mv", external commands.. But those are pretty much isolated.
I'll send another WIP series implementing :(icase) and :(glob), mainly to show (me) how future pathspec feature development looks like after this.
Nguyễn Thái Ngọc Duy (31):
clean: remove unused variable "seen"
Add copy_pathspec
Add parse_pathspec() that converts cmdline args to struct pathspec
parse_pathspec: save original pathspec for reporting
Export parse_pathspec() and convert some get_pathspec() calls Guard against new pathspec magic in pathspec matching code
clean: convert to use parse_pathspec
parse_pathspec: add PATHSPEC_EMPTY_MATCH_ALL
commit: convert to use parse_pathspec
status: convert to use parse_pathspec
rerere: convert to use parse_pathspec
checkout: convert to use parse_pathspec
rm: convert to use parse_pathspec
parse_pathspec: support stripping submodule trailing slashes
ls-files: convert to use parse_pathspec
archive: convert to use parse_pathspec
parse_pathspec: support stripping/checking submodule paths
add: convert to use parse_pathspec
Convert read_cache_preload() to take struct pathspec Convert unmerge_cache to take struct pathspec
checkout: convert read_tree_some to take struct pathspec Convert report_path_error to take struct pathspec
Convert refresh_index to take struct pathspec
Convert {read,fill}_directory to take struct pathspec Convert add_files_to_cache to take struct pathspec
Convert common_prefix() to use struct pathspec
Remove diff_tree_{setup,release}_paths
Remove init_pathspec() in favor of parse_pathspec()
Remove match_pathspec() in favor of match_pathspec_depth()
tree-diff: remove the use of pathspec's raw[] in follow-rename codepath Rename field "raw" to "_raw" in struct pathspec
archive.c | 18 +++-- archive.h | 2 +- builtin/add.c | 155 +++++++++++++++---------------------- builtin/blame.c | 12 +-- builtin/checkout.c | 44 ++++++----- builtin/clean.c | 21 ++--- builtin/commit.c | 37 +++++---- builtin/diff-files.c | 2 +- builtin/diff-index.c | 2 +- builtin/diff.c | 6 +- builtin/grep.c | 6 +- builtin/log.c | 2 +- builtin/ls-files.c | 72 +++++++----------- builtin/ls-tree.c | 10 ++- builtin/mv.c | 13 ++-- builtin/rerere.c | 6 +- builtin/reset.c | 4 +- builtin/rm.c | 23 +++--- builtin/update-index.c | 3 +- cache.h | 36 +++++++-- diff-lib.c | 2 +- diff.h | 2 - dir.c | 202 ++++++++----------------------------------------- dir.h | 9 ++- merge-recursive.c | 2 +- notes-merge.c | 4 +- preload-index.c | 20 ++--- read-cache.c | 5 +- rerere.c | 6 +- rerere.h | 4 +- resolve-undo.c | 4 +- resolve-undo.h | 2 +- revision.c | 11 +-- setup.c | 149 ++++++++++++++++++++++++++++++------ tree-diff.c | 47 +++++++----- tree-walk.c | 2 + tree.c | 4 +- tree.h | 2 +- wt-status.c | 17 ++--- wt-status.h | 2 +- 40 files changed, 460 insertions(+), 510 deletions(-)
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 1/31 clean: remove unused variable "seen"
--- builtin/clean.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
builtin/clean.c +2 -9
@@ -46,7 +46,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)struct strbuf buf =STRBUF_INIT ;struct string_list exclude_list =STRING_LIST_INIT_NODUP ;const char *qname; -char *seen =NULL ;struct option options[] = {OPT__QUIET (&quiet,N_ ("do not print names of files removed" )),OPT__DRY_RUN (&show_only,N_ ("dry run" )),
@@ -105,9 +104,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)fill_directory (&dir, pathspec); -if (pathspec) - seen =xmalloc (argc >0 ? argc :1 ); -for (i =0 ; i < dir.nr; i++) {struct dir_entry *ent = dir.entries[i];int len, pos;
@@ -141,11 +137,9 @@ int cmd_clean(int argc, const char **argv, const char *prefix)if (lstat (ent->name, &st))continue ; -if (pathspec) { -memset (seen,0 , argc >0 ? argc :1 ); +if (pathspec) matches =match_pathspec (pathspec, ent->name, len, -0 , seen); - } +0 ,NULL );if (S_ISDIR (st.st_mode)) {strbuf_addstr (&directory, ent->name);
@@ -184,7 +178,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix) } } } -free (seen);strbuf_release (&directory);string_list_clear (&exclude_list,0 );
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 2/31 Add copy_pathspec
In reply to Nguyễn Thái Ngọc Duy--- builtin/mv.c | 13 +++++++------ cache.h | 1 + dir.c | 8 ++++++++ 3 files changed, 16 insertions(+), 6 deletions(-)
builtin/mv.c +7 -6
@@ -15,8 +15,9 @@ static const char * const builtin_mv_usage[] = { NULL }; -static const char **copy_pathspec (const char *prefix,const char **pathspec, -int count,int base_name) +static const char **internal_copy_pathspec (const char *prefix, +const char **pathspec, +int count,int base_name) {int i;const char **result =xmalloc ((count +1 ) *sizeof (const char *));
@@ -81,17 +82,17 @@ int cmd_mv(int argc, const char **argv, const char *prefix)if (read_cache () <0 )die (_ ("index file corrupt" )); - source =copy_pathspec (prefix, argv, argc,0 ); + source =internal_copy_pathspec (prefix, argv, argc,0 ); modes =xcalloc (argc,sizeof (enum update_mode )); - dest_path =copy_pathspec (prefix, argv + argc,1 ,0 ); + dest_path =internal_copy_pathspec (prefix, argv + argc,1 ,0 );if (dest_path[0 ][0 ] =='\0' )/* special case: "." was normalized to "" */ - destination =copy_pathspec (dest_path[0 ], argv, argc,1 ); + destination =internal_copy_pathspec (dest_path[0 ], argv, argc,1 );else if (!lstat (dest_path[0 ], &st) &&S_ISDIR (st.st_mode)) { dest_path[0 ] =add_slash (dest_path[0 ]); - destination =copy_pathspec (dest_path[0 ], argv, argc,1 ); + destination =internal_copy_pathspec (dest_path[0 ], argv, argc,1 ); }else {if (argc !=1 )die ("destination '%s' is not a directory" , dest_path[0 ]);
cache.h +1 -0
@@ -491,6 +491,7 @@ struct pathspec { };extern int init_pathspec (struct pathspec *,const char **); +extern void copy_pathspec (struct pathspec *dst,const struct pathspec *src);extern void free_pathspec (struct pathspec *);extern int ce_path_match (const struct cache_entry *ce,const struct pathspec *pathspec);
dir.c +8 -0
@@ -1559,6 +1559,14 @@ int init_pathspec(struct pathspec *pathspec, const char **paths)return 0 ; } +void copy_pathspec (struct pathspec *dst,const struct pathspec *src) +{ + *dst = *src; + dst->items =xmalloc (sizeof (struct pathspec_item ) * dst->nr); +memcpy (dst->items, src->items, +sizeof (struct pathspec_item ) * dst->nr); +} +void free_pathspec (struct pathspec *pathspec) {free (pathspec->items);
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 3/31 Add parse_pathspec() that converts cmdline args to struct pathspec
In reply to Nguyễn Thái Ngọc DuyCurrently to fill a struct pathspec, we do:
const char **paths; paths = get_pathspec(prefix, argv); ... init_pathspec(&pathspec, paths);
"paths" can only carry bare strings, which loses information from command line arguments such as pathspec magic or the prefix part's length for each argument.
parse_pathspec() is introduced to combine the two calls into one. The plan is gradually replace all get_pathspec() and init_pathspec() with parse_pathspec(). get_pathspec() now becomes a thin wrapper of parse_pathspec().
parse_pathspec() allows the caller to reject the pathspec magics that it does not support. When a new pathspec magic is introduced, we can enable it per command after making sure that all underlying code has no problem with the new magic.
"flags" parameter is currently unused. But it would allow callers to pass certain instructions to parse_pathspec, for example forcing literal pathspec when no magic is used.
With the introduction of parse_pathspec, there are now two functions that can initialize struct pathspec: init_pathspec and parse_pathspec. Any semantic changes in struct pathspec must be reflected in both functions. init_pathspec() will be phased out in favor of parse_pathspec().
--- cache.h | 2 ++ dir.c | 4 +-- dir.h | 2 ++ setup.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++--------------- 4 files changed, 90 insertions(+), 26 deletions(-)
cache.h +2 -0
@@ -481,9 +481,11 @@ struct pathspec {int nr; unsigned int has_wildcard:1; unsigned int recursive:1; +unsigned magic;int max_depth;struct pathspec_item {const char *match; +unsigned magic;int len;int nowildcard_len;int flags;
dir.c +2 -2
@@ -323,7 +323,7 @@ int match_pathspec_depth(const struct pathspec *ps,/* * Return the length of the "simple" part of a path match limiter. */ -static int simple_length (const char *match) +int simple_length (const char *match) {int len =-1 ;
@@ -335,7 +335,7 @@ static int simple_length(const char *match) } } -static int no_wildcard (const char *string) +int no_wildcard (const char *string) {return string[simple_length (string)] =='\0' ; }
dir.h +2 -0
@@ -88,6 +88,8 @@ struct dir_struct {#define MATCHED_RECURSIVELY 1#define MATCHED_FNMATCH 2#define MATCHED_EXACTLY 3 +extern int simple_length (const char *match); +extern int no_wildcard (const char *string);extern char *common_prefix (const char **pathspec);extern int match_pathspec (const char **pathspec,const char *name,int namelen,int prefix,char *seen); extern int match_pathspec_depth(const struct pathspec *pathspec,
setup.c +84 -24
140 lines not on this page · raw message
Signature · 1 line
1.8.0.rc2.23.g1fb49df
Re: [PATCH v3 03/31] Add parse_pathspec() that converts cmdline args to struct pathspec
setup.c static const char *prefix_pathspec(const char *prefix, int prefixlen, const char · line 316
Quoted 9 lines · Nguyễn Thái Ngọc Duy
setup.c +8
-0+static void parse_pathspec (struct pathspec *pathspec, +unsigned magic_mask,unsigned flags, +const char *prefix,const char **argv) +{ +struct pathspec_item *item; +const char *entry = *argv; +for (i =0 ; i < n; i++) { +const char *arg = argv[i];
Nit: "*argv" was assigned to "entry" above. Reassign that variable instead?
Re: [PATCH v3 03/31] Add parse_pathspec() that converts cmdline args to struct pathspec
Quoted 12 lines · Martin von Zweigbergk
setup.c static const char *prefix_pathspec(const char *prefix, int prefixlen, const char · line 316
Quoted 9 lines · Nguyễn Thái Ngọc Duy
setup.c +8
-0+static void parse_pathspec (struct pathspec *pathspec, +unsigned magic_mask,unsigned flags, +const char *prefix,const char **argv) +{ +struct pathspec_item *item; +const char *entry = *argv; +for (i =0 ; i < n; i++) { +const char *arg = argv[i];Nit: "*argv" was assigned to "entry" above. Reassign that variable instead?
Yeah. Thanks for catching.
Signature · 1 line
Duy
PATCH v3 4/31 parse_pathspec: save original pathspec for reporting
In reply to Nguyễn Thái Ngọc DuyWe usually use pathspec_item's match field for pathspec error reporting. However "match" (or "raw") does not show the magic part, which will play more important role later on. Preserve exact user input for reporting.
--- cache.h | 1 + dir.c | 1 + setup.c | 2 ++ 3 files changed, 4 insertions(+)
cache.h +1 -0
@@ -485,6 +485,7 @@ struct pathspec {int max_depth;struct pathspec_item {const char *match; +const char *original;unsigned magic;int len;int nowildcard_len;
dir.c +1 -0
@@ -1538,6 +1538,7 @@ int init_pathspec(struct pathspec *pathspec, const char **paths)const char *path = paths[i]; item->match = path; + item->original = path; item->len =strlen (path); item->flags =0 ;if (limit_pathspec_to_literal ()) {
setup.c +2 -0
@@ -249,6 +249,7 @@ static unsigned prefix_pathspec(struct pathspec_item *item,else match =prefix_path (prefix, prefixlen, copyfrom); *raw = item->match = match; + item->original = elt; item->len =strlen (item->match); item->flags =0 ;if (limit_pathspec_to_literal ())
@@ -295,6 +296,7 @@ static void parse_pathspec(struct pathspec *pathspec, pathspec->items = item =xmalloc (sizeof (*item)); item->match = prefix; + item->original = prefix; item->nowildcard_len = item->len =strlen (prefix); raw[0 ] = prefix; raw[1 ] =NULL ;
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 5/31 Export parse_pathspec() and convert some get_pathspec() calls
In reply to Nguyễn Thái Ngọc DuyThese call sites follow the pattern:
paths = get_pathspec(prefix, argv); init_pathspec(&pathspec, paths);
which can be converted into a single parse_pathspec() call.
--- builtin/grep.c | 4 +--- builtin/ls-tree.c | 8 +++++++- builtin/update-index.c | 3 +-- cache.h | 6 ++++++ revision.c | 4 ++-- setup.c | 7 +++---- 6 files changed, 20 insertions(+), 12 deletions(-)
builtin/grep.c +1 -3
@@ -630,7 +630,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)const char *show_in_pager =NULL , *default_pager ="dummy" ;struct grep_opt opt;struct object_array list =OBJECT_ARRAY_INIT ; -const char **paths =NULL ;struct pathspec pathspec;struct string_list path_list =STRING_LIST_INIT_NODUP ;int i;
@@ -857,8 +856,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)verify_filename (prefix, argv[j], j == i); } - paths =get_pathspec (prefix, argv + i); -init_pathspec (&pathspec, paths); +parse_pathspec (&pathspec,PATHSPEC_FROMTOP ,0 , prefix, argv + i); pathspec.max_depth = opt.max_depth; pathspec.recursive =1 ;
builtin/ls-tree.c +7 -1
@@ -166,7 +166,13 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)if (get_sha1 (argv[0 ], sha1))die ("Not a valid object name %s" , argv[0 ]); -init_pathspec (&pathspec,get_pathspec (prefix, argv +1 )); +/* +* show_recursive() rolls its own matching code and is +* generally ignorant of 'struct pathspec'. The magic mask +* cannot be lifted until it is converted to use +* match_pathspec_depth() or tree_entry_interesting() +*/ +parse_pathspec (&pathspec,PATHSPEC_FROMTOP ,0 , prefix, argv +1 );for (i =0 ; i < pathspec.nr; i++) pathspec.items[i].nowildcard_len = pathspec.items[i].len; pathspec.has_wildcard =0 ;
builtin/update-index.c +1 -2
@@ -546,10 +546,9 @@ static int do_reupdate(int ac, const char **av,*/ int pos;int has_head =1 ; -const char **paths =get_pathspec (prefix, av +1 );struct pathspec pathspec; -init_pathspec (&pathspec, paths); +parse_pathspec (&pathspec,PATHSPEC_FROMTOP ,0 , prefix, av +1 );if (read_ref ("HEAD" , head_sha1))/* If there is no HEAD, that means it is an initial
cache.h +6 -0
@@ -474,6 +474,9 @@ extern int index_name_is_other(const struct index_state *, const char *, int);extern int ie_match_stat (const struct index_state *,struct cache_entry *,struct stat *,unsigned int );extern int ie_modified (const struct index_state *,struct cache_entry *,struct stat *,unsigned int ); +/* Pathspec magic */ +#define PATHSPEC_FROMTOP (1<<0) +#define PATHSPEC_ONESTAR 1/* the pathspec pattern sastisfies GFNM_ONESTAR */ struct pathspec {
@@ -494,6 +497,9 @@ struct pathspec { };extern int init_pathspec (struct pathspec *,const char **); +extern void parse_pathspec (struct pathspec *pathspec,unsigned magic_mask, +unsigned flags,const char *prefix, +const char **args);extern void copy_pathspec (struct pathspec *dst,const struct pathspec *src);extern void free_pathspec (struct pathspec *);extern int ce_path_match (const struct cache_entry *ce,const struct pathspec *pathspec);
revision.c +2 -2
@@ -1851,8 +1851,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s*/ ALLOC_GROW (prune_data.path, prune_data.nr+1 , prune_data.alloc); prune_data.path[prune_data.nr++] =NULL ; -init_pathspec (&revs->prune_data, -get_pathspec (revs->prefix, prune_data.path)); +parse_pathspec (&revs->prune_data,PATHSPEC_FROMTOP ,0 , + revs->prefix, prune_data.path); }if (revs->def ==NULL )
setup.c +3 -4
@@ -162,7 +162,6 @@ void verify_non_filename(const char *prefix, const char *arg)* { PATHSPEC_REGEXP, '\0', "regexp" }, * */ -#define PATHSPEC_FROMTOP (1<<0) static struct pathspec_magic { unsigned bit;
@@ -276,9 +275,9 @@ static int pathspec_item_cmp(const void *a_, const void *b_)* Given command line arguments and a prefix, convert the input to * pathspec. die() if any magic other than ones in magic_mask. */ -static void parse_pathspec (struct pathspec *pathspec, -unsigned magic_mask,unsigned flags, -const char *prefix,const char **argv) +void parse_pathspec (struct pathspec *pathspec, +unsigned magic_mask,unsigned flags, +const char *prefix,const char **argv) {struct pathspec_item *item;const char *entry = *argv;
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 6/31 Guard against new pathspec magic in pathspec matching code
In reply to Nguyễn Thái Ngọc DuyGUARD_PATHSPEC() marks pathspec-sensitive code (basically anything in 'struct pathspec' except fields "nr" and "original"). GUARD_PATHSPEC() is not supposed to fail. The steps for a new pathspec magic or optimization would be:
- update parse_pathspec, add extra information to struct pathspec
- grep GUARD_PATHSPEC() and update all relevant code (or note those that won't work with your new stuff). Update GUARD_PATHSPEC mask accordingly.
- update parse_pathspec calls to allow new magic. Make sure parse_pathspec() catches unsupported syntax early, not until GUARD_PATHSPEC catches it.
- add tests to verify supported/unsupported commands both work as expected.
--- builtin/diff.c | 2 ++ cache.h | 7 +++++++ dir.c | 2 ++ tree-diff.c | 19 +++++++++++++++++++ tree-walk.c | 2 ++ 5 files changed, 32 insertions(+)
builtin/diff.c +2 -0
@@ -371,6 +371,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)die (_ ("unhandled object '%s' given." ), name); }if (rev.prune_data.nr) { +/* builtin_diff_b_f() */ +GUARD_PATHSPEC (&rev.prune_data,PATHSPEC_FROMTOP );if (!path) path = rev.prune_data.items[0 ].match; paths += rev.prune_data.nr;
cache.h +7 -0
@@ -496,6 +496,13 @@ struct pathspec { } *items; }; +#define GUARD_PATHSPEC (ps, mask) \ + do { \ + if ((ps)->magic & ~(mask)) \ + die("BUG:%s:%d: unsupported magic %x", \ + __FILE__, __LINE__, (ps)->magic & ~(mask)); \ + } while (0) +extern int init_pathspec (struct pathspec *,const char **); extern void parse_pathspec(struct pathspec *pathspec, unsigned magic_mask, unsigned flags, const char *prefix,
dir.c +2 -0
@@ -282,6 +282,8 @@ int match_pathspec_depth(const struct pathspec *ps, {int i, retval =0 ; +GUARD_PATHSPEC (ps,PATHSPEC_FROMTOP ); +if (!ps->nr) {if (!ps->recursive || ps->max_depth ==-1 )return MATCHED_RECURSIVELY ;
tree-diff.c +19 -0
@@ -199,6 +199,25 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, coconst char *paths[1 ];int i; +/* +* follow-rename code is very specific, we need exactly one +* path. Magic that matches more than one path is not +* supported. +*/ +GUARD_PATHSPEC (&opt->pathspec,PATHSPEC_FROMTOP ); +#if 0 +/* +* We should reject wildcards as well. Unfortunately we +* haven't got a reliable way to detect that 'foo\*bar' in +* fact has no wildcards. nowildcard_len is merely a hint for +* optimization. Let it slip for now until wildmatch is taught +* about dry-run mode and returns wildcard info. +*/ +if (opt->pathspec.has_wildcard) +die ("BUG:%s:%d: wildcards are not supported" , + __FILE__, __LINE__); +#endif +/* Remove the file creation entry from the diff queue, and remember it */ choice = q->queue[0 ]; q->nr =0 ;
tree-walk.c +2 -0
@@ -635,6 +635,8 @@ enum interesting tree_entry_interesting(const struct name_entry *entry,enum interesting never_interesting = ps->has_wildcard ? entry_not_interesting : all_entries_not_interesting; +GUARD_PATHSPEC (ps,PATHSPEC_FROMTOP ); +if (!ps->nr) {if (!ps->recursive || ps->max_depth ==-1 )return all_entries_interesting;
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 7/31 clean: convert to use parse_pathspec
In reply to Nguyễn Thái Ngọc Duy--- builtin/clean.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
builtin/clean.c +7 -7
@@ -42,7 +42,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)int rm_flags =REMOVE_DIR_KEEP_NESTED_GIT ;struct strbuf directory =STRBUF_INIT ;struct dir_struct dir; -static const char **pathspec; +struct pathspec pathspec;struct strbuf buf =STRBUF_INIT ;struct string_list exclude_list =STRING_LIST_INIT_NODUP ;const char *qname;
@@ -100,9 +100,9 @@ int cmd_clean(int argc, const char **argv, const char *prefix)add_exclude (exclude_list.items[i].string,"" ,0 , &dir.exclude_list[EXC_CMDL ]); - pathspec =get_pathspec (prefix, argv); +parse_pathspec (&pathspec,PATHSPEC_FROMTOP ,0 , prefix, argv); -fill_directory (&dir, pathspec); +fill_directory (&dir, pathspec.raw);for (i =0 ; i < dir.nr; i++) {struct dir_entry *ent = dir.entries[i];
@@ -137,9 +137,9 @@ int cmd_clean(int argc, const char **argv, const char *prefix)if (lstat (ent->name, &st))continue ; -if (pathspec) - matches =match_pathspec (pathspec, ent->name, len, -0 ,NULL ); +if (pathspec.nr) + matches =match_pathspec_depth (&pathspec, ent->name, + len,0 ,NULL );if (S_ISDIR (st.st_mode)) {strbuf_addstr (&directory, ent->name);
@@ -163,7 +163,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix) }strbuf_reset (&directory); }else { -if (pathspec && !matches) +if (pathspec.nr && !matches)continue ; qname =quote_path_relative (ent->name,-1 , &buf, prefix);if (show_only) {
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 8/31 parse_pathspec: add PATHSPEC_EMPTY_MATCH_ALL
In reply to Nguyễn Thái Ngọc DuyWe have two ways of dealing with empty pathspec:
1. limit it to current prefix
2. match the entire working directory
Some commands go with #1, some with #2. get_pathspec() and parse_pathspec() only supports #1. Make it support #2 too via PATHSPEC_EMPTY_MATCH_ALL flag.
--- cache.h | 3 +++ setup.c | 3 +++ 2 files changed, 6 insertions(+)
cache.h +3 -0
@@ -503,6 +503,9 @@ struct pathspec { __FILE__, __LINE__, (ps)->magic & ~(mask)); \ }while (0 ) +/* parse_pathspec flags */ +#define PATHSPEC_EMPTY_MATCH_ALL (1<<0)/* No args means match everything */ +extern int init_pathspec (struct pathspec *,const char **); extern void parse_pathspec(struct pathspec *pathspec, unsigned magic_mask, unsigned flags, const char *prefix,
setup.c +3 -0
@@ -289,6 +289,9 @@ void parse_pathspec(struct pathspec *pathspec,if (!entry && !prefix)return ; +if (!*argv && (flags &PATHSPEC_EMPTY_MATCH_ALL )) +return ; +/* No arguments with prefix -> prefix pathspec */ if (!entry) {static const char *raw[2 ];
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 9/31 commit: convert to use parse_pathspec
In reply to Nguyễn Thái Ngọc Duy--- builtin/commit.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
builtin/commit.c +9 -9
@@ -277,17 +277,17 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, {int fd;struct string_list partial; -const char **pathspec =NULL ; +struct pathspec pathspec;char *old_index_env =NULL ;int refresh_flags =REFRESH_QUIET ;if (is_status) refresh_flags |=REFRESH_UNMERGED ; +parse_pathspec (&pathspec,PATHSPEC_FROMTOP , +PATHSPEC_EMPTY_MATCH_ALL , + prefix, argv); -if (*argv) - pathspec =get_pathspec (prefix, argv); - -if (read_cache_preload (pathspec) <0 ) +if (read_cache_preload (pathspec.raw) <0 )die (_ ("index file corrupt" ));if (interactive) {
@@ -329,9 +329,9 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,* (A) if all goes well, commit the real index; * (B) on failure, rollback the real index. */ -if (all || (also && pathspec && *pathspec)) { +if (all || (also && pathspec.nr)) { fd =hold_locked_index (&index_lock,1 ); -add_files_to_cache (also ? prefix :NULL , pathspec,0 ); +add_files_to_cache (also ? prefix :NULL , pathspec.raw,0 );refresh_cache_or_die (refresh_flags);update_main_cache_tree (WRITE_TREE_SILENT ); if (write_cache(fd, active_cache, active_nr) ||
@@ -350,7 +350,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,* and create commit from the_index. * We still need to refresh the index here. */ -if (!only && (!pathspec || !*pathspec)) { +if (!only && !pathspec.nr) { fd =hold_locked_index (&index_lock,1 );refresh_cache_or_die (refresh_flags);if (active_cache_changed) {
@@ -395,7 +395,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,memset (&partial,0 ,sizeof (partial)); partial.strdup_strings =1 ; -if (list_paths (&partial, !current_head ?NULL :"HEAD" , prefix, pathspec)) +if (list_paths (&partial, !current_head ?NULL :"HEAD" , prefix, pathspec.raw))exit (1 );discard_cache ();
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 10/31 status: convert to use parse_pathspec
In reply to Nguyễn Thái Ngọc Duy--- builtin/commit.c | 9 +++++---- wt-status.c | 17 +++++++---------- wt-status.h | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-)
builtin/commit.c +5 -4
@@ -1205,11 +1205,12 @@ int cmd_status(int argc, const char **argv, const char *prefix)handle_untracked_files_arg (&s);if (show_ignored_in_status) s.show_ignored_files =1 ; -if (*argv) - s.pathspec =get_pathspec (prefix, argv); +parse_pathspec (&s.pathspec,PATHSPEC_FROMTOP , +PATHSPEC_EMPTY_MATCH_ALL , + prefix, argv); -read_cache_preload (s.pathspec); -refresh_index (&the_index,REFRESH_QUIET |REFRESH_UNMERGED , s.pathspec,NULL ,NULL ); +read_cache_preload (s.pathspec.raw); +refresh_index (&the_index,REFRESH_QUIET |REFRESH_UNMERGED , s.pathspec.raw,NULL ,NULL ); fd =hold_locked_index (&index_lock,0 );if (0 <= fd)
wt-status.c +7 -10
@@ -434,7 +434,7 @@ static void wt_status_collect_changes_worktree(struct wt_status *s) } rev.diffopt.format_callback = wt_status_collect_changed_cb; rev.diffopt.format_callback_data = s; -init_pathspec (&rev.prune_data, s->pathspec); +copy_pathspec (&rev.prune_data, &s->pathspec);run_diff_files (&rev,0 ); }
@@ -459,22 +459,20 @@ static void wt_status_collect_changes_index(struct wt_status *s) rev.diffopt.detect_rename =1 ; rev.diffopt.rename_limit =200 ; rev.diffopt.break_opt =0 ; -init_pathspec (&rev.prune_data, s->pathspec); +copy_pathspec (&rev.prune_data, &s->pathspec);run_diff_index (&rev,1 ); }static void wt_status_collect_changes_initial (struct wt_status *s) { -struct pathspec pathspec;int i; -init_pathspec (&pathspec, s->pathspec);for (i =0 ; i < active_nr; i++) {struct string_list_item *it;struct wt_status_change_data *d;struct cache_entry *ce = active_cache[i]; -if (!ce_path_match (ce, &pathspec)) +if (!ce_path_match (ce, &s->pathspec))continue ; it =string_list_insert (&s->change, ce->name); d = it->util;
@@ -489,7 +487,6 @@ static void wt_status_collect_changes_initial(struct wt_status *s)else d->index_status =DIFF_STATUS_ADDED ; } -free_pathspec (&pathspec); }static void wt_status_collect_untracked (struct wt_status *s)
@@ -505,11 +502,11 @@ static void wt_status_collect_untracked(struct wt_status *s)DIR_SHOW_OTHER_DIRECTORIES |DIR_HIDE_EMPTY_DIRECTORIES ;setup_standard_excludes (&dir); -fill_directory (&dir, s->pathspec); +fill_directory (&dir, s->pathspec.raw);for (i =0 ; i < dir.nr; i++) {struct dir_entry *ent = dir.entries[i];if (cache_name_is_other (ent->name, ent->len) && -match_pathspec (s->pathspec, ent->name, ent->len,0 ,NULL )) +match_pathspec_depth (&s->pathspec, ent->name, ent->len,0 ,NULL ))string_list_insert (&s->untracked, ent->name);free (ent); }
@@ -517,11 +514,11 @@ static void wt_status_collect_untracked(struct wt_status *s)if (s->show_ignored_files) { dir.nr =0 ; dir.flags =DIR_SHOW_IGNORED |DIR_SHOW_OTHER_DIRECTORIES ; -fill_directory (&dir, s->pathspec); +fill_directory (&dir, s->pathspec.raw);for (i =0 ; i < dir.nr; i++) {struct dir_entry *ent = dir.entries[i];if (cache_name_is_other (ent->name, ent->len) && -match_pathspec (s->pathspec, ent->name, ent->len,0 ,NULL )) +match_pathspec_depth (&s->pathspec, ent->name, ent->len,0 ,NULL ))string_list_insert (&s->ignored, ent->name);free (ent); }
wt-status.h +1 -1
@@ -44,7 +44,7 @@ struct wt_status {int is_initial;char *branch;const char *reference; -const char **pathspec; +struct pathspec pathspec;int verbose;int amend;enum commit_whence whence;
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 11/31 rerere: convert to use parse_pathspec
In reply to Nguyễn Thái Ngọc Duy--- builtin/rerere.c | 6 +++--- rerere.c | 8 ++++---- rerere.h | 4 +++- 3 files changed, 10 insertions(+), 8 deletions(-)
builtin/rerere.c +3 -3
@@ -68,11 +68,11 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)return rerere (flags);if (!strcmp (argv[0 ],"forget" )) { -const char **pathspec; +struct pathspec pathspec;if (argc <2 )warning ("'git rerere forget' without paths is deprecated" ); - pathspec =get_pathspec (prefix, argv +1 ); -return rerere_forget (pathspec); +parse_pathspec (&pathspec,PATHSPEC_FROMTOP ,0 , prefix, argv +1 ); +return rerere_forget (&pathspec); } fd =setup_rerere (&merge_rr, flags);
rerere.c +4 -4
@@ -655,7 +655,7 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)return 0 ; } -int rerere_forget (const char **pathspec) +int rerere_forget (struct pathspec *pathspec) {int i, fd;struct string_list conflict =STRING_LIST_INIT_DUP ;
@@ -666,12 +666,12 @@ int rerere_forget(const char **pathspec) fd =setup_rerere (&merge_rr,RERERE_NOAUTOUPDATE ); -unmerge_cache (pathspec); +unmerge_cache (pathspec->raw);find_conflict (&conflict);for (i =0 ; i < conflict.nr; i++) {struct string_list_item *it = &conflict.items[i]; -if (!match_pathspec (pathspec, it->string,strlen (it->string), -0 ,NULL )) +if (!match_pathspec_depth (pathspec, it->string,strlen (it->string), +0 ,NULL ))continue ;rerere_forget_one_path (it->string, &merge_rr); }
rerere.h +3 -1
@@ -3,6 +3,8 @@#include "string-list.h" +struct pathspec ; +#define RERERE_AUTOUPDATE 01#define RERERE_NOAUTOUPDATE 02
@@ -16,7 +18,7 @@ extern void *RERERE_RESOLVED;extern int setup_rerere (struct string_list *,int );extern int rerere (int );extern const char *rerere_path (const char *hex,const char *file); -extern int rerere_forget (const char **); +extern int rerere_forget (struct pathspec *);extern int rerere_remaining (struct string_list *);extern void rerere_clear (struct string_list *);extern void rerere_gc (struct string_list *);
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 12/31 checkout: convert to use parse_pathspec
In reply to Nguyễn Thái Ngọc DuyThis commit introduces a subtle bug:
- when match_pathspec() returns seen[], it follows the order of the input "const char **pathspec", which is now pathspec.raw[]
- when match_pathspec() returns seen[], it follows the order of pathspec.items[]
- due to 86e4ca6 (tree_entry_interesting(): fix depth limit with overlapping pathspecs - 2010-12-15), pathspec.items[] is sorted, but pathspec.raw[] is NOT.
by converting from match_pathspec() to match_pathspec_depth(), we also have to switch the original path array. Unfortunately we can't because this array is processed by report_path_error() and it's also used by builtin/ls-files.c, which still uses the old indexing.
The bug causes wrong error messages (e.g. if the first pathspec is faulty, it may report the second..) The bug will be dealt with after ls-files is converted.
--- builtin/checkout.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-)
builtin/checkout.c +21 -16
@@ -45,7 +45,7 @@ struct checkout_opts {int branch_exists;const char *prefix; -const char **pathspec; +struct pathspec pathspec;struct tree *source_tree; };
@@ -256,39 +256,37 @@ static int checkout_paths(const struct checkout_opts *opts,if (opts->patch_mode)return run_add_interactive (revision,"--patch=checkout" , - opts->pathspec); + opts->pathspec.raw); lock_file =xcalloc (1 ,sizeof (struct lock_file )); newfd =hold_locked_index (lock_file,1 ); -if (read_cache_preload (opts->pathspec) <0 ) +if (read_cache_preload (opts->pathspec.raw) <0 )return error (_ ("corrupt index file" ));if (opts->source_tree) -read_tree_some (opts->source_tree, opts->pathspec); +read_tree_some (opts->source_tree, opts->pathspec.raw); -for (pos =0 ; opts->pathspec[pos]; pos++) - ; - ps_matched =xcalloc (1 , pos); + ps_matched =xcalloc (1 , opts->pathspec.nr);for (pos =0 ; pos < active_nr; pos++) {struct cache_entry *ce = active_cache[pos];if (opts->source_tree && !(ce->ce_flags &CE_UPDATE ))continue ; -match_pathspec (opts->pathspec, ce->name,ce_namelen (ce),0 , ps_matched); +match_pathspec_depth (&opts->pathspec, ce->name,ce_namelen (ce),0 , ps_matched); } -if (report_path_error (ps_matched, opts->pathspec, opts->prefix)) +if (report_path_error (ps_matched, opts->pathspec.raw, opts->prefix))return 1 ;/* "checkout -m path" to recreate conflicted state */ if (opts->merge) -unmerge_cache (opts->pathspec); +unmerge_cache (opts->pathspec.raw);/* Any unmerged paths? */ for (pos =0 ; pos < active_nr; pos++) {struct cache_entry *ce = active_cache[pos]; -if (match_pathspec (opts->pathspec, ce->name,ce_namelen (ce),0 ,NULL )) { +if (match_pathspec_depth (&opts->pathspec, ce->name,ce_namelen (ce),0 ,NULL )) {if (!ce_stage (ce))continue ;if (opts->force) {
@@ -315,7 +313,7 @@ static int checkout_paths(const struct checkout_opts *opts,struct cache_entry *ce = active_cache[pos];if (opts->source_tree && !(ce->ce_flags &CE_UPDATE ))continue ; -if (match_pathspec (opts->pathspec, ce->name,ce_namelen (ce),0 ,NULL )) { +if (match_pathspec_depth (&opts->pathspec, ce->name,ce_namelen (ce),0 ,NULL )) {if (!ce_stage (ce)) { errs |=checkout_entry (ce, &state,NULL );continue ;
@@ -960,7 +958,7 @@ static int switch_unborn_to_new_branch(const struct checkout_opts *opts)static int checkout_branch (struct checkout_opts *opts,struct branch_info *new) { -if (opts->pathspec) +if (opts->pathspec.nr)die (_ ("paths cannot be used with switching branches" ));if (opts->patch_mode)
@@ -1110,9 +1108,16 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) }if (argc) { - opts.pathspec =get_pathspec (prefix, argv); +/* +* In patch mode (opts.patch_mode != 0), we pass the +* pathspec to an external program, git-add--interactive. +* Do not accept any kind of magic that that program +* cannot handle. Magic mask is pretty safe to be +* lifted for new magic when opts.patch_mode == 0. +*/ +parse_pathspec (&opts.pathspec,PATHSPEC_FROMTOP ,0 , prefix, argv); -if (!opts.pathspec) +if (!opts.pathspec.nr)die (_ ("invalid path specification" ));/*
@@ -1144,7 +1149,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)strbuf_release (&buf); } -if (opts.patch_mode || opts.pathspec) +if (opts.patch_mode || opts.pathspec.nr)return checkout_paths (&opts, new.name);else return checkout_branch (&opts, &new);
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 13/31 rm: convert to use parse_pathspec
In reply to Nguyễn Thái Ngọc Duy--- builtin/rm.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
builtin/rm.c +11 -12
@@ -216,7 +216,7 @@ static struct option builtin_rm_options[] = {int cmd_rm (int argc,const char **argv,const char *prefix) {int i, newfd; -const char **pathspec; +struct pathspec pathspec;char *seen;git_config (git_default_config,NULL );
@@ -249,31 +249,30 @@ int cmd_rm(int argc, const char **argv, const char *prefix) } } - pathspec =get_pathspec (prefix, argv); -refresh_index (&the_index,REFRESH_QUIET , pathspec,NULL ,NULL ); +parse_pathspec (&pathspec,PATHSPEC_FROMTOP ,0 , prefix, argv); +refresh_index (&the_index,REFRESH_QUIET , pathspec.raw,NULL ,NULL ); seen =NULL ; -for (i =0 ; pathspec[i] ; i++) -/* nothing */ ; - seen =xcalloc (i,1 ); + seen =xcalloc (pathspec.nr,1 );for (i =0 ; i < active_nr; i++) {struct cache_entry *ce = active_cache[i]; -if (!match_pathspec (pathspec, ce->name,ce_namelen (ce),0 , seen)) +if (!match_pathspec_depth (&pathspec, ce->name,ce_namelen (ce),0 , seen))continue ;ALLOC_GROW (list.entry, list.nr +1 , list.alloc); list.entry[list.nr].name = ce->name; list.entry[list.nr++].is_submodule =S_ISGITLINK (ce->ce_mode); } -if (pathspec) { -const char *match; +if (pathspec.nr) { +const char *original;int seen_any =0 ; -for (i =0 ; (match = pathspec[i]) !=NULL ; i++) { +for (i =0 ; i < pathspec.nr; i++) { + original = pathspec.items[i].original;if (!seen[i]) {if (!ignore_unmatch) {die (_ ("pathspec '%s' did not match any files" ), - match); + original); } }else {
@@ -281,7 +280,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix) }if (!recursive && seen[i] ==MATCHED_RECURSIVELY )die (_ ("not removing '%s' recursively without -r" ), - *match ? match :"." ); + *original ? original :"." ); }if (! seen_any)
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 14/31 parse_pathspec: support stripping submodule trailing slashes
In reply to Nguyễn Thái Ngọc DuyThis flag is equivalent to builtin/ls-files.c:strip_trailing_slashes() and is intended to replace that function when ls-files is converted to use parse_pathspec.
--- cache.h | 1 + setup.c | 9 +++++++++ 2 files changed, 10 insertions(+)
cache.h +1 -0
@@ -505,6 +505,7 @@ struct pathspec {/* parse_pathspec flags */ #define PATHSPEC_EMPTY_MATCH_ALL (1<<0)/* No args means match everything */ +#define PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP (1<<1)extern int init_pathspec (struct pathspec *,const char **); extern void parse_pathspec(struct pathspec *pathspec, unsigned magic_mask,
setup.c +9 -0
@@ -250,6 +250,15 @@ static unsigned prefix_pathspec(struct pathspec_item *item, *raw = item->match = match; item->original = elt; item->len =strlen (item->match); + +if ((flags &PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP ) && + (item->len >=1 && item->match[item->len -1 ] =='/' ) && + (i =cache_name_pos (item->match, item->len -1 )) >=0 && +S_ISGITLINK (active_cache[i]->ce_mode)) { + item->len--; + match[item->len] ='\0' ; + } + item->flags =0 ;if (limit_pathspec_to_literal ()) item->nowildcard_len = item->len;
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 15/31 ls-files: convert to use parse_pathspec
In reply to Nguyễn Thái Ngọc Duystrip_trailing_slash_from_submodules() modifies pathspec and is moved to dir.c, close to other pathspec code. It'll be removed later when parse_pathspec() learns to take over its job.
This commit introduces a subtle bug:
- when match_pathspec() returns seen[], it follows the order of the input "const char **pathspec", which is now pathspec.raw[]
- when match_pathspec() returns seen[], it follows the order of pathspec.items[]
- due to 86e4ca6 (tree_entry_interesting(): fix depth limit with overlapping pathspecs - 2010-12-15), pathspec.items[] is sorted, but pathspec.raw[] is NOT.
by converting from match_pathspec() to match_pathspec_depth(), we also have to switch the original path array. The bug causes wrong error messages (e.g. if the first pathspec is faulty, it may report the second..). report_path_error will be fixed in a separate patch.
--- builtin/ls-files.c | 45 ++++++++++++--------------------------------- 1 file changed, 12 insertions(+), 33 deletions(-)
builtin/ls-files.c +12 -33
@@ -30,7 +30,7 @@ static int debug_mode;static const char *prefix;static int max_prefix_len;static int prefix_len; -static const char **pathspec; +static struct pathspec pathspec;static int error_unmatch;static char *ps_matched;static const char *with_tree;
@@ -58,7 +58,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)if (len >= ent->len)die ("git ls-files: internal error - directory entry not superset of prefix" ); -if (!match_pathspec (pathspec, ent->name, ent->len, len, ps_matched)) +if (!match_pathspec_depth (&pathspec, ent->name, ent->len, len, ps_matched))return ;fputs (tag, stdout);
@@ -133,7 +133,7 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)if (len >=ce_namelen (ce))die ("git ls-files: internal error - cache entry not superset of prefix" ); -if (!match_pathspec (pathspec, ce->name,ce_namelen (ce), len, ps_matched)) +if (!match_pathspec_depth (&pathspec, ce->name,ce_namelen (ce), len, ps_matched))return ; if (tag && *tag && show_valid_bit &&
@@ -187,7 +187,7 @@ static void show_ru_info(void) len =strlen (path);if (len < max_prefix_len)continue ;/* outside of the prefix */ -if (!match_pathspec (pathspec, path, len, max_prefix_len, ps_matched)) +if (!match_pathspec_depth (&pathspec, path, len, max_prefix_len, ps_matched))continue ;/* uninterested */ for (i =0 ; i <3 ; i++) {if (!ui->mode[i])
@@ -216,7 +216,7 @@ static void show_files(struct dir_struct *dir)/* For cached/deleted files we don't need to even do the readdir */ if (show_others || show_killed) { -fill_directory (dir, pathspec); +fill_directory (dir, pathspec.raw);if (show_others)show_other_files (dir);if (show_killed)
@@ -287,21 +287,6 @@ static void prune_cache(const char *prefix) active_nr = last; } -static void strip_trailing_slash_from_submodules (void ) -{ -const char **p; - -for (p = pathspec; *p !=NULL ; p++) { -int len =strlen (*p), pos; - -if (len <1 || (*p)[len -1 ] !='/' ) -continue ; - pos =cache_name_pos (*p, len -1 ); -if (pos >=0 &&S_ISGITLINK (active_cache[pos]->ce_mode)) - *p =xstrndup (*p, len -1 ); - } -} -/* * Read the tree specified with --with-tree option * (typically, HEAD) into stage #1 and then
@@ -549,23 +534,17 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)if (require_work_tree && !is_inside_work_tree ())setup_work_tree (); - pathspec =get_pathspec (prefix, argv); - -/* be nice with submodule paths ending in a slash */ -if (pathspec) -strip_trailing_slash_from_submodules (); +parse_pathspec (&pathspec,PATHSPEC_FROMTOP , +PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP , + prefix, argv);/* Find common prefix for all pathspec's */ - max_prefix =common_prefix (pathspec); + max_prefix =common_prefix (pathspec.raw); max_prefix_len = max_prefix ?strlen (max_prefix) :0 ;/* Treat unmatching pathspec elements as errors */ -if (pathspec && error_unmatch) { -int num; -for (num =0 ; pathspec[num]; num++) - ; - ps_matched =xcalloc (1 , num); - } +if (pathspec.nr && error_unmatch) + ps_matched =xcalloc (1 , pathspec.nr);if ((dir.flags &DIR_SHOW_IGNORED ) && !exc_given)die ("ls-files --ignored needs some exclude pattern" );
@@ -592,7 +571,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)if (ps_matched) {int bad; - bad =report_path_error (ps_matched, pathspec, prefix); + bad =report_path_error (ps_matched, pathspec.raw, prefix);if (bad)fprintf (stderr,"Did you forget to 'git add'?\n" );
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 16/31 archive: convert to use parse_pathspec
In reply to Nguyễn Thái Ngọc Duy--- archive.c | 16 ++++++++++------ archive.h | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-)
archive.c +10 -6
@@ -151,7 +151,6 @@ int write_archive_entries(struct archiver_args *args,struct archiver_context context;struct unpack_trees_options opts;struct tree_desc t; -struct pathspec pathspec;int err;if (args->baselen >0 && args->base[args->baselen -1 ] =='/' ) {
@@ -186,10 +185,8 @@ int write_archive_entries(struct archiver_args *args,git_attr_set_direction (GIT_ATTR_INDEX , &the_index); } -init_pathspec (&pathspec, args->pathspec); - err =read_tree_recursive (args->tree,"" ,0 ,0 , &pathspec, + err =read_tree_recursive (args->tree,"" ,0 ,0 , &args->pathspec, write_archive_entry, &context); -free_pathspec (&pathspec);if (err ==READ_TREE_RECURSIVE ) err =0 ;return err;
@@ -231,8 +228,15 @@ static int path_exists(struct tree *tree, const char *path)static void parse_pathspec_arg (const char **pathspec,struct archiver_args *ar_args) { - ar_args->pathspec = pathspec =get_pathspec ("" , pathspec); -if (pathspec) { +/* +* raw[] is used to check for unused pathspec. This is +* tree_entry_interesting's limitation because it does not +* mark "used" pathspec. The magic mask cannot be lifted until +* it does. +*/ +parse_pathspec (&ar_args->pathspec,PATHSPEC_FROMTOP ,0 ,"" , pathspec); +if (ar_args->pathspec.nr) { + pathspec = ar_args->pathspec.raw;while (*pathspec) {if (!path_exists (ar_args->tree, *pathspec))die ("path not found: %s" , *pathspec);
archive.h +1 -1
@@ -8,7 +8,7 @@ struct archiver_args {const unsigned char *commit_sha1;const struct commit *commit;time_t time; -const char **pathspec; +struct pathspec pathspec; unsigned int verbose : 1; unsigned int worktree_attributes : 1; unsigned int convert : 1;
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 17/31 parse_pathspec: support stripping/checking submodule paths
In reply to Nguyễn Thái Ngọc DuyPATHSPEC_SYMLINK_LEADING_PATH and _STRIP_SUBMODULE_SLASH_EXPENSIVE are respectively the alternate implementation of builtin/add.c:validate_pathspec() and builtin/add.c:treat_gitlinks(). They are intended to replace those functions when builtin/add.c is converted to use parse_pathspec.
--- cache.h | 2 ++ setup.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+)
cache.h +2 -0
@@ -506,6 +506,8 @@ struct pathspec {/* parse_pathspec flags */ #define PATHSPEC_EMPTY_MATCH_ALL (1<<0)/* No args means match everything */ #define PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP (1<<1) +#define PATHSPEC_SYMLINK_LEADING_PATH (1<<2)/* has_symlink_leading_path */ +#define PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE (1<<3)extern int init_pathspec (struct pathspec *,const char **); extern void parse_pathspec(struct pathspec *pathspec, unsigned magic_mask,
setup.c +26 -0
@@ -259,6 +259,26 @@ static unsigned prefix_pathspec(struct pathspec_item *item, match[item->len] ='\0' ; } +if (flags &PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE ) +for (i =0 ; i < active_nr; i++) { +struct cache_entry *ce = active_cache[i]; +int ce_len =ce_namelen (ce); + +if (!S_ISGITLINK (ce->ce_mode)) +continue ; + +if (item->len <= ce_len || match[ce_len] !='/' || +memcmp (ce->name, match, ce_len)) +continue ; +if (item->len == ce_len +1 ) { +/* strip trailing slash */ + item->len--; + match[item->len] ='\0' ; + }else +die (_ ("Pathspec '%s' is in submodule '%.*s'" ), + elt, ce_len, ce->name); + } + item->flags =0 ;if (limit_pathspec_to_literal ()) item->nowildcard_len = item->len;
@@ -333,6 +353,12 @@ void parse_pathspec(struct pathspec *pathspec,if (item[i].magic & ~magic_mask)die (_ ("pathspec magic in '%s' is not supported" " by this command" ), arg); + +if ((flags &PATHSPEC_SYMLINK_LEADING_PATH ) && +has_symlink_leading_path (item[i].match, item[i].len)) { +die (_ ("pathspec '%s' is beyond a symbolic link" ), arg); + } +if (item[i].nowildcard_len < item[i].len) pathspec->has_wildcard =1 ; pathspec->magic |= item[i].magic;
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 18/31 add: convert to use parse_pathspec
In reply to Nguyễn Thái Ngọc Duy--- builtin/add.c | 106 +++++++++++++++++++++------------------------------------- 1 file changed, 39 insertions(+), 67 deletions(-)
builtin/add.c +39 -67
@@ -153,33 +153,6 @@ static char *prune_directory(struct dir_struct *dir, const char **pathspec, intreturn seen; } -static void treat_gitlinks (const char **pathspec) -{ -int i; - -if (!pathspec || !*pathspec) -return ; - -for (i =0 ; i < active_nr; i++) { -struct cache_entry *ce = active_cache[i]; -if (S_ISGITLINK (ce->ce_mode)) { -int len =ce_namelen (ce), j; -for (j =0 ; pathspec[j]; j++) { -int len2 =strlen (pathspec[j]); -if (len2 <= len || pathspec[j][len] !='/' || -memcmp (ce->name, pathspec[j], len)) -continue ; -if (len2 == len +1 ) -/* strip trailing slash */ - pathspec[j] =xstrndup (ce->name, len); -else -die (_ ("Path '%s' is in submodule '%.*s'" ), - pathspec[j], len, ce->name); - } - } - } -} -static void refresh (int verbose,const char **pathspec) {char *seen;
@@ -197,23 +170,6 @@ static void refresh(int verbose, const char **pathspec)free (seen); } -static const char **validate_pathspec (int argc,const char **argv,const char *prefix) -{ -const char **pathspec =get_pathspec (prefix, argv); - -if (pathspec) { -const char **p; -for (p = pathspec; *p; p++) { -if (has_symlink_leading_path (*p,strlen (*p))) { -int len = prefix ?strlen (prefix) :0 ; -die (_ ("'%s' is beyond a symbolic link" ), *p + len); - } - } - } - -return pathspec; -} -int run_add_interactive (const char *revision,const char *patch_mode,const char **pathspec) {
@@ -245,17 +201,20 @@ int run_add_interactive(const char *revision, const char *patch_mode,int interactive_add (int argc,const char **argv,const char *prefix,int patch) { -const char **pathspec =NULL ; +struct pathspec pathspec; -if (argc) { - pathspec =validate_pathspec (argc, argv, prefix); -if (!pathspec) -return -1 ; - } +/* +* Do not enable fancy magic here. git-add--interactive may +* not be able to handle it. +*/ +parse_pathspec (&pathspec,PATHSPEC_FROMTOP , +PATHSPEC_EMPTY_MATCH_ALL | +PATHSPEC_SYMLINK_LEADING_PATH , + prefix, argv);return run_add_interactive (NULL , patch ?"--patch" :NULL , - pathspec); + pathspec.raw); }static int edit_patch (int argc,const char **argv,const char *prefix)
@@ -367,7 +326,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) {int exit_status =0 ;int newfd; -const char **pathspec; +struct pathspec pathspec;struct dir_struct dir;int flags;int add_new_files;
@@ -415,11 +374,18 @@ int cmd_add(int argc, const char **argv, const char *prefix)fprintf (stderr,_ ("Maybe you wanted to say 'git add .'?\n" ));return 0 ; } - pathspec =validate_pathspec (argc, argv, prefix);if (read_cache () <0 )die (_ ("index file corrupt" )); -treat_gitlinks (pathspec); + +/* +* Check the "pathspec '%s' did not match any files" block +* below before enabling new magic. +*/ +parse_pathspec (&pathspec,PATHSPEC_FROMTOP , +PATHSPEC_SYMLINK_LEADING_PATH | +PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE , + prefix, argv);if (add_new_files) {int baselen;
@@ -432,33 +398,39 @@ int cmd_add(int argc, const char **argv, const char *prefix) }/* This picks up the paths that are not tracked */ - baselen =fill_directory (&dir, pathspec); -if (pathspec) - seen =prune_directory (&dir, pathspec, baselen); + baselen =fill_directory (&dir, pathspec.raw); +if (pathspec.nr) + seen =prune_directory (&dir, pathspec.raw, baselen); }if (refresh_only) { -refresh (verbose, pathspec); +refresh (verbose, pathspec.raw); goto finish; } -if (pathspec) { +if (pathspec.nr) {int i;struct path_exclude_check check;path_exclude_check_init (&check, &dir);if (!seen) - seen =find_used_pathspec (pathspec); -for (i =0 ; pathspec[i]; i++) { -if (!seen[i] && pathspec[i][0 ] - && !file_exists (pathspec[i])) { + seen =find_used_pathspec (pathspec.raw); + +/* +* file_exists() assumes exact match +*/ +GUARD_PATHSPEC (&pathspec,PATHSPEC_FROMTOP ); + +for (i =0 ; pathspec.raw[i]; i++) { +if (!seen[i] && pathspec.raw[i][0 ] + && !file_exists (pathspec.raw[i])) {if (ignore_missing) {int dtype =DT_UNKNOWN ; -if (is_path_excluded (&check, pathspec[i],-1 , &dtype)) -dir_add_ignored (&dir, pathspec[i],strlen (pathspec[i])); +if (is_path_excluded (&check, pathspec.raw[i],-1 , &dtype)) +dir_add_ignored (&dir, pathspec.raw[i],strlen (pathspec.raw[i])); }else die (_ ("pathspec '%s' did not match any files" ), - pathspec[i]); + pathspec.raw[i]); } }free (seen);
@@ -467,7 +439,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)plug_bulk_checkin (); - exit_status |=add_files_to_cache (prefix, pathspec, flags); + exit_status |=add_files_to_cache (prefix, pathspec.raw, flags);if (add_new_files) exit_status |=add_files (&dir, flags);
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 19/31 Convert read_cache_preload() to take struct pathspec
In reply to Nguyễn Thái Ngọc Duy--- builtin/checkout.c | 2 +- builtin/commit.c | 4 ++-- builtin/diff-files.c | 2 +- builtin/diff-index.c | 2 +- builtin/diff.c | 4 ++-- cache.h | 4 +++- preload-index.c | 20 +++++++++++--------- 7 files changed, 21 insertions(+), 17 deletions(-)
builtin/checkout.c +1 -1
@@ -261,7 +261,7 @@ static int checkout_paths(const struct checkout_opts *opts, lock_file =xcalloc (1 ,sizeof (struct lock_file )); newfd =hold_locked_index (lock_file,1 ); -if (read_cache_preload (opts->pathspec.raw) <0 ) +if (read_cache_preload (&opts->pathspec) <0 )return error (_ ("corrupt index file" ));if (opts->source_tree)
builtin/commit.c +2 -2
@@ -287,7 +287,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,PATHSPEC_EMPTY_MATCH_ALL , prefix, argv); -if (read_cache_preload (pathspec.raw) <0 ) +if (read_cache_preload (&pathspec) <0 )die (_ ("index file corrupt" ));if (interactive) {
@@ -1209,7 +1209,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)PATHSPEC_EMPTY_MATCH_ALL , prefix, argv); -read_cache_preload (s.pathspec.raw); +read_cache_preload (&s.pathspec);refresh_index (&the_index,REFRESH_QUIET |REFRESH_UNMERGED , s.pathspec.raw,NULL ,NULL ); fd =hold_locked_index (&index_lock,0 );
builtin/diff-files.c +1 -1
@@ -61,7 +61,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix) (rev.diffopt.output_format & DIFF_FORMAT_PATCH)) rev.combine_merges = rev.dense_combined_merges = 1; -if (read_cache_preload (rev.diffopt.pathspec.raw) <0 ) { +if (read_cache_preload (&rev.diffopt.pathspec) <0 ) {perror ("read_cache_preload" );return -1 ; }
builtin/diff-index.c +1 -1
@@ -43,7 +43,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)usage (diff_cache_usage);if (!cached) {setup_work_tree (); -if (read_cache_preload (rev.diffopt.pathspec.raw) <0 ) { +if (read_cache_preload (&rev.diffopt.pathspec) <0 ) {perror ("read_cache_preload" );return -1 ; }
builtin/diff.c +2 -2
@@ -140,7 +140,7 @@ static int builtin_diff_index(struct rev_info *revs,usage (builtin_diff_usage);if (!cached) {setup_work_tree (); -if (read_cache_preload (revs->diffopt.pathspec.raw) <0 ) { +if (read_cache_preload (&revs->diffopt.pathspec) <0 ) {perror ("read_cache_preload" );return -1 ; }
@@ -240,7 +240,7 @@ static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv revs->combine_merges = revs->dense_combined_merges =1 ;setup_work_tree (); -if (read_cache_preload (revs->diffopt.pathspec.raw) <0 ) { +if (read_cache_preload (&revs->diffopt.pathspec) <0 ) {perror ("read_cache_preload" );return -1 ; }
cache.h +3 -1
@@ -182,6 +182,8 @@ struct cache_entry {#error "CE_EXTENDED_FLAGS out of range"#endif +struct pathspec ; +/* * Copy the sha1 and stat state of a cache entry from one to * another. But we never change the name, or the hash state!
@@ -434,7 +436,7 @@ extern int init_db(const char *template_dir, unsigned int flags);/* Initialize and use the cache information */ extern int read_index (struct index_state *); -extern int read_index_preload (struct index_state *,const char **pathspec); +extern int read_index_preload (struct index_state *,const struct pathspec *pathspec);extern int read_index_from (struct index_state *,const char *path);extern int is_index_unborn (struct index_state *);extern int read_index_unmerged (struct index_state *);
preload-index.c +11 -9
@@ -4,7 +4,8 @@#include "cache.h" #ifdef NO_PTHREADS -static void preload_index (struct index_state *index,const char **pathspec) +static void preload_index (struct index_state *index, +const struct pathspec *pathspec) { ;/* nothing */ }
@@ -24,7 +25,7 @@ static void preload_index(struct index_state *index, const char **pathspec)struct thread_data {pthread_t pthread;struct index_state *index; -const char **pathspec; +struct pathspec pathspec;int offset, nr; };
@@ -35,9 +36,7 @@ static void *preload_thread(void *_data)struct index_state *index = p->index;struct cache_entry **cep = index->cache + p->offset;struct cache_def cache; -struct pathspec pathspec; -init_pathspec (&pathspec, p->pathspec);memset (&cache,0 ,sizeof (cache)); nr = p->nr;if (nr + p->offset > index->cache_nr)
@@ -53,7 +52,7 @@ static void *preload_thread(void *_data)continue ;if (ce_uptodate (ce))continue ; -if (!ce_path_match (ce, &pathspec)) +if (!ce_path_match (ce, &p->pathspec))continue ;if (threaded_has_symlink_leading_path (&cache, ce->name,ce_namelen (ce)))continue ;
@@ -63,11 +62,11 @@ static void *preload_thread(void *_data)continue ;ce_mark_uptodate (ce); }while (--nr >0 ); -free_pathspec (&pathspec);return NULL ; } -static void preload_index (struct index_state *index,const char **pathspec) +static void preload_index (struct index_state *index, +const struct pathspec *pathspec) {int threads, i, work, offset;struct thread_data data[MAX_PARALLEL ];
@@ -82,10 +81,12 @@ static void preload_index(struct index_state *index, const char **pathspec) threads =MAX_PARALLEL ; offset =0 ; work =DIV_ROUND_UP (index->cache_nr, threads); +memset (&data,0 ,sizeof (data));for (i =0 ; i < threads; i++) {struct thread_data *p = data+i; p->index = index; - p->pathspec = pathspec; +if (pathspec) +copy_pathspec (&p->pathspec, pathspec); p->offset = offset; p->nr = work; offset += work;
@@ -100,7 +101,8 @@ static void preload_index(struct index_state *index, const char **pathspec) }#endif -int read_index_preload (struct index_state *index,const char **pathspec) +int read_index_preload (struct index_state *index, +const struct pathspec *pathspec) {int retval =read_index (index);
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 20/31 Convert unmerge_cache to take struct pathspec
In reply to Nguyễn Thái Ngọc Duy--- builtin/checkout.c | 2 +- rerere.c | 2 +- resolve-undo.c | 4 ++-- resolve-undo.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
builtin/checkout.c +1 -1
@@ -281,7 +281,7 @@ static int checkout_paths(const struct checkout_opts *opts,/* "checkout -m path" to recreate conflicted state */ if (opts->merge) -unmerge_cache (opts->pathspec.raw); +unmerge_cache (&opts->pathspec);/* Any unmerged paths? */ for (pos =0 ; pos < active_nr; pos++) {
rerere.c +1 -1
@@ -666,7 +666,7 @@ int rerere_forget(struct pathspec *pathspec) fd =setup_rerere (&merge_rr,RERERE_NOAUTOUPDATE ); -unmerge_cache (pathspec->raw); +unmerge_cache (pathspec);find_conflict (&conflict);for (i =0 ; i < conflict.nr; i++) {struct string_list_item *it = &conflict.items[i];
resolve-undo.c +2 -2
@@ -156,7 +156,7 @@ int unmerge_index_entry_at(struct index_state *istate, int pos)return unmerge_index_entry_at (istate, pos); } -void unmerge_index (struct index_state *istate,const char **pathspec) +void unmerge_index (struct index_state *istate,const struct pathspec *pathspec) {int i;
@@ -165,7 +165,7 @@ void unmerge_index(struct index_state *istate, const char **pathspec)for (i =0 ; i < istate->cache_nr; i++) {struct cache_entry *ce = istate->cache[i]; -if (!match_pathspec (pathspec, ce->name,ce_namelen (ce),0 ,NULL )) +if (!match_pathspec_depth (pathspec, ce->name,ce_namelen (ce),0 ,NULL ))continue ; i =unmerge_index_entry_at (istate, i); }
resolve-undo.h +1 -1
@@ -11,6 +11,6 @@ extern void resolve_undo_write(struct strbuf *, struct string_list *);extern struct string_list *resolve_undo_read (const char *,unsigned long );extern void resolve_undo_clear_index (struct index_state *);extern int unmerge_index_entry_at (struct index_state *,int ); -extern void unmerge_index (struct index_state *,const char **); +extern void unmerge_index (struct index_state *,const struct pathspec *);#endif
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 21/31 checkout: convert read_tree_some to take struct pathspec
In reply to Nguyễn Thái Ngọc Duy--- builtin/checkout.c | 9 +++------ tree.c | 4 ++-- tree.h | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-)
builtin/checkout.c +3 -6
@@ -82,12 +82,9 @@ static int update_some(const unsigned char *sha1, const char *base, int baselen,return 0 ; } -static int read_tree_some (struct tree *tree,const char **pathspec) +static int read_tree_some (struct tree *tree,const struct pathspec *pathspec) { -struct pathspec ps; -init_pathspec (&ps, pathspec); -read_tree_recursive (tree,"" ,0 ,0 , &ps, update_some,NULL ); -free_pathspec (&ps); +read_tree_recursive (tree,"" ,0 ,0 , pathspec, update_some,NULL );/* update the index with the given tree's info * for all args, expanding wildcards, and exit
@@ -265,7 +262,7 @@ static int checkout_paths(const struct checkout_opts *opts,return error (_ ("corrupt index file" ));if (opts->source_tree) -read_tree_some (opts->source_tree, opts->pathspec.raw); +read_tree_some (opts->source_tree, &opts->pathspec); ps_matched =xcalloc (1 , opts->pathspec.nr);
tree.c +2 -2
@@ -47,7 +47,7 @@ static int read_one_entry_quick(const unsigned char *sha1, const char *base, int }static int read_tree_1 (struct tree *tree,struct strbuf *base, -int stage,struct pathspec *pathspec, +int stage,const struct pathspec *pathspec,read_tree_fn_t fn,void *context) {struct tree_desc desc;
@@ -116,7 +116,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,int read_tree_recursive (struct tree *tree,const char *base,int baselen, -int stage,struct pathspec *pathspec, +int stage,const struct pathspec *pathspec,read_tree_fn_t fn,void *context) {struct strbuf sb =STRBUF_INIT ;
tree.h +1 -1
@@ -25,7 +25,7 @@ typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const chextern int read_tree_recursive (struct tree *tree,const char *base,int baselen, -int stage,struct pathspec *pathspec, +int stage,const struct pathspec *pathspec,read_tree_fn_t fn,void *context);extern int read_tree (struct tree *tree,int stage,struct pathspec *pathspec);
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 22/31 Convert report_path_error to take struct pathspec
In reply to Nguyễn Thái Ngọc DuyThis commit fixes a subtle bug in ls-files and commit:
- when match_pathspec() returns seen[], it follows the order of the input "const char **pathspec", which is now pathspec.raw[]
- when match_pathspec() returns seen[], it follows the order of pathspec.items[]
- due to 86e4ca6 (tree_entry_interesting(): fix depth limit with overlapping pathspecs - 2010-12-15), pathspec.items[] is sorted, but pathspec.raw[] is NOT.
by converting from match_pathspec() to match_pathspec_depth(), we also have to switch the original path array. We haven't done so because there are other call sites of report_path_error() that relies on old order. We now follow pathspec.items[] order.
--- builtin/checkout.c | 2 +- builtin/commit.c | 14 ++++++-------- builtin/ls-files.c | 19 +++++++++++-------- cache.h | 2 +- 4 files changed, 19 insertions(+), 18 deletions(-)
builtin/checkout.c +1 -1
@@ -273,7 +273,7 @@ static int checkout_paths(const struct checkout_opts *opts,match_pathspec_depth (&opts->pathspec, ce->name,ce_namelen (ce),0 , ps_matched); } -if (report_path_error (ps_matched, opts->pathspec.raw, opts->prefix)) +if (report_path_error (ps_matched, &opts->pathspec, opts->prefix))return 1 ;/* "checkout -m path" to recreate conflicted state */
builtin/commit.c +6 -8
@@ -181,20 +181,18 @@ static int commit_index_files(void)* and return the paths that match the given pattern in list. */ static int list_paths (struct string_list *list,const char *with_tree, -const char *prefix,const char **pattern) +const char *prefix,const struct pathspec *pattern) {int i;char *m; -if (!pattern) +if (!pattern->nr)return 0 ; -for (i =0 ; pattern[i]; i++) - ; - m =xcalloc (1 , i); + m =xcalloc (1 , pattern->nr);if (with_tree) { -char *max_prefix =common_prefix (pattern); +char *max_prefix =common_prefix (pattern->raw);overlay_tree_on_cache (with_tree, max_prefix ? max_prefix : prefix);free (max_prefix); }
@@ -205,7 +203,7 @@ static int list_paths(struct string_list *list, const char *with_tree,if (ce->ce_flags &CE_UPDATE )continue ; -if (!match_pathspec (pattern, ce->name,ce_namelen (ce),0 , m)) +if (!match_pathspec_depth (pattern, ce->name,ce_namelen (ce),0 , m))continue ; item =string_list_insert (list, ce->name);if (ce_skip_worktree (ce))
@@ -395,7 +393,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,memset (&partial,0 ,sizeof (partial)); partial.strdup_strings =1 ; -if (list_paths (&partial, !current_head ?NULL :"HEAD" , prefix, pathspec.raw)) +if (list_paths (&partial, !current_head ?NULL :"HEAD" , prefix, &pathspec))exit (1 );discard_cache ();
builtin/ls-files.c +11 -8
@@ -349,15 +349,16 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix) } } -int report_path_error (const char *ps_matched,const char **pathspec,const char *prefix) +int report_path_error (const char *ps_matched, +const struct pathspec *pathspec, +const char *prefix) {/* * Make sure all pathspec matched; otherwise it is an error. */ struct strbuf sb =STRBUF_INIT ; -const char *name;int num, errors =0 ; -for (num =0 ; pathspec[num]; num++) { +for (num =0 ; num < pathspec->nr; num++) {int other, found_dup;if (ps_matched[num])
@@ -365,13 +366,16 @@ int report_path_error(const char *ps_matched, const char **pathspec, const char/* * The caller might have fed identical pathspec * twice. Do not barf on such a mistake. +* FIXME: parse_pathspec should have eliminated +* duplicate pathspec. */ for (found_dup = other =0 ; - !found_dup && pathspec[other]; + !found_dup && other < pathspec->nr; other++) {if (other == num || !ps_matched[other])continue ; -if (!strcmp (pathspec[other], pathspec[num])) +if (!strcmp (pathspec->items[other].original, + pathspec->items[num].original))/* * Ok, we have a match already. */
@@ -380,9 +384,8 @@ int report_path_error(const char *ps_matched, const char **pathspec, const charif (found_dup)continue ; - name =quote_path_relative (pathspec[num],-1 , &sb, prefix);error ("pathspec '%s' did not match any file(s) known to git." , - name); + pathspec->items[num].original); errors++; }strbuf_release (&sb);
@@ -571,7 +574,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)if (ps_matched) {int bad; - bad =report_path_error (ps_matched, pathspec.raw, prefix); + bad =report_path_error (ps_matched, &pathspec, prefix);if (bad)fprintf (stderr,"Did you forget to 'git add'?\n" );
cache.h +1 -1
@@ -1289,7 +1289,7 @@ extern int ws_blank_line(const char *line, int len, unsigned ws_rule);#define ws_tab_width (rule) ((rule) & WS_TAB_WIDTH_MASK)/* ls-files */ -int report_path_error (const char *ps_matched,const char **pathspec,const char *prefix); +int report_path_error (const char *ps_matched,const struct pathspec *pathspec,const char *prefix);void overlay_tree_on_cache (const char *tree_name,const char *prefix);char *alias_lookup (const char *alias);
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 23/31 Convert refresh_index to take struct pathspec
In reply to Nguyễn Thái Ngọc Duy--- builtin/add.c | 15 +++++++-------- builtin/commit.c | 2 +- builtin/rm.c | 2 +- cache.h | 2 +- read-cache.c | 5 +++-- 5 files changed, 13 insertions(+), 13 deletions(-)
builtin/add.c +7 -8
@@ -153,19 +153,18 @@ static char *prune_directory(struct dir_struct *dir, const char **pathspec, intreturn seen; } -static void refresh (int verbose,const char **pathspec) +static void refresh (int verbose,const struct pathspec *pathspec) {char *seen; -int i, specs; +int i; -for (specs =0 ; pathspec[specs]; specs++) -/* nothing */ ; - seen =xcalloc (specs,1 ); + seen =xcalloc (pathspec->nr,1 );refresh_index (&the_index, verbose ?REFRESH_IN_PORCELAIN :REFRESH_QUIET , pathspec, seen,_ ("Unstaged changes after refreshing the index:" )); -for (i =0 ; i < specs; i++) { +for (i =0 ; i < pathspec->nr; i++) {if (!seen[i]) -die (_ ("pathspec '%s' did not match any files" ), pathspec[i]); +die (_ ("pathspec '%s' did not match any files" ), + pathspec->items[i].match); }free (seen); }
@@ -404,7 +403,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) }if (refresh_only) { -refresh (verbose, pathspec.raw); +refresh (verbose, &pathspec); goto finish; }
builtin/commit.c +1 -1
@@ -1208,7 +1208,7 @@ int cmd_status(int argc, const char **argv, const char *prefix) prefix, argv);read_cache_preload (&s.pathspec); -refresh_index (&the_index,REFRESH_QUIET |REFRESH_UNMERGED , s.pathspec.raw,NULL ,NULL ); +refresh_index (&the_index,REFRESH_QUIET |REFRESH_UNMERGED , &s.pathspec,NULL ,NULL ); fd =hold_locked_index (&index_lock,0 );if (0 <= fd)
builtin/rm.c +1 -1
@@ -250,7 +250,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix) }parse_pathspec (&pathspec,PATHSPEC_FROMTOP ,0 , prefix, argv); -refresh_index (&the_index,REFRESH_QUIET , pathspec.raw,NULL ,NULL ); +refresh_index (&the_index,REFRESH_QUIET , &pathspec,NULL ,NULL ); seen =NULL ; seen =xcalloc (pathspec.nr,1 );
cache.h +1 -1
@@ -533,7 +533,7 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);#define REFRESH_IGNORE_MISSING 0x0008/* ignore non-existent */ #define REFRESH_IGNORE_SUBMODULES 0x0010/* ignore submodules */ #define REFRESH_IN_PORCELAIN 0x0020/* user friendly output, not "needs update" */ -extern int refresh_index (struct index_state *,unsigned int flags,const char **pathspec,char *seen,const char *header_msg); +extern int refresh_index (struct index_state *,unsigned int flags,const struct pathspec *pathspec,char *seen,const char *header_msg);struct lock_file {struct lock_file *next;
read-cache.c +3 -2
@@ -1093,7 +1093,8 @@ static void show_file(const char * fmt, const char * name, int in_porcelain,printf (fmt, name); } -int refresh_index (struct index_state *istate,unsigned int flags,const char **pathspec, +int refresh_index (struct index_state *istate,unsigned int flags, +const struct pathspec *pathspec,char *seen,const char *header_msg) {int i;
@@ -1128,7 +1129,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **pcontinue ;if (pathspec && - !match_pathspec (pathspec, ce->name,ce_namelen (ce),0 , seen)) + !match_pathspec_depth (pathspec, ce->name,ce_namelen (ce),0 , seen)) filtered =1 ;if (ce_stage (ce)) {
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 24/31 Convert {read,fill}_directory to take struct pathspec
In reply to Nguyễn Thái Ngọc Duy--- builtin/add.c | 2 +- builtin/clean.c | 2 +- builtin/grep.c | 2 +- builtin/ls-files.c | 2 +- dir.c | 16 +++++++++++----- dir.h | 4 ++-- wt-status.c | 4 ++-- 7 files changed, 19 insertions(+), 13 deletions(-)
builtin/add.c +1 -1
@@ -397,7 +397,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) }/* This picks up the paths that are not tracked */ - baselen =fill_directory (&dir, pathspec.raw); + baselen =fill_directory (&dir, &pathspec);if (pathspec.nr) seen =prune_directory (&dir, pathspec.raw, baselen); }
builtin/clean.c +1 -1
@@ -102,7 +102,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)parse_pathspec (&pathspec,PATHSPEC_FROMTOP ,0 , prefix, argv); -fill_directory (&dir, pathspec.raw); +fill_directory (&dir, &pathspec);for (i =0 ; i < dir.nr; i++) {struct dir_entry *ent = dir.entries[i];
builtin/grep.c +1 -1
@@ -522,7 +522,7 @@ static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec,if (exc_std)setup_standard_excludes (&dir); -fill_directory (&dir, pathspec->raw); +fill_directory (&dir, pathspec);for (i =0 ; i < dir.nr; i++) {const char *name = dir.entries[i]->name;int namelen =strlen (name);
builtin/ls-files.c +1 -1
@@ -216,7 +216,7 @@ static void show_files(struct dir_struct *dir)/* For cached/deleted files we don't need to even do the readdir */ if (show_others || show_killed) { -fill_directory (dir, pathspec.raw); +fill_directory (dir, &pathspec);if (show_others)show_other_files (dir);if (show_killed)
dir.c +11 -5
@@ -98,7 +98,7 @@ char *common_prefix(const char **pathspec)return len ?xmemdupz (*pathspec, len) :NULL ; } -int fill_directory (struct dir_struct *dir,const char **pathspec) +int fill_directory (struct dir_struct *dir,const struct pathspec *pathspec) {size_t len;
@@ -106,10 +106,10 @@ int fill_directory(struct dir_struct *dir, const char **pathspec)* Calculate common prefix for the pathspec, and * use that to optimize the directory walk */ - len =common_prefix_len (pathspec); + len =common_prefix_len (pathspec->raw);/* Read the directory and prune it */ -read_directory (dir, pathspec ? *pathspec :"" , len, pathspec); +read_directory (dir, pathspec->nr ? pathspec->raw[0 ] :"" , len, pathspec);return len; }
@@ -1323,14 +1323,20 @@ static int treat_leading_path(struct dir_struct *dir,return rc; } -int read_directory (struct dir_struct *dir,const char *path,int len,const char **pathspec) +int read_directory (struct dir_struct *dir,const char *path,int len,const struct pathspec *pathspec) {struct path_simplify *simplify; +/* +* Check out create_simplify() +*/ +if (pathspec) +GUARD_PATHSPEC (pathspec,PATHSPEC_FROMTOP ); +if (has_symlink_leading_path (path, len))return dir->nr; - simplify =create_simplify (pathspec); + simplify =create_simplify (pathspec ? pathspec->raw :NULL );if (!len ||treat_leading_path (dir, path, len, simplify))read_directory_recursive (dir, path, len,0 , simplify);free_simplify (simplify);
dir.h +2 -2
@@ -97,8 +97,8 @@ extern int match_pathspec_depth(const struct pathspec *pathspec, int prefix, char *seen);extern int within_depth (const char *name,int namelen,int depth,int max_depth); -extern int fill_directory (struct dir_struct *dir,const char **pathspec); -extern int read_directory (struct dir_struct *,const char *path,int len,const char **pathspec); +extern int fill_directory (struct dir_struct *dir,const struct pathspec *pathspec); +extern int read_directory (struct dir_struct *,const char *path,int len,const struct pathspec *pathspec);extern int is_excluded_from_list (const char *pathname,int pathlen,const char *basename,int *dtype,struct exclude_list *el);
wt-status.c +2 -2
@@ -502,7 +502,7 @@ static void wt_status_collect_untracked(struct wt_status *s)DIR_SHOW_OTHER_DIRECTORIES |DIR_HIDE_EMPTY_DIRECTORIES ;setup_standard_excludes (&dir); -fill_directory (&dir, s->pathspec.raw); +fill_directory (&dir, &s->pathspec);for (i =0 ; i < dir.nr; i++) {struct dir_entry *ent = dir.entries[i]; if (cache_name_is_other(ent->name, ent->len) &&
@@ -514,7 +514,7 @@ static void wt_status_collect_untracked(struct wt_status *s)if (s->show_ignored_files) { dir.nr =0 ; dir.flags =DIR_SHOW_IGNORED |DIR_SHOW_OTHER_DIRECTORIES ; -fill_directory (&dir, s->pathspec.raw); +fill_directory (&dir, &s->pathspec);for (i =0 ; i < dir.nr; i++) {struct dir_entry *ent = dir.entries[i]; if (cache_name_is_other(ent->name, ent->len) &&
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 25/31 Convert add_files_to_cache to take struct pathspec
In reply to Nguyễn Thái Ngọc Duy--- builtin/add.c | 8 +++++--- builtin/commit.c | 2 +- cache.h | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-)
builtin/add.c +5 -3
@@ -80,13 +80,15 @@ static void update_callback(struct diff_queue_struct *q, } } -int add_files_to_cache (const char *prefix,const char **pathspec,int flags) +int add_files_to_cache (const char *prefix, +const struct pathspec *pathspec,int flags) {struct update_callback_data data;struct rev_info rev;init_revisions (&rev, prefix);setup_revisions (0 ,NULL , &rev,NULL ); -init_pathspec (&rev.prune_data, pathspec); +if (pathspec) +copy_pathspec (&rev.prune_data, pathspec); rev.diffopt.output_format =DIFF_FORMAT_CALLBACK ; rev.diffopt.format_callback = update_callback; data.flags = flags;
@@ -438,7 +440,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)plug_bulk_checkin (); - exit_status |=add_files_to_cache (prefix, pathspec.raw, flags); + exit_status |=add_files_to_cache (prefix, &pathspec, flags);if (add_new_files) exit_status |=add_files (&dir, flags);
builtin/commit.c +1 -1
@@ -329,7 +329,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,*/ if (all || (also && pathspec.nr)) { fd =hold_locked_index (&index_lock,1 ); -add_files_to_cache (also ? prefix :NULL , pathspec.raw,0 ); +add_files_to_cache (also ? prefix :NULL , &pathspec,0 );refresh_cache_or_die (refresh_flags);update_main_cache_tree (WRITE_TREE_SILENT ); if (write_cache(fd, active_cache, active_nr) ||
cache.h +1 -1
@@ -1255,7 +1255,7 @@ void packet_trace_identity(const char *prog);* return 0 if success, 1 - if addition of a file failed and * ADD_FILES_IGNORE_ERRORS was specified in flags */ -int add_files_to_cache (const char *prefix,const char **pathspec,int flags); +int add_files_to_cache (const char *prefix,const struct pathspec *pathspec,int flags);/* diff.c */ extern int diff_auto_refresh_index;
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 26/31 Convert common_prefix() to use struct pathspec
In reply to Nguyễn Thái Ngọc DuyThe code now takes advantage of nowildcard_len field.
--- builtin/commit.c | 2 +- builtin/ls-files.c | 2 +- dir.c | 31 +++++++++++++++---------------- dir.h | 2 +- 4 files changed, 18 insertions(+), 19 deletions(-)
builtin/commit.c +1 -1
@@ -192,7 +192,7 @@ static int list_paths(struct string_list *list, const char *with_tree, m =xcalloc (1 , pattern->nr);if (with_tree) { -char *max_prefix =common_prefix (pattern->raw); +char *max_prefix =common_prefix (pattern);overlay_tree_on_cache (with_tree, max_prefix ? max_prefix : prefix);free (max_prefix); }
builtin/ls-files.c +1 -1
@@ -542,7 +542,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) prefix, argv);/* Find common prefix for all pathspec's */ - max_prefix =common_prefix (pathspec.raw); + max_prefix =common_prefix (&pathspec); max_prefix_len = max_prefix ?strlen (max_prefix) :0 ;/* Treat unmatching pathspec elements as errors */
dir.c +15 -16
@@ -59,26 +59,25 @@ inline int git_fnmatch(const char *pattern, const char *string,return fnmatch (pattern, string, fnm_flags); } -static size_t common_prefix_len (const char **pathspec) +static size_t common_prefix_len (const struct pathspec *pathspec) { -const char *n, *first; +int n;size_t max =0 ; -int literal =limit_pathspec_to_literal (); -if (!pathspec) -return max; - - first = *pathspec; -while ((n = *pathspec++)) { -size_t i, len =0 ; -for (i =0 ; first == n || i < max; i++) { -char c = n[i]; -if (!c || c != first[i] || (!literal &&is_glob_special (c))) +GUARD_PATHSPEC (pathspec,PATHSPEC_FROMTOP ); + +for (n =0 ; n < pathspec->nr; n++) { +size_t i =0 , len =0 ; +while (i < pathspec->items[n].nowildcard_len && + (n ==0 || i < max)) { +char c = pathspec->items[n].match[i]; +if (c != pathspec->items[0 ].match[i])break ;if (c =='/' ) len = i +1 ; + i++; } -if (first == n || len < max) { +if (n ==0 || len < max) { max = len;if (!max)break ;
@@ -91,11 +90,11 @@ static size_t common_prefix_len(const char **pathspec)* Returns a copy of the longest leading path common among all * pathspecs. */ -char *common_prefix (const char **pathspec) +char *common_prefix (const struct pathspec *pathspec) {unsigned long len =common_prefix_len (pathspec); -return len ?xmemdupz (*pathspec, len) :NULL ; +return len ?xmemdupz (pathspec->items[0 ].match, len) :NULL ; }int fill_directory (struct dir_struct *dir,const struct pathspec *pathspec)
@@ -106,7 +105,7 @@ int fill_directory(struct dir_struct *dir, const struct pathspec *pathspec)* Calculate common prefix for the pathspec, and * use that to optimize the directory walk */ - len =common_prefix_len (pathspec->raw); + len =common_prefix_len (pathspec);/* Read the directory and prune it */ read_directory (dir, pathspec->nr ? pathspec->raw[0 ] :"" , len, pathspec);
dir.h +1 -1
@@ -90,7 +90,7 @@ struct dir_struct {#define MATCHED_EXACTLY 3extern int simple_length (const char *match);extern int no_wildcard (const char *string); -extern char *common_prefix (const char **pathspec); +extern char *common_prefix (const struct pathspec *pathspec);extern int match_pathspec (const char **pathspec,const char *name,int namelen,int prefix,char *seen); extern int match_pathspec_depth(const struct pathspec *pathspec, const char *name, int namelen,
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 27/31 Remove diff_tree_{setup,release}_paths
In reply to Nguyễn Thái Ngọc Duy--- builtin/blame.c | 12 ++++++------ builtin/reset.c | 4 ++-- diff.h | 2 -- notes-merge.c | 4 ++-- revision.c | 5 +++-- tree-diff.c | 18 ++++-------------- 6 files changed, 17 insertions(+), 28 deletions(-)
builtin/blame.c +6 -6
@@ -406,7 +406,7 @@ static struct origin *find_origin(struct scoreboard *sb, paths[0 ] = origin->path; paths[1 ] =NULL ; -diff_tree_setup_paths (paths, &diff_opts); +init_pathspec (&diff_opts.pathspec, paths);diff_setup_done (&diff_opts);if (is_null_sha1 (origin->commit->object.sha1))
@@ -456,7 +456,7 @@ static struct origin *find_origin(struct scoreboard *sb, } }diff_flush (&diff_opts); -diff_tree_release_paths (&diff_opts); +free_pathspec (&diff_opts.pathspec);if (porigin) {/* * Create a freestanding copy that is not part of
@@ -492,7 +492,7 @@ static struct origin *find_rename(struct scoreboard *sb, diff_opts.output_format =DIFF_FORMAT_NO_OUTPUT ; diff_opts.single_follow = origin->path; paths[0 ] =NULL ; -diff_tree_setup_paths (paths, &diff_opts); +init_pathspec (&diff_opts.pathspec, paths);diff_setup_done (&diff_opts);if (is_null_sha1 (origin->commit->object.sha1))
@@ -514,7 +514,7 @@ static struct origin *find_rename(struct scoreboard *sb, } }diff_flush (&diff_opts); -diff_tree_release_paths (&diff_opts); +free_pathspec (&diff_opts.pathspec);return porigin; }
@@ -1072,7 +1072,7 @@ static int find_copy_in_parent(struct scoreboard *sb, diff_opts.output_format =DIFF_FORMAT_NO_OUTPUT ; paths[0 ] =NULL ; -diff_tree_setup_paths (paths, &diff_opts); +init_pathspec (&diff_opts.pathspec, paths);diff_setup_done (&diff_opts);/* Try "find copies harder" on new path if requested;
@@ -1155,7 +1155,7 @@ static int find_copy_in_parent(struct scoreboard *sb, }reset_scanned_flag (sb);diff_flush (&diff_opts); -diff_tree_release_paths (&diff_opts); +free_pathspec (&diff_opts.pathspec);return retval; }
builtin/reset.c +2 -2
@@ -183,7 +183,7 @@ static int read_from_tree(const char *prefix, const char **argv,struct diff_options opt;memset (&opt,0 ,sizeof (opt)); -diff_tree_setup_paths (get_pathspec (prefix, (const char **)argv), &opt); +parse_pathspec (&opt.pathspec,PATHSPEC_FROMTOP ,0 , prefix, argv); opt.output_format =DIFF_FORMAT_CALLBACK ; opt.format_callback = update_index_from_diff; opt.format_callback_data = &index_was_discarded;
@@ -195,7 +195,7 @@ static int read_from_tree(const char *prefix, const char **argv,return 1 ;diffcore_std (&opt);diff_flush (&opt); -diff_tree_release_paths (&opt); +free_pathspec (&opt.pathspec);if (!index_was_discarded)/* The index is still clobbered from do_diff_cache() */
diff.h +0 -2
@@ -176,8 +176,6 @@ const char *diff_get_color(int diff_use_color, enum color_diff ix);extern const char mime_boundary_leader[]; -extern void diff_tree_setup_paths (const char **paths,struct diff_options *); -extern void diff_tree_release_paths (struct diff_options *);extern int diff_tree (struct tree_desc *t1,struct tree_desc *t2,const char *base,struct diff_options *opt); extern int diff_tree_sha1(const unsigned char *old, const unsigned char *new,
notes-merge.c +2 -2
@@ -169,7 +169,7 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o, sha1_to_hex(mp->remote)); }diff_flush (&opt); -diff_tree_release_paths (&opt); +free_pathspec (&opt.pathspec); *num_changes = len;return changes;
@@ -255,7 +255,7 @@ static void diff_tree_local(struct notes_merge_options *o, sha1_to_hex(mp->local)); }diff_flush (&opt); -diff_tree_release_paths (&opt); +free_pathspec (&opt.pathspec); }static void check_notes_merge_worktree (struct notes_merge_options *o)
revision.c +3 -2
@@ -1885,12 +1885,13 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s revs->limited =1 ;if (revs->prune_data.nr) { -diff_tree_setup_paths (revs->prune_data.raw, &revs->pruning); +copy_pathspec (&revs->pruning.pathspec, &revs->prune_data);/* Can't prune commits with rename following: the paths change.. */ if (!DIFF_OPT_TST (&revs->diffopt,FOLLOW_RENAMES )) revs->prune =1 ;if (!revs->full_diff) -diff_tree_setup_paths (revs->prune_data.raw, &revs->diffopt); +copy_pathspec (&revs->diffopt.pathspec, + &revs->prune_data); }if (revs->combine_merges) revs->ignore_merges =0 ;
tree-diff.c +4 -14
@@ -230,11 +230,11 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co diff_opts.break_opt = opt->break_opt; diff_opts.rename_score = opt->rename_score; paths[0 ] =NULL ; -diff_tree_setup_paths (paths, &diff_opts); +init_pathspec (&diff_opts.pathspec, paths);diff_setup_done (&diff_opts);diff_tree (t1, t2, base, &diff_opts);diffcore_std (&diff_opts); -diff_tree_release_paths (&diff_opts); +free_pathspec (&diff_opts.pathspec);/* Go through the new set of filepairing, and see if we find a more interesting one */ opt->found_follow =0 ;
@@ -253,9 +253,9 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co choice = p;/* Update the path we use from now on.. */ -diff_tree_release_paths (opt); +free_pathspec (&opt->pathspec); opt->pathspec.raw[0 ] =xstrdup (p->one->path); -diff_tree_setup_paths (opt->pathspec.raw, opt); +init_pathspec (&opt->pathspec, opt->pathspec.raw);/* * The caller expects us to return a set of vanilla
@@ -329,13 +329,3 @@ int diff_root_tree_sha1(const unsigned char *new, const char *base, struct diff_free (tree);return retval; } - -void diff_tree_release_paths (struct diff_options *opt) -{ -free_pathspec (&opt->pathspec); -} - -void diff_tree_setup_paths (const char **p,struct diff_options *opt) -{ -init_pathspec (&opt->pathspec, p); -}
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 28/31 Remove init_pathspec() in favor of parse_pathspec()
In reply to Nguyễn Thái Ngọc Duy--- archive.c | 2 +- builtin/blame.c | 6 +++--- builtin/log.c | 2 +- builtin/ls-files.c | 10 ++++------ cache.h | 1 - diff-lib.c | 2 +- dir.c | 52 ---------------------------------------------------- merge-recursive.c | 2 +- revision.c | 2 +- tree-diff.c | 10 +++++----- 10 files changed, 17 insertions(+), 72 deletions(-)
archive.c +1 -1
@@ -219,7 +219,7 @@ static int path_exists(struct tree *tree, const char *path)struct pathspec pathspec;int ret; -init_pathspec (&pathspec, paths); +parse_pathspec (&pathspec,0 ,0 ,"" , paths); ret =read_tree_recursive (tree,"" ,0 ,0 , &pathspec, reject_entry,NULL );free_pathspec (&pathspec);return ret !=0 ;
builtin/blame.c +3 -3
@@ -406,7 +406,7 @@ static struct origin *find_origin(struct scoreboard *sb, paths[0 ] = origin->path; paths[1 ] =NULL ; -init_pathspec (&diff_opts.pathspec, paths); +parse_pathspec (&diff_opts.pathspec,0 ,0 ,"" , paths);diff_setup_done (&diff_opts);if (is_null_sha1 (origin->commit->object.sha1))
@@ -492,7 +492,7 @@ static struct origin *find_rename(struct scoreboard *sb, diff_opts.output_format =DIFF_FORMAT_NO_OUTPUT ; diff_opts.single_follow = origin->path; paths[0 ] =NULL ; -init_pathspec (&diff_opts.pathspec, paths); +parse_pathspec (&diff_opts.pathspec,0 ,0 ,"" , paths);diff_setup_done (&diff_opts);if (is_null_sha1 (origin->commit->object.sha1))
@@ -1072,7 +1072,7 @@ static int find_copy_in_parent(struct scoreboard *sb, diff_opts.output_format =DIFF_FORMAT_NO_OUTPUT ; paths[0 ] =NULL ; -init_pathspec (&diff_opts.pathspec, paths); +parse_pathspec (&diff_opts.pathspec,0 ,0 ,"" , paths);diff_setup_done (&diff_opts);/* Try "find copies harder" on new path if requested;
builtin/log.c +1 -1
@@ -455,7 +455,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)init_grep_defaults ();git_config (git_log_config,NULL ); -init_pathspec (&match_all,NULL ); +memset (&match_all,0 ,sizeof (match_all));init_revisions (&rev, prefix); rev.diff =1 ; rev.always_show_header =1 ;
builtin/ls-files.c +4 -6
@@ -318,13 +318,11 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix) }if (prefix) { -static const char *(matchbuf[2 ]); - matchbuf[0 ] = prefix; - matchbuf[1 ] =NULL ; -init_pathspec (&pathspec, matchbuf); - pathspec.items[0 ].nowildcard_len = pathspec.items[0 ].len; +static const char *(matchbuf[1 ]); + matchbuf[0 ] =NULL ; +parse_pathspec (&pathspec,0 ,0 , prefix, matchbuf); }else -init_pathspec (&pathspec,NULL ); +memset (&pathspec,0 ,sizeof (pathspec));if (read_tree (tree,1 , &pathspec))die ("unable to read tree entries %s" , tree_name);
cache.h +0 -1
@@ -511,7 +511,6 @@ struct pathspec {#define PATHSPEC_SYMLINK_LEADING_PATH (1<<2)/* has_symlink_leading_path */ #define PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE (1<<3) -extern int init_pathspec (struct pathspec *,const char **);extern void parse_pathspec (struct pathspec *pathspec,unsigned magic_mask,unsigned flags,const char *prefix,const char **args);
diff-lib.c +1 -1
@@ -500,7 +500,7 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)struct rev_info revs;init_revisions (&revs,NULL ); -init_pathspec (&revs.prune_data, opt->pathspec.raw); +copy_pathspec (&revs.prune_data, &opt->pathspec); revs.diffopt = *opt;if (diff_cache (&revs, tree_sha1,NULL ,1 ))
dir.c +0 -52
58 lines not on this page · raw message
merge-recursive.c +1 -1
@@ -297,7 +297,7 @@ static int get_files_dirs(struct merge_options *o, struct tree *tree) {int n;struct pathspec match_all; -init_pathspec (&match_all,NULL ); +memset (&match_all,0 ,sizeof (match_all));if (read_tree_recursive (tree,"" ,0 ,0 , &match_all, save_files_dirs, o))return 0 ; n = o->current_file_set.nr + o->current_directory_set.nr;
revision.c +1 -1
@@ -1112,7 +1112,7 @@ static void prepare_show_merge(struct rev_info *revs) i++; }free_pathspec (&revs->prune_data); -init_pathspec (&revs->prune_data, prune); +parse_pathspec (&revs->prune_data,0 ,0 ,"" , prune); revs->limited =1 ; }
tree-diff.c +5 -5
@@ -196,7 +196,6 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, costruct diff_options diff_opts;struct diff_queue_struct *q = &diff_queued_diff;struct diff_filepair *choice; -const char *paths[1 ];int i;/*
@@ -229,8 +228,6 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co diff_opts.single_follow = opt->pathspec.raw[0 ]; diff_opts.break_opt = opt->break_opt; diff_opts.rename_score = opt->rename_score; - paths[0 ] =NULL ; -init_pathspec (&diff_opts.pathspec, paths);diff_setup_done (&diff_opts);diff_tree (t1, t2, base, &diff_opts);diffcore_std (&diff_opts);
@@ -248,14 +245,17 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co*/ if ((p->status =='R' || p->status =='C' ) && !strcmp (p->two->path, opt->pathspec.raw[0 ])) { +const char *path[2 ]; +/* Switch the file-pairs around */ q->queue[i] = choice; choice = p;/* Update the path we use from now on.. */ + path[0 ] = p->one->path; + path[1 ] =NULL ;free_pathspec (&opt->pathspec); - opt->pathspec.raw[0 ] =xstrdup (p->one->path); -init_pathspec (&opt->pathspec, opt->pathspec.raw); +parse_pathspec (&opt->pathspec,0 ,0 ,"" , path);/* * The caller expects us to return a set of vanilla
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 29/31 Remove match_pathspec() in favor of match_pathspec_depth()
In reply to Nguyễn Thái Ngọc Duy--- builtin/add.c | 46 ++++++++++++--------------- dir.c | 100 ---------------------------------------------------------- dir.h | 1 - 3 files changed, 20 insertions(+), 127 deletions(-)
builtin/add.c +20 -26
@@ -99,7 +99,7 @@ int add_files_to_cache(const char *prefix,return !!data.add_errors; } -static void fill_pathspec_matches (const char **pathspec,char *seen,int specs) +static void fill_pathspec_matches (struct pathspec *pathspec,char *seen) {int num_unmatched =0 , i;
@@ -109,49 +109,43 @@ static void fill_pathspec_matches(const char **pathspec, char *seen, int specs)* mistakenly think that the user gave a pathspec that did not match * anything. */ -for (i =0 ; i < specs; i++) +for (i =0 ; i < pathspec->nr; i++)if (!seen[i]) num_unmatched++;if (!num_unmatched)return ;for (i =0 ; i < active_nr; i++) {struct cache_entry *ce = active_cache[i]; -match_pathspec (pathspec, ce->name,ce_namelen (ce),0 , seen); +match_pathspec_depth (pathspec, ce->name,ce_namelen (ce),0 , seen); } } -static char *find_used_pathspec (const char **pathspec) +static char *find_used_pathspec (struct pathspec *pathspec) {char *seen; -int i; - -for (i =0 ; pathspec[i]; i++) - ;/* just counting */ - seen =xcalloc (i,1 ); -fill_pathspec_matches (pathspec, seen, i); + seen =xcalloc (pathspec->nr,1 ); +fill_pathspec_matches (pathspec, seen);return seen; } -static char *prune_directory (struct dir_struct *dir,const char **pathspec,int prefix) +static char *prune_directory (struct dir_struct *dir,struct pathspec *pathspec,int prefix) {char *seen; -int i, specs; +int i;struct dir_entry **src, **dst; -for (specs =0 ; pathspec[specs]; specs++) -/* nothing */ ; - seen =xcalloc (specs,1 ); + seen =xcalloc (pathspec->nr,1 ); src = dst = dir->entries; i = dir->nr;while (--i >=0 ) {struct dir_entry *entry = *src++; -if (match_pathspec (pathspec, entry->name, entry->len, - prefix, seen)) +if (match_pathspec_depth (pathspec, entry->name, entry->len, + prefix, seen)) *dst++ = entry; } dir->nr = dst - dir->entries; -fill_pathspec_matches (pathspec, seen, specs); +fill_pathspec_matches (pathspec, seen);return seen; }
@@ -401,7 +395,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)/* This picks up the paths that are not tracked */ baselen =fill_directory (&dir, &pathspec);if (pathspec.nr) - seen =prune_directory (&dir, pathspec.raw, baselen); + seen =prune_directory (&dir, &pathspec, baselen); }if (refresh_only) {
@@ -415,23 +409,23 @@ int cmd_add(int argc, const char **argv, const char *prefix)path_exclude_check_init (&check, &dir);if (!seen) - seen =find_used_pathspec (pathspec.raw); + seen =find_used_pathspec (&pathspec);/* * file_exists() assumes exact match */ GUARD_PATHSPEC (&pathspec,PATHSPEC_FROMTOP ); -for (i =0 ; pathspec.raw[i]; i++) { -if (!seen[i] && pathspec.raw[i][0 ] - && !file_exists (pathspec.raw[i])) { +for (i =0 ; i < pathspec.nr; i++) { +const char *path = pathspec.items[i].match; +if (!seen[i] && !file_exists (path)) {if (ignore_missing) {int dtype =DT_UNKNOWN ; -if (is_path_excluded (&check, pathspec.raw[i],-1 , &dtype)) -dir_add_ignored (&dir, pathspec.raw[i],strlen (pathspec.raw[i])); +if (is_path_excluded (&check, path,-1 , &dtype)) +dir_add_ignored (&dir, path, pathspec.items[i].len); }else die (_ ("pathspec '%s' did not match any files" ), - pathspec.raw[i]); + pathspec.items[i].original); } }free (seen);
dir.c +0 -100
106 lines not on this page · raw message
dir.h +0 -1
@@ -91,7 +91,6 @@ struct dir_struct {extern int simple_length (const char *match);extern int no_wildcard (const char *string);extern char *common_prefix (const struct pathspec *pathspec); -extern int match_pathspec (const char **pathspec,const char *name,int namelen,int prefix,char *seen);extern int match_pathspec_depth (const struct pathspec *pathspec,const char *name,int namelen,int prefix,char *seen);
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 30/31 tree-diff: remove the use of pathspec's raw[] in follow-rename codepath
In reply to Nguyễn Thái Ngọc DuyPut a checkpoint to guard unsupported pathspec features in future.
--- tree-diff.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tree-diff.c +2 -2
@@ -225,7 +225,7 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, coDIFF_OPT_SET (&diff_opts,RECURSIVE );DIFF_OPT_SET (&diff_opts,FIND_COPIES_HARDER ); diff_opts.output_format =DIFF_FORMAT_NO_OUTPUT ; - diff_opts.single_follow = opt->pathspec.raw[0 ]; + diff_opts.single_follow = opt->pathspec.items[0 ].match; diff_opts.break_opt = opt->break_opt; diff_opts.rename_score = opt->rename_score;diff_setup_done (&diff_opts);
@@ -244,7 +244,7 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co* the future! */ if ((p->status =='R' || p->status =='C' ) && - !strcmp (p->two->path, opt->pathspec.raw[0 ])) { + !strcmp (p->two->path, opt->pathspec.items[0 ].match)) {const char *path[2 ];/* Switch the file-pairs around */
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH v3 31/31 Rename field "raw" to "_raw" in struct pathspec
In reply to Nguyễn Thái Ngọc DuyThis patch is essentially no-op. It helps catching new use of this field though. This field is introduced as an intermediate step for the pathspec conversion and will be removed eventually. At this stage no more access sites should be introduced.
--- archive.c | 2 +- builtin/add.c | 2 +- builtin/checkout.c | 2 +- builtin/ls-tree.c | 2 +- cache.h | 2 +- dir.c | 4 ++-- setup.c | 6 +++--- 7 files changed, 10 insertions(+), 10 deletions(-)
archive.c +1 -1
@@ -236,7 +236,7 @@ static void parse_pathspec_arg(const char **pathspec,*/ parse_pathspec (&ar_args->pathspec,PATHSPEC_FROMTOP ,0 ,"" , pathspec);if (ar_args->pathspec.nr) { - pathspec = ar_args->pathspec.raw; + pathspec = ar_args->pathspec._raw;while (*pathspec) {if (!path_exists (ar_args->tree, *pathspec))die ("path not found: %s" , *pathspec);
builtin/add.c +1 -1
@@ -209,7 +209,7 @@ int interactive_add(int argc, const char **argv, const char *prefix, int patch)return run_add_interactive (NULL , patch ?"--patch" :NULL , - pathspec.raw); + pathspec._raw); }static int edit_patch (int argc,const char **argv,const char *prefix)
builtin/checkout.c +1 -1
@@ -253,7 +253,7 @@ static int checkout_paths(const struct checkout_opts *opts,if (opts->patch_mode)return run_add_interactive (revision,"--patch=checkout" , - opts->pathspec.raw); + opts->pathspec._raw); lock_file =xcalloc (1 ,sizeof (struct lock_file ));
builtin/ls-tree.c +1 -1
@@ -35,7 +35,7 @@ static int show_recursive(const char *base, int baselen, const char *pathname)if (ls_options &LS_RECURSIVE )return 1 ; - s = pathspec.raw; + s = pathspec._raw;if (!s)return 0 ;
cache.h +1 -1
@@ -482,7 +482,7 @@ extern int ie_modified(const struct index_state *, struct cache_entry *, struct#define PATHSPEC_ONESTAR 1/* the pathspec pattern sastisfies GFNM_ONESTAR */ struct pathspec { -const char **raw;/* get_pathspec() result, not freed by free_pathspec() */ +const char **_raw;/* get_pathspec() result, not freed by free_pathspec() */ int nr;unsigned int has_wildcard:1 ;unsigned int recursive:1 ;
dir.c +2 -2
@@ -108,7 +108,7 @@ int fill_directory(struct dir_struct *dir, const struct pathspec *pathspec) len =common_prefix_len (pathspec);/* Read the directory and prune it */ -read_directory (dir, pathspec->nr ? pathspec->raw[0 ] :"" , len, pathspec); +read_directory (dir, pathspec->nr ? pathspec->_raw[0 ] :"" , len, pathspec);return len; }
@@ -1235,7 +1235,7 @@ int read_directory(struct dir_struct *dir, const char *path, int len, const struif (has_symlink_leading_path (path, len))return dir->nr; - simplify =create_simplify (pathspec ? pathspec->raw :NULL ); + simplify =create_simplify (pathspec ? pathspec->_raw :NULL );if (!len ||treat_leading_path (dir, path, len, simplify))read_directory_recursive (dir, path, len,0 , simplify);free_simplify (simplify);
setup.c +3 -3
@@ -332,7 +332,7 @@ void parse_pathspec(struct pathspec *pathspec, raw[0 ] = prefix; raw[1 ] =NULL ; pathspec->nr =1 ; - pathspec->raw = raw; + pathspec->_raw = raw;return ; }
@@ -342,7 +342,7 @@ void parse_pathspec(struct pathspec *pathspec, pathspec->nr = n; pathspec->items = item =xmalloc (sizeof (*item) * n); - pathspec->raw = argv; + pathspec->_raw = argv; prefixlen = prefix ?strlen (prefix) :0 ;for (i =0 ; i < n; i++) {
@@ -372,7 +372,7 @@ const char **get_pathspec(const char *prefix, const char **pathspec) {struct pathspec ps;parse_pathspec (&ps,PATHSPEC_FROMTOP ,0 , prefix, pathspec); -return ps.raw; +return ps._raw; }/*
Signature · 1 line
1.8.0.rc2.23.g1fb49df
Quoted 15 lines · Nguyễn Thái Ngọc Duy
Changes from v2 (it's hard to keep track of after the rebase, so I may be missing something here):
- rebased on top of recent master, incorporate changes in
init_pathspecfrom jk/pathspec-literal and nd/pathspec-wildcard toparse_pathspec- kill
strip_trailing_slash_from_submodulesandtreat_gitlinks(pretty sure it'll cause conflicts with as/check-ignore)- kill
init_pathspec,match_pathspec,diff_tree_setup_pathsanddiff_tree_release_paths- check points for future pathspec development
Quoted 7 lines
As far as I understand the "pathspec unification", I'd say we are there, with a few exceptions like "mv", external commands.. But those are pretty much isolated.
I'll send another WIP series implementing :(icase) and :(glob), mainly to show (me) how future pathspec feature development looks like after this.
;-)
Thanks; looking forward to reading it.
Re: [PATCH v3 08/31] parse_pathspec: add PATHSPEC_EMPTY_MATCH_ALL
In reply to Nguyễn Thái Ngọc DuyHi,
I was tempted to ask this before, and the recent thread regarding "add -u/A" [1] convinced me to.
Quoted 8 lines · Nguyễn Thái Ngọc Duy
We have two ways of dealing with empty pathspec:
1. limit it to current prefix
2. match the entire working directorySome commands go with #1, some with #2.
get_pathspec()andparse_pathspec()only supports #1. Make it support #2 too viaPATHSPEC_EMPTY_MATCH_ALLflag.
If #2 is indeed the direction we want to go, then maybe we should make that the default behavior from parse_pathspec()? I.e. rename the flag "PATHSPEC_EMPTY_MATCH_PREFIX" (or something). Makes sense?
Btw, Matthieu was asking where we use #1. If you do invert the name and meaning of the flag, then the answer to that question should be (mostly?) obvious from a re-roll of your series (i.e. all the places where PATHSPEC_EMPTY_MATCH_PREFIX is used).
Martin
[1] http://thread.gmane.org/gmane.comp.version-control.git/213988/focus=214113
Re: [PATCH v3 08/31] parse_pathspec: add PATHSPEC_EMPTY_MATCH_ALL
Quoted 11 lines · Martin von Zweigbergk
Hi,
I was tempted to ask this before, and the recent thread regarding "add -u/A" [1] convinced me to.
Quoted 5 lines · Nguyễn Thái Ngọc Duy
We have two ways of dealing with empty pathspec:
1. limit it to current prefix
2. match the entire working directory
Quoted 7 lines
Quoted 3 lines
Some commands go with #1, some with #2.
get_pathspec()andparse_pathspec()only supports #1. Make it support #2 too viaPATHSPEC_EMPTY_MATCH_ALLflag.If #2 is indeed the direction we want to go, then maybe we should make that the default behavior from
parse_pathspec()? I.e. rename the flag "PATHSPEC_EMPTY_MATCH_PREFIX" (or something). Makes sense?
No problem with me. Will do unless someone objects.
Quoted 8 lines
Btw, Matthieu was asking where we use #1. If you do invert the name and meaning of the flag, then the answer to that question should be (mostly?) obvious from a re-roll of your series (i.e. all the places where
PATHSPEC_EMPTY_MATCH_PREFIXis used).Martin
[1] http://thread.gmane.org/gmane.comp.version-control.git/213988/focus=214113
Signature · 1 line
Duy