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

path.c: clarify two field names in 'struct common_dir'

An array of 'struct common_dir' instances is used to specify whether various paths in $GIT_DIR are specific to a worktree, or are common, i.e. belong to main worktree. The names of two fields in this struct are somewhat confusing or ambigious: - The path is recorded in the struct's 'dirname' field, even though several entries are regular files e.g. 'gc.pid', 'packed-refs', etc. Rename this field to 'path' to reduce confusion. - The field 'exclude' tells whether the path is excluded... from where? Excluded from the common dir or from the worktree? It means the former, but it's ambigious. Rename this field to 'is_common' to make it unambigious what it means. This, however, means the exact opposite of what 'exclude' meant, so we have to negate the field's value in all entries as well. The diff is best viewed with '--color-words'. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Oct 21, 2019 at 18:00 UTC c72fc40d0904cbf3199258c2f471c2351e024b1e
1 file changed +33 -33
path.c
+33 -33
@@ -101,36 +101,36 @@ struct common_dir {
101 /* Not considered garbage for report_linked_checkout_garbage */
102 unsigned ignore_garbage:1;
103 unsigned is_dir:1;
104 - /* Not common even though its parent is */
105 - unsigned exclude:1;
106 - const char *dirname;
104 + /* Belongs to the common dir, though it may contain paths that don't */
105 + unsigned is_common:1;
106 + const char *path;
107 };
108
109 static struct common_dir common_list[] = {
110 - { 0, 1, 0, "branches" },
111 - { 0, 1, 0, "common" },
112 - { 0, 1, 0, "hooks" },
113 - { 0, 1, 0, "info" },
114 - { 0, 0, 1, "info/sparse-checkout" },
115 - { 1, 1, 0, "logs" },
116 - { 1, 0, 1, "logs/HEAD" },
117 - { 0, 1, 1, "logs/refs/bisect" },
118 - { 0, 1, 1, "logs/refs/rewritten" },
119 - { 0, 1, 1, "logs/refs/worktree" },
120 - { 0, 1, 0, "lost-found" },
121 - { 0, 1, 0, "objects" },
122 - { 0, 1, 0, "refs" },
123 - { 0, 1, 1, "refs/bisect" },
124 - { 0, 1, 1, "refs/rewritten" },
125 - { 0, 1, 1, "refs/worktree" },
126 - { 0, 1, 0, "remotes" },
127 - { 0, 1, 0, "worktrees" },
128 - { 0, 1, 0, "rr-cache" },
129 - { 0, 1, 0, "svn" },
130 - { 0, 0, 0, "config" },
131 - { 1, 0, 0, "gc.pid" },
132 - { 0, 0, 0, "packed-refs" },
133 - { 0, 0, 0, "shallow" },
110 + { 0, 1, 1, "branches" },
111 + { 0, 1, 1, "common" },
112 + { 0, 1, 1, "hooks" },
113 + { 0, 1, 1, "info" },
114 + { 0, 0, 0, "info/sparse-checkout" },
115 + { 1, 1, 1, "logs" },
116 + { 1, 0, 0, "logs/HEAD" },
117 + { 0, 1, 0, "logs/refs/bisect" },
118 + { 0, 1, 0, "logs/refs/rewritten" },
119 + { 0, 1, 0, "logs/refs/worktree" },
120 + { 0, 1, 1, "lost-found" },
121 + { 0, 1, 1, "objects" },
122 + { 0, 1, 1, "refs" },
123 + { 0, 1, 0, "refs/bisect" },
124 + { 0, 1, 0, "refs/rewritten" },
125 + { 0, 1, 0, "refs/worktree" },
126 + { 0, 1, 1, "remotes" },
127 + { 0, 1, 1, "worktrees" },
128 + { 0, 1, 1, "rr-cache" },
129 + { 0, 1, 1, "svn" },
130 + { 0, 0, 1, "config" },
131 + { 1, 0, 1, "gc.pid" },
132 + { 0, 0, 1, "packed-refs" },
133 + { 0, 0, 1, "shallow" },
134 { 0, 0, 0, NULL }
135 };
136
@@ -331,8 +331,8 @@ static void init_common_trie(void)
331 if (common_trie_done_setup)
332 return;
333
334 - for (p = common_list; p->dirname; p++)
335 - add_to_trie(&common_trie, p->dirname, p);
334 + for (p = common_list; p->path; p++)
335 + add_to_trie(&common_trie, p->path, p);
336
337 common_trie_done_setup = 1;
338 }
@@ -349,10 +349,10 @@ static int check_common(const char *unmatched, void *value, void *baton)
349 return 0;
350
351 if (dir->is_dir && (unmatched[0] == 0 || unmatched[0] == '/'))
352 - return !dir->exclude;
352 + return dir->is_common;
353
354 if (!dir->is_dir && unmatched[0] == 0)
355 - return !dir->exclude;
355 + return dir->is_common;
356
357 return 0;
358 }
@@ -376,8 +376,8 @@ void report_linked_checkout_garbage(void)
376 return;
377 strbuf_addf(&sb, "%s/", get_git_dir());
378 len = sb.len;
379 - for (p = common_list; p->dirname; p++) {
380 - const char *path = p->dirname;
379 + for (p = common_list; p->path; p++) {
380 + const char *path = p->path;
381 if (p->ignore_garbage)
382 continue;
383 strbuf_setlen(&sb, len);