These call sites follow the pattern:
paths = get_pathspec(prefix, argv);
init_pathspec(pathspec, paths);
which can be converted into a single parse_pathspec() call.
Signed-off-by: Nguyễn Thái Ngọc Duy pclo...@gmail.com
---
builtin/grep.c | 4 +---
builtin/ls-tree.c | 2 +-
builtin/update-index.c | 3 +--
cache.h| 6 ++
revision.c | 4 ++--
setup.c| 6 +++---
6 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index 0e1b6c8..705f9ff 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -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;
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index fb76e38..a78ba53 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -166,7 +166,7 @@ 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));
+ 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;
diff --git a/builtin/update-index.c b/builtin/update-index.c
index ada1dff..6728e59 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -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
diff --git a/cache.h b/cache.h
index 9304d91..e52365d 100644
--- a/cache.h
+++ b/cache.h
@@ -473,6 +473,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(10)
+
struct pathspec {
const char **raw; /* get_pathspec() result, not freed by
free_pathspec() */
int nr;
@@ -487,6 +490,9 @@ struct pathspec {
};
extern int init_pathspec(struct pathspec *, const char **);
+extern void parse_pathspec(struct pathspec *pathspec, unsigned magic,
+ unsigned flags, const char *prefix,
+ const char **args);
extern void free_pathspec(struct pathspec *);
extern int ce_path_match(const struct cache_entry *ce, const struct pathspec
*pathspec);
diff --git a/revision.c b/revision.c
index 95d21e6..a044242 100644
--- a/revision.c
+++ b/revision.c
@@ -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)
diff --git a/setup.c b/setup.c
index 4fcdae6..6e960b9 100644
--- a/setup.c
+++ b/setup.c
@@ -266,9 +266,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;
--
1.8.0.rc2.23.g1fb49df
--
To