summaryrefslogtreecommitdiff
path: root/builtin/check-ignore.c
diff options
context:
space:
mode:
authorLibravatar Adam Spiers <git@adamspiers.org>2013-04-11 13:05:11 +0100
committerLibravatar Junio C Hamano <gitster@pobox.com>2013-04-11 11:01:58 -0700
commit0006d85c3a2fcbd803ed46cf283fab4e4fae3a7f (patch)
tree2defa4151a8aa9df407dd0f79dfece06bf02aaa0 /builtin/check-ignore.c
parentcheck-ignore: add -n / --non-matching option (diff)
downloadtgif-0006d85c3a2fcbd803ed46cf283fab4e4fae3a7f.tar.xz
check-ignore: move setup into cmd_check_ignore()
Initialisation of the dir_struct and path_exclude_check structs was previously done within check_ignore(). This was acceptable since check_ignore() was only called once per check-ignore invocation; however the next commit will convert it into an inner loop which is called once per line of STDIN when --stdin is given. Therefore moving the initialisation code out into cmd_check_ignore() ensures that initialisation is still only performed once per check-ignore invocation, and consequently that the output is identical whether pathspecs are provided as CLI arguments or via STDIN. Signed-off-by: Adam Spiers <git@adamspiers.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/check-ignore.c')
-rw-r--r--builtin/check-ignore.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c
index 59acf74c58..e2d3006464 100644
--- a/builtin/check-ignore.c
+++ b/builtin/check-ignore.c
@@ -63,30 +63,20 @@ static void output_exclude(const char *path, struct exclude *exclude)
}
}
-static int check_ignore(const char *prefix, const char **pathspec)
+static int check_ignore(struct path_exclude_check *check,
+ const char *prefix, const char **pathspec)
{
- struct dir_struct dir;
const char *path, *full_path;
char *seen;
int num_ignored = 0, dtype = DT_UNKNOWN, i;
- struct path_exclude_check check;
struct exclude *exclude;
- /* read_cache() is only necessary so we can watch out for submodules. */
- if (read_cache() < 0)
- die(_("index file corrupt"));
-
- memset(&dir, 0, sizeof(dir));
- dir.flags |= DIR_COLLECT_IGNORED;
- setup_standard_excludes(&dir);
-
if (!pathspec || !*pathspec) {
if (!quiet)
fprintf(stderr, "no pathspec given.\n");
return 0;
}
- path_exclude_check_init(&check, &dir);
/*
* look for pathspecs matching entries in the index, since these
* should not be ignored, in order to be consistent with
@@ -101,7 +91,7 @@ static int check_ignore(const char *prefix, const char **pathspec)
die_if_path_beyond_symlink(full_path, prefix);
exclude = NULL;
if (!seen[i]) {
- exclude = last_exclude_matching_path(&check, full_path,
+ exclude = last_exclude_matching_path(check, full_path,
-1, &dtype);
}
if (!quiet && (exclude || show_non_matching))
@@ -110,13 +100,11 @@ static int check_ignore(const char *prefix, const char **pathspec)
num_ignored++;
}
free(seen);
- clear_directory(&dir);
- path_exclude_check_clear(&check);
return num_ignored;
}
-static int check_ignore_stdin_paths(const char *prefix)
+static int check_ignore_stdin_paths(struct path_exclude_check *check, const char *prefix)
{
struct strbuf buf, nbuf;
char **pathspec = NULL;
@@ -139,17 +127,18 @@ static int check_ignore_stdin_paths(const char *prefix)
}
ALLOC_GROW(pathspec, nr + 1, alloc);
pathspec[nr] = NULL;
- num_ignored = check_ignore(prefix, (const char **)pathspec);
+ num_ignored = check_ignore(check, prefix, (const char **)pathspec);
maybe_flush_or_die(stdout, "attribute to stdout");
strbuf_release(&buf);
strbuf_release(&nbuf);
- free(pathspec);
return num_ignored;
}
int cmd_check_ignore(int argc, const char **argv, const char *prefix)
{
int num_ignored;
+ struct dir_struct dir;
+ struct path_exclude_check check;
git_config(git_default_config, NULL);
@@ -174,12 +163,24 @@ int cmd_check_ignore(int argc, const char **argv, const char *prefix)
if (show_non_matching && !verbose)
die(_("--non-matching is only valid with --verbose"));
+ /* read_cache() is only necessary so we can watch out for submodules. */
+ if (read_cache() < 0)
+ die(_("index file corrupt"));
+
+ memset(&dir, 0, sizeof(dir));
+ dir.flags |= DIR_COLLECT_IGNORED;
+ setup_standard_excludes(&dir);
+
+ path_exclude_check_init(&check, &dir);
if (stdin_paths) {
- num_ignored = check_ignore_stdin_paths(prefix);
+ num_ignored = check_ignore_stdin_paths(&check, prefix);
} else {
- num_ignored = check_ignore(prefix, argv);
+ num_ignored = check_ignore(&check, prefix, argv);
maybe_flush_or_die(stdout, "ignore to stdout");
}
+ clear_directory(&dir);
+ path_exclude_check_clear(&check);
+
return !num_ignored;
}