@matheusbsbs / matheus-bagliano / commits / dcf0c16ef1
Fork 0

core.excludesfile clean-up

There are inconsistencies in the way commands currently handle the core.excludesfile configuration variable. The problem is the variable is too new to be noticed by anything other than git-add and git-status. * git-ls-files does not notice any of the "ignore" files by default, as it predates the standardized set of ignore files. The calling scripts established the convention to use .git/info/exclude, .gitignore, and later core.excludesfile. * git-add and git-status know about it because they call add_excludes_from_file() directly with their own notion of which standard set of ignore files to use. This is just a stupid duplication of code that need to be updated every time the definition of the standard set of ignore files is changed. * git-read-tree takes --exclude-per-directory=<gitignore>, not because the flexibility was needed. Again, this was because the option predates the standardization of the ignore files. * git-merge-recursive uses hardcoded per-directory .gitignore and nothing else. git-clean (scripted version) does not honor core.* because its call to underlying ls-files does not know about it. git-clean in C (parked in 'pu') doesn't either. We probably could change git-ls-files to use the standard set when no excludes are specified on the command line and ignore processing was asked, or something like that, but that will be a change in semantics and might break people's scripts in a subtle way. I am somewhat reluctant to make such a change. On the other hand, I think it makes perfect sense to fix git-read-tree, git-merge-recursive and git-clean to follow the same rule as other commands. I do not think of a valid use case to give an exclude-per-directory that is nonstandard to read-tree command, outside a "negative" test in the t1004 test script. This patch is the first step to untangle this mess. The next step would be to teach read-tree, merge-recursive and clean (in C) to use setup_standard_excludes(). Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Nov 16, 2007 at 17:05 UTC dcf0c16ef1a8c2e468afe686a27a5549fea59798
7 files changed +26 -34
builtin-add.c
+2 -20
@@ -17,7 +17,6 @@ static const char builtin_add_usage[] =
17 "git-add [-n] [-v] [-f] [--interactive | -i] [-u] [--refresh] [--] <filepattern>...";
18
19 static int take_worktree_changes;
20 -static const char *excludes_file;
20
21 static void prune_directory(struct dir_struct *dir, const char **pathspec, int prefix)
22 {
@@ -57,12 +56,7 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec,
56 memset(dir, 0, sizeof(*dir));
57 if (!ignored_too) {
58 dir->collect_ignored = 1;
60 - dir->exclude_per_dir = ".gitignore";
61 - path = git_path("info/exclude");
62 - if (!access(path, R_OK))
63 - add_excludes_from_file(dir, path);
64 - if (excludes_file != NULL && !access(excludes_file, R_OK))
65 - add_excludes_from_file(dir, excludes_file);
59 + setup_standard_excludes(dir);
60 }
61
62 /*
@@ -144,18 +138,6 @@ static void refresh(int verbose, const char **pathspec)
138 free(seen);
139 }
140
147 -static int git_add_config(const char *var, const char *value)
148 -{
149 - if (!strcmp(var, "core.excludesfile")) {
150 - if (!value)
151 - die("core.excludesfile without value");
152 - excludes_file = xstrdup(value);
153 - return 0;
154 - }
155 -
156 - return git_default_config(var, value);
157 -}
158 -
141 static struct lock_file lock_file;
142
143 static const char ignore_error[] =
@@ -183,7 +165,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
165 exit(1);
166 }
167
186 - git_config(git_add_config);
168 + git_config(git_default_config);
169
170 newfd = hold_locked_index(&lock_file, 1);
171
cache.h
+1
@@ -571,6 +571,7 @@ extern int pager_in_use;
571 extern int pager_use_color;
572
573 extern char *editor_program;
574 +extern char *excludes_file;
575
576 /* base85 */
577 int decode_85(char *dst, const char *line, int linelen);
config.c
+7
@@ -431,6 +431,13 @@ int git_default_config(const char *var, const char *value)
431 return 0;
432 }
433
434 + if (!strcmp(var, "core.excludesfile")) {
435 + if (!value)
436 + die("core.excludesfile without value");
437 + excludes_file = xstrdup(value);
438 + return 0;
439 + }
440 +
441 /* Add other config variables here and to Documentation/config.txt. */
442 return 0;
443 }
dir.c
+12
@@ -709,3 +709,15 @@ int is_inside_dir(const char *dir)
709 char buffer[PATH_MAX];
710 return get_relative_cwd(buffer, sizeof(buffer), dir) != NULL;
711 }
712 +
713 +void setup_standard_excludes(struct dir_struct *dir)
714 +{
715 + const char *path;
716 +
717 + dir->exclude_per_dir = ".gitignore";
718 + path = git_path("info/exclude");
719 + if (!access(path, R_OK))
720 + add_excludes_from_file(dir, path);
721 + if (excludes_file && !access(excludes_file, R_OK))
722 + add_excludes_from_file(dir, excludes_file);
723 +}
dir.h
+2
@@ -64,4 +64,6 @@ extern struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathna
64 extern char *get_relative_cwd(char *buffer, int size, const char *dir);
65 extern int is_inside_dir(const char *dir);
66
67 +extern void setup_standard_excludes(struct dir_struct *dir);
68 +
69 #endif
environment.c
+1
@@ -34,6 +34,7 @@ char *pager_program;
34 int pager_in_use;
35 int pager_use_color = 1;
36 char *editor_program;
37 +char *excludes_file;
38 int auto_crlf = 0; /* 1: both ways, -1: only when adding git objects */
39
40 /* This is set by setup_git_dir_gently() and/or git_default_config() */
wt-status.c
+1 -14
@@ -22,7 +22,6 @@ static const char use_add_rm_msg[] =
22 "use \"git add/rm <file>...\" to update what will be committed";
23 static const char use_add_to_include_msg[] =
24 "use \"git add <file>...\" to include in what will be committed";
25 -static const char *excludes_file;
25
26 static int parse_status_slot(const char *var, int offset)
27 {
@@ -247,22 +246,16 @@ static void wt_status_print_changed(struct wt_status *s)
246 static void wt_status_print_untracked(struct wt_status *s)
247 {
248 struct dir_struct dir;
250 - const char *x;
249 int i;
250 int shown_header = 0;
251
252 memset(&dir, 0, sizeof(dir));
253
256 - dir.exclude_per_dir = ".gitignore";
254 if (!s->untracked) {
255 dir.show_other_directories = 1;
256 dir.hide_empty_directories = 1;
257 }
261 - x = git_path("info/exclude");
262 - if (file_exists(x))
263 - add_excludes_from_file(&dir, x);
264 - if (excludes_file && file_exists(excludes_file))
265 - add_excludes_from_file(&dir, excludes_file);
258 + setup_standard_excludes(&dir);
259
260 read_directory(&dir, ".", "", 0, NULL);
261 for(i = 0; i < dir.nr; i++) {
@@ -360,11 +353,5 @@ int git_status_config(const char *k, const char *v)
353 int slot = parse_status_slot(k, 13);
354 color_parse(v, k, wt_status_colors[slot]);
355 }
363 - if (!strcmp(k, "core.excludesfile")) {
364 - if (!v)
365 - die("core.excludesfile without value");
366 - excludes_file = xstrdup(v);
367 - return 0;
368 - }
356 return git_default_config(k, v);
357 }