From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 03/21] Export parse_pathspec() and convert some get_pathspec() calls
Date: Fri, 11 Jan 2013 18:20:57 +0700 [thread overview]
Message-ID: <1357903275-16804-4-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1357903275-16804-1-git-send-email-pclouds@gmail.com>
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 <pclouds@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 (1<<0)
+
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
next prev parent reply other threads:[~2013-01-11 11:21 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-11 11:20 [PATCH v2 00/21] nd/parse-pathspec reroll Nguyễn Thái Ngọc Duy
2013-01-11 11:20 ` [PATCH v2 01/21] pathspec: save the non-wildcard length part Nguyễn Thái Ngọc Duy
2013-01-11 11:20 ` [PATCH v2 02/21] Add parse_pathspec() that converts cmdline args to struct pathspec Nguyễn Thái Ngọc Duy
2013-01-11 11:20 ` Nguyễn Thái Ngọc Duy [this message]
2013-01-11 17:56 ` [PATCH v2 03/21] Export parse_pathspec() and convert some get_pathspec() calls Matt Kraai
2013-01-12 6:00 ` Duy Nguyen
2013-01-11 11:20 ` [PATCH v2 04/21] clean: convert to use parse_pathspec Nguyễn Thái Ngọc Duy
2013-01-11 11:20 ` [PATCH v2 05/21] commit: " Nguyễn Thái Ngọc Duy
2013-01-12 22:54 ` Martin von Zweigbergk
2013-01-11 11:21 ` [PATCH v2 06/21] status: " Nguyễn Thái Ngọc Duy
2013-01-11 11:21 ` [PATCH v2 07/21] rerere: " Nguyễn Thái Ngọc Duy
2013-01-11 11:21 ` [PATCH v2 08/21] checkout: " Nguyễn Thái Ngọc Duy
2013-01-11 11:21 ` [PATCH v2 09/21] rm: " Nguyễn Thái Ngọc Duy
2013-01-11 11:21 ` [PATCH v2 10/21] ls-files: " Nguyễn Thái Ngọc Duy
2013-01-11 11:21 ` [PATCH v2 11/21] archive: " Nguyễn Thái Ngọc Duy
2013-01-11 11:21 ` [PATCH v2 12/21] add: " Nguyễn Thái Ngọc Duy
2013-01-11 11:21 ` [PATCH v2 13/21] Convert read_cache_preload() to take struct pathspec Nguyễn Thái Ngọc Duy
2013-01-11 11:21 ` [PATCH v2 14/21] Convert unmerge_cache " Nguyễn Thái Ngọc Duy
2013-01-11 11:21 ` [PATCH v2 15/21] checkout: convert read_tree_some " Nguyễn Thái Ngọc Duy
2013-01-11 11:21 ` [PATCH v2 16/21] Convert report_path_error " Nguyễn Thái Ngọc Duy
2013-01-11 11:21 ` [PATCH v2 17/21] Convert refresh_index " Nguyễn Thái Ngọc Duy
2013-01-11 14:19 ` Nguyen Thai Ngoc Duy
2013-01-11 11:21 ` [PATCH v2 18/21] Convert {read,fill}_directory " Nguyễn Thái Ngọc Duy
2013-01-11 11:21 ` [PATCH v2 19/21] Convert add_files_to_cache " Nguyễn Thái Ngọc Duy
2013-01-11 11:21 ` [PATCH v2 20/21] Convert more init_pathspec() to parse_pathspec() Nguyễn Thái Ngọc Duy
2013-01-11 11:21 ` [PATCH v2 21/21] Rename field "raw" to "_raw" in struct pathspec Nguyễn Thái Ngọc Duy
2013-01-11 14:26 ` [PATCH v2 22/21] Convert the last use of match_pathspec() and remove it Nguyễn Thái Ngọc Duy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1357903275-16804-4-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).