Skip to content

Commit 0701530

Browse files
dturner-twgitster
authored andcommitted
refs: clean up common_list
Instead of common_list having formatting like ! and /, use a struct to hold common_list data in a structured form. We don't use 'exclude' yet; instead, we keep the old codepath that handles info/sparse-checkout and logs/HEAD. Later, we will use exclude. [jc: with "make common_list[] static" clean-up from Ramsay squashed in] Signed-off-by: David Turner <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 33f2c4f commit 0701530

File tree

1 file changed

+37
-21
lines changed

1 file changed

+37
-21
lines changed

path.c

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -91,35 +91,51 @@ static void replace_dir(struct strbuf *buf, int len, const char *newdir)
9191
buf->buf[newlen] = '/';
9292
}
9393

94-
static const char *common_list[] = {
95-
"/branches", "/hooks", "/info", "!/logs", "/lost-found",
96-
"/objects", "/refs", "/remotes", "/worktrees", "/rr-cache", "/svn",
97-
"config", "!gc.pid", "packed-refs", "shallow",
98-
NULL
94+
struct common_dir {
95+
/* Not considered garbage for report_linked_checkout_garbage */
96+
unsigned ignore_garbage:1;
97+
unsigned is_dir:1;
98+
/* Not common even though its parent is */
99+
unsigned exclude:1;
100+
const char *dirname;
101+
};
102+
103+
static struct common_dir common_list[] = {
104+
{ 0, 1, 0, "branches" },
105+
{ 0, 1, 0, "hooks" },
106+
{ 0, 1, 0, "info" },
107+
{ 0, 0, 1, "info/sparse-checkout" },
108+
{ 1, 1, 0, "logs" },
109+
{ 1, 1, 1, "logs/HEAD" },
110+
{ 0, 1, 0, "lost-found" },
111+
{ 0, 1, 0, "objects" },
112+
{ 0, 1, 0, "refs" },
113+
{ 0, 1, 0, "remotes" },
114+
{ 0, 1, 0, "worktrees" },
115+
{ 0, 1, 0, "rr-cache" },
116+
{ 0, 1, 0, "svn" },
117+
{ 0, 0, 0, "config" },
118+
{ 1, 0, 0, "gc.pid" },
119+
{ 0, 0, 0, "packed-refs" },
120+
{ 0, 0, 0, "shallow" },
121+
{ 0, 0, 0, NULL }
99122
};
100123

101124
static void update_common_dir(struct strbuf *buf, int git_dir_len)
102125
{
103126
char *base = buf->buf + git_dir_len;
104-
const char **p;
127+
const struct common_dir *p;
105128

106129
if (is_dir_file(base, "logs", "HEAD") ||
107130
is_dir_file(base, "info", "sparse-checkout"))
108131
return; /* keep this in $GIT_DIR */
109-
for (p = common_list; *p; p++) {
110-
const char *path = *p;
111-
int is_dir = 0;
112-
if (*path == '!')
113-
path++;
114-
if (*path == '/') {
115-
path++;
116-
is_dir = 1;
117-
}
118-
if (is_dir && dir_prefix(base, path)) {
132+
for (p = common_list; p->dirname; p++) {
133+
const char *path = p->dirname;
134+
if (p->is_dir && dir_prefix(base, path)) {
119135
replace_dir(buf, git_dir_len, get_git_common_dir());
120136
return;
121137
}
122-
if (!is_dir && !strcmp(base, path)) {
138+
if (!p->is_dir && !strcmp(base, path)) {
123139
replace_dir(buf, git_dir_len, get_git_common_dir());
124140
return;
125141
}
@@ -129,16 +145,16 @@ static void update_common_dir(struct strbuf *buf, int git_dir_len)
129145
void report_linked_checkout_garbage(void)
130146
{
131147
struct strbuf sb = STRBUF_INIT;
132-
const char **p;
148+
const struct common_dir *p;
133149
int len;
134150

135151
if (!git_common_dir_env)
136152
return;
137153
strbuf_addf(&sb, "%s/", get_git_dir());
138154
len = sb.len;
139-
for (p = common_list; *p; p++) {
140-
const char *path = *p;
141-
if (*path == '!')
155+
for (p = common_list; p->dirname; p++) {
156+
const char *path = p->dirname;
157+
if (p->ignore_garbage)
142158
continue;
143159
strbuf_setlen(&sb, len);
144160
strbuf_addstr(&sb, path);

0 commit comments

Comments
 (0)