@matheusbsbs / matheus-bagliano / commits / 039bc64e88
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 14, 2007 at 00:05 UTC 039bc64e886716593d59910694a6c8ed5b72c515
7 files changed +25 -34
builtin-add.c
+2 -20
@@ -21,7 +21,6 @@ static const char * const builtin_add_usage[] = {
21 };
22
23 static int take_worktree_changes;
24 -static const char *excludes_file;
24
25 static void prune_directory(struct dir_struct *dir, const char **pathspec, int prefix)
26 {
@@ -61,12 +60,7 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec,
60 memset(dir, 0, sizeof(*dir));
61 if (!ignored_too) {
62 dir->collect_ignored = 1;
64 - dir->exclude_per_dir = ".gitignore";
65 - path = git_path("info/exclude");
66 - if (!access(path, R_OK))
67 - add_excludes_from_file(dir, path);
68 - if (excludes_file != NULL && !access(excludes_file, R_OK))
69 - add_excludes_from_file(dir, excludes_file);
63 + setup_standard_excludes(dir);
64 }
65
66 /*
@@ -141,18 +135,6 @@ static void refresh(int verbose, const char **pathspec)
135 free(seen);
136 }
137
144 -static int git_add_config(const char *var, const char *value)
145 -{
146 - if (!strcmp(var, "core.excludesfile")) {
147 - if (!value)
148 - die("core.excludesfile without value");
149 - excludes_file = xstrdup(value);
150 - return 0;
151 - }
152 -
153 - return git_default_config(var, value);
154 -}
155 -
138 int interactive_add(void)
139 {
140 const char *argv[2] = { "add--interactive", NULL };
@@ -193,7 +175,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
175 exit(interactive_add());
176 }
177
196 - git_config(git_add_config);
178 + git_config(git_default_config);
179
180 newfd = hold_locked_index(&lock_file, 1);
181
cache.h
+1
@@ -581,6 +581,7 @@ extern int pager_in_use;
581 extern int pager_use_color;
582
583 extern char *editor_program;
584 +extern char *excludes_file;
585
586 /* base85 */
587 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
@@ -778,3 +778,15 @@ int remove_dir_recursively(struct strbuf *path, int only_empty)
778 ret = rmdir(path->buf);
779 return ret;
780 }
781 +
782 +void setup_standard_excludes(struct dir_struct *dir)
783 +{
784 + const char *path;
785 +
786 + dir->exclude_per_dir = ".gitignore";
787 + path = git_path("info/exclude");
788 + if (!access(path, R_OK))
789 + add_excludes_from_file(dir, path);
790 + if (excludes_file && !access(excludes_file, R_OK))
791 + add_excludes_from_file(dir, excludes_file);
792 +}
dir.h
+1
@@ -71,6 +71,7 @@ extern struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathna
71 extern char *get_relative_cwd(char *buffer, int size, const char *dir);
72 extern int is_inside_dir(const char *dir);
73
74 +extern void setup_standard_excludes(struct dir_struct *dir);
75 extern int remove_dir_recursively(struct strbuf *path, int only_empty);
76
77 #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 {
@@ -251,22 +250,16 @@ static void wt_status_print_changed(struct wt_status *s)
250 static void wt_status_print_untracked(struct wt_status *s)
251 {
252 struct dir_struct dir;
254 - const char *x;
253 int i;
254 int shown_header = 0;
255
256 memset(&dir, 0, sizeof(dir));
257
260 - dir.exclude_per_dir = ".gitignore";
258 if (!s->untracked) {
259 dir.show_other_directories = 1;
260 dir.hide_empty_directories = 1;
261 }
265 - x = git_path("info/exclude");
266 - if (file_exists(x))
267 - add_excludes_from_file(&dir, x);
268 - if (excludes_file && file_exists(excludes_file))
269 - add_excludes_from_file(&dir, excludes_file);
262 + setup_standard_excludes(&dir);
263
264 read_directory(&dir, ".", "", 0, NULL);
265 for(i = 0; i < dir.nr; i++) {
@@ -364,11 +357,5 @@ int git_status_config(const char *k, const char *v)
357 int slot = parse_status_slot(k, 13);
358 color_parse(v, k, wt_status_colors[slot]);
359 }
367 - if (!strcmp(k, "core.excludesfile")) {
368 - if (!v)
369 - die("core.excludesfile without value");
370 - excludes_file = xstrdup(v);
371 - return 0;
372 - }
360 return git_default_config(k, v);
361 }