Merge branch 'as/check-ignore'
authorJunio C Hamano <gitster@pobox.com>
Thu, 24 Jan 2013 05:19:10 +0000 (23 21:19 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 24 Jan 2013 05:19:10 +0000 (23 21:19 -0800)
Add a new command "git check-ignore" for debugging .gitignore
files.

The variable names may want to get cleaned up but that can be done
in-tree.

* as/check-ignore:
  clean.c, ls-files.c: respect encapsulation of exclude_list_groups
  t0008: avoid brace expansion
  add git-check-ignore sub-command
  setup.c: document get_pathspec()
  add.c: extract new die_if_path_beyond_symlink() for reuse
  add.c: extract check_path_for_gitlink() from treat_gitlinks() for reuse
  pathspec.c: rename newly public functions for clarity
  add.c: move pathspec matchers into new pathspec.c for reuse
  add.c: remove unused argument from validate_pathspec()
  dir.c: improve docs for match_pathspec() and match_pathspec_depth()
  dir.c: provide clear_directory() for reclaiming dir_struct memory
  dir.c: keep track of where patterns came from
  dir.c: use a single struct exclude_list per source of excludes

Conflicts:
builtin/ls-files.c
dir.c

14 files changed:
1  2 
.gitignore
Documentation/gitignore.txt
Makefile
builtin.h
builtin/add.c
builtin/clean.c
builtin/ls-files.c
command-list.txt
contrib/completion/git-completion.bash
dir.c
dir.h
git.c
setup.c
unpack-trees.c

diff --cc .gitignore
Simple merge
Simple merge
diff --cc Makefile
+++ b/Makefile
@@@ -654,18 -633,19 +654,19 @@@ LIB_H += list-objects.
  LIB_H += ll-merge.h
  LIB_H += log-tree.h
  LIB_H += mailmap.h
 -LIB_H += merge-file.h
 +LIB_H += merge-blobs.h
  LIB_H += merge-recursive.h
  LIB_H += mergesort.h
 -LIB_H += notes.h
  LIB_H += notes-cache.h
  LIB_H += notes-merge.h
 +LIB_H += notes.h
  LIB_H += object.h
 -LIB_H += pack.h
  LIB_H += pack-refs.h
  LIB_H += pack-revindex.h
 +LIB_H += pack.h
  LIB_H += parse-options.h
  LIB_H += patch-ids.h
+ LIB_H += pathspec.h
  LIB_H += pkt-line.h
  LIB_H += progress.h
  LIB_H += prompt.h
diff --cc builtin.h
Simple merge
diff --cc builtin/add.c
Simple merge
diff --cc builtin/clean.c
Simple merge
@@@ -452,62 -453,65 +453,64 @@@ static int option_parse_exclude_standar
  
  int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
  {
-       int require_work_tree = 0, show_tag = 0;
+       int require_work_tree = 0, show_tag = 0, i;
        const char *max_prefix;
        struct dir_struct dir;
+       struct exclude_list *el;
+       struct string_list exclude_list = STRING_LIST_INIT_NODUP;
        struct option builtin_ls_files_options[] = {
                { OPTION_CALLBACK, 'z', NULL, NULL, NULL,
 -                      "paths are separated with NUL character",
 +                      N_("paths are separated with NUL character"),
                        PARSE_OPT_NOARG, option_parse_z },
                OPT_BOOLEAN('t', NULL, &show_tag,
 -                      "identify the file status with tags"),
 +                      N_("identify the file status with tags")),
                OPT_BOOLEAN('v', NULL, &show_valid_bit,
 -                      "use lowercase letters for 'assume unchanged' files"),
 +                      N_("use lowercase letters for 'assume unchanged' files")),
                OPT_BOOLEAN('c', "cached", &show_cached,
 -                      "show cached files in the output (default)"),
 +                      N_("show cached files in the output (default)")),
                OPT_BOOLEAN('d', "deleted", &show_deleted,
 -                      "show deleted files in the output"),
 +                      N_("show deleted files in the output")),
                OPT_BOOLEAN('m', "modified", &show_modified,
 -                      "show modified files in the output"),
 +                      N_("show modified files in the output")),
                OPT_BOOLEAN('o', "others", &show_others,
 -                      "show other files in the output"),
 +                      N_("show other files in the output")),
                OPT_BIT('i', "ignored", &dir.flags,
 -                      "show ignored files in the output",
 +                      N_("show ignored files in the output"),
                        DIR_SHOW_IGNORED),
                OPT_BOOLEAN('s', "stage", &show_stage,
 -                      "show staged contents' object name in the output"),
 +                      N_("show staged contents' object name in the output")),
                OPT_BOOLEAN('k', "killed", &show_killed,
 -                      "show files on the filesystem that need to be removed"),
 +                      N_("show files on the filesystem that need to be removed")),
                OPT_BIT(0, "directory", &dir.flags,
 -                      "show 'other' directories' name only",
 +                      N_("show 'other' directories' name only"),
                        DIR_SHOW_OTHER_DIRECTORIES),
                OPT_NEGBIT(0, "empty-directory", &dir.flags,
 -                      "don't show empty directories",
 +                      N_("don't show empty directories"),
                        DIR_HIDE_EMPTY_DIRECTORIES),
                OPT_BOOLEAN('u', "unmerged", &show_unmerged,
 -                      "show unmerged files in the output"),
 +                      N_("show unmerged files in the output")),
                OPT_BOOLEAN(0, "resolve-undo", &show_resolve_undo,
 -                          "show resolve-undo information"),
 -              { OPTION_CALLBACK, 'x', "exclude",
 -                      &exclude_list, "pattern",
 -                      "skip files matching pattern",
 +                          N_("show resolve-undo information")),
