@@ -91,35 +91,51 @@ static void replace_dir(struct strbuf *buf, int len, const char *newdir)
91
91
buf -> buf [newlen ] = '/' ;
92
92
}
93
93
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 }
99
122
};
100
123
101
124
static void update_common_dir (struct strbuf * buf , int git_dir_len )
102
125
{
103
126
char * base = buf -> buf + git_dir_len ;
104
- const char * * p ;
127
+ const struct common_dir * p ;
105
128
106
129
if (is_dir_file (base , "logs" , "HEAD" ) ||
107
130
is_dir_file (base , "info" , "sparse-checkout" ))
108
131
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 )) {
119
135
replace_dir (buf , git_dir_len , get_git_common_dir ());
120
136
return ;
121
137
}
122
- if (!is_dir && !strcmp (base , path )) {
138
+ if (!p -> is_dir && !strcmp (base , path )) {
123
139
replace_dir (buf , git_dir_len , get_git_common_dir ());
124
140
return ;
125
141
}
@@ -129,16 +145,16 @@ static void update_common_dir(struct strbuf *buf, int git_dir_len)
129
145
void report_linked_checkout_garbage (void )
130
146
{
131
147
struct strbuf sb = STRBUF_INIT ;
132
- const char * * p ;
148
+ const struct common_dir * p ;
133
149
int len ;
134
150
135
151
if (!git_common_dir_env )
136
152
return ;
137
153
strbuf_addf (& sb , "%s/" , get_git_dir ());
138
154
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 )
142
158
continue ;
143
159
strbuf_setlen (& sb , len );
144
160
strbuf_addstr (& sb , path );
0 commit comments