Skip to content

Commit 77a6d84

Browse files
pcloudsgitster
authored andcommitted
count-objects: report unused files in $GIT_DIR/worktrees/...
In linked checkouts, borrowed parts like config is taken from $GIT_COMMON_DIR. $GIT_DIR/config is never used. Report them as garbage. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e3df33b commit 77a6d84

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

builtin/count-objects.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
7070
/* we do not take arguments other than flags for now */
7171
if (argc)
7272
usage_with_options(count_objects_usage, opts);
73-
if (verbose)
73+
if (verbose) {
7474
report_garbage = real_report_garbage;
75+
report_linked_checkout_garbage();
76+
}
7577

7678
for_each_loose_file_in_objdir(get_object_directory(),
7779
count_loose, count_cruft, NULL, NULL);

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ extern const char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1
695695
extern const char *git_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
696696
extern const char *git_path_submodule(const char *path, const char *fmt, ...)
697697
__attribute__((format (printf, 2, 3)));
698+
extern void report_linked_checkout_garbage(void);
698699

699700
/*
700701
* Return the name of the file in the local object database that would

path.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "cache.h"
55
#include "strbuf.h"
66
#include "string-list.h"
7+
#include "dir.h"
78

89
static int get_st_mode_bits(const char *path, int *mode)
910
{
@@ -91,9 +92,9 @@ static void replace_dir(struct strbuf *buf, int len, const char *newdir)
9192
}
9293

9394
static const char *common_list[] = {
94-
"/branches", "/hooks", "/info", "/logs", "/lost-found", "/modules",
95+
"/branches", "/hooks", "/info", "!/logs", "/lost-found", "/modules",
9596
"/objects", "/refs", "/remotes", "/worktrees", "/rr-cache", "/svn",
96-
"config", "gc.pid", "packed-refs", "shallow",
97+
"config", "!gc.pid", "packed-refs", "shallow",
9798
NULL
9899
};
99100

@@ -107,6 +108,8 @@ static void update_common_dir(struct strbuf *buf, int git_dir_len)
107108
for (p = common_list; *p; p++) {
108109
const char *path = *p;
109110
int is_dir = 0;
111+
if (*path == '!')
112+
path++;
110113
if (*path == '/') {
111114
path++;
112115
is_dir = 1;
@@ -122,6 +125,28 @@ static void update_common_dir(struct strbuf *buf, int git_dir_len)
122125
}
123126
}
124127

128+
void report_linked_checkout_garbage(void)
129+
{
130+
struct strbuf sb = STRBUF_INIT;
131+
const char **p;
132+
int len;
133+
134+
if (!git_common_dir_env)
135+
return;
136+
strbuf_addf(&sb, "%s/", get_git_dir());
137+
len = sb.len;
138+
for (p = common_list; *p; p++) {
139+
const char *path = *p;
140+
if (*path == '!')
141+
continue;
142+
strbuf_setlen(&sb, len);
143+
strbuf_addstr(&sb, path);
144+
if (file_exists(sb.buf))
145+
report_garbage("unused in linked checkout", sb.buf);
146+
}
147+
strbuf_release(&sb);
148+
}
149+
125150
static void adjust_git_path(struct strbuf *buf, int git_dir_len)
126151
{
127152
const char *base = buf->buf + git_dir_len;

0 commit comments

Comments
 (0)