-               { OPTION_CALLBACK, 'x', "exclude", &dir.exclude_list[EXC_CMDL], N_("pattern"),
++              { OPTION_CALLBACK, 'x', "exclude", &exclude_list, N_("pattern"),
 +                      N_("skip files matching pattern"),
                        0, option_parse_exclude },
 -              { OPTION_CALLBACK, 'X', "exclude-from", &dir, "file",
 -                      "exclude patterns are read from <file>",
 +              { OPTION_CALLBACK, 'X', "exclude-from", &dir, N_("file"),
 +                      N_("exclude patterns are read from <file>"),
                        0, option_parse_exclude_from },
 -              OPT_STRING(0, "exclude-per-directory", &dir.exclude_per_dir, "file",
 -                      "read additional per-directory exclude patterns in <file>"),
 +              OPT_STRING(0, "exclude-per-directory", &dir.exclude_per_dir, N_("file"),
 +                      N_("read additional per-directory exclude patterns in <file>")),
                { OPTION_CALLBACK, 0, "exclude-standard", &dir, NULL,
 -                      "add the standard git exclusions",
 +                      N_("add the standard git exclusions"),
                        PARSE_OPT_NOARG, option_parse_exclude_standard },
                { OPTION_SET_INT, 0, "full-name", &prefix_len, NULL,
 -                      "make the output relative to the project top directory",
 +                      N_("make the output relative to the project top directory"),
                        PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL },
                OPT_BOOLEAN(0, "error-unmatch", &error_unmatch,
 -                      "if any <file> is not in the index, treat this as an error"),
 -              OPT_STRING(0, "with-tree", &with_tree, "tree-ish",
 -                      "pretend that paths removed since <tree-ish> are still present"),
 +                      N_("if any <file> is not in the index, treat this as an error")),
 +              OPT_STRING(0, "with-tree", &with_tree, N_("tree-ish"),
 +                      N_("pretend that paths removed since <tree-ish> are still present")),
                OPT__ABBREV(&abbrev),
 -              OPT_BOOLEAN(0, "debug", &debug_mode, "show debugging data"),
 +              OPT_BOOLEAN(0, "debug", &debug_mode, N_("show debugging data")),
                OPT_END()
        };
  
Simple merge
diff --cc dir.c
--- 1/dir.c
--- 2/dir.c
+++ b/dir.c
@@@ -1620,10 -1572,32 +1674,40 @@@ void free_pathspec(struct pathspec *pat
        pathspec->items = NULL;
  }
  
 +int limit_pathspec_to_literal(void)
 +{
 +      static int flag = -1;
 +      if (flag < 0)
 +              flag = git_env_bool(GIT_LITERAL_PATHSPECS_ENVIRONMENT, 0);
 +      return flag;
 +}
++
+ /*
+  * Frees memory within dir which was allocated for exclude lists and
+  * the exclude_stack.  Does not free dir itself.
+  */
+ void clear_directory(struct dir_struct *dir)
+ {
+       int i, j;
+       struct exclude_list_group *group;
+       struct exclude_list *el;
+       struct exclude_stack *stk;
+       for (i = EXC_CMDL; i <= EXC_FILE; i++) {
+               group = &dir->exclude_list_group[i];
+               for (j = 0; j < group->nr; j++) {
+                       el = &group->el[j];
+                       if (i == EXC_DIRS)
+                               free((char *)el->src);
+                       clear_exclude_list(el);
+               }
+               free(group->el);
+       }
+       stk = dir->exclude_stack;
+       while (stk) {
+               struct exclude_stack *prev = stk->prev;
+               free(stk);
+               stk = prev;
+       }
+ }
diff --cc dir.h
Simple merge
diff --cc git.c
Simple merge
diff --cc setup.c
Simple merge
diff --cc unpack-trees.c
Simple merge