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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Nov 30, 2014 at 15:24 UTC
77a6d84045c8b558d1e08ff2ffe70347b19be6ef
3 files changed
+31
-3
builtin/count-objects.c
+3
-1
@@ -70,8 +70,10 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
70
/* we do not take arguments other than flags for now */
71
if (argc)
72
usage_with_options(count_objects_usage, opts);
73
- if (verbose)
73
+ if (verbose) {
74
report_garbage = real_report_garbage;
75
+ report_linked_checkout_garbage();
76
+ }
77
78
for_each_loose_file_in_objdir(get_object_directory(),
79
count_loose, count_cruft, NULL, NULL);
cache.h
+1
@@ -695,6 +695,7 @@ extern const char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1
695
extern const char *git_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
696
extern const char *git_path_submodule(const char *path, const char *fmt, ...)
697
__attribute__((format (printf, 2, 3)));
698
+extern void report_linked_checkout_garbage(void);
699
700
/*
701
* Return the name of the file in the local object database that would
path.c
+27
-2
@@ -4,6 +4,7 @@
4
#include "cache.h"
5
#include "strbuf.h"
6
#include "string-list.h"
7
+#include "dir.h"
8
9
static int get_st_mode_bits(const char *path, int *mode)
10
{
@@ -91,9 +92,9 @@ static void replace_dir(struct strbuf *buf, int len, const char *newdir)
92
}
93
94
static const char *common_list[] = {
94
- "/branches", "/hooks", "/info", "/logs", "/lost-found", "/modules",
95
+ "/branches", "/hooks", "/info", "!/logs", "/lost-found", "/modules",
96
"/objects", "/refs", "/remotes", "/worktrees", "/rr-cache", "/svn",
96
- "config", "gc.pid", "packed-refs", "shallow",
97
+ "config", "!gc.pid", "packed-refs", "shallow",
98
NULL
99
};
100
@@ -107,6 +108,8 @@ static void update_common_dir(struct strbuf *buf, int git_dir_len)
108
for (p = common_list; *p; p++) {
109
const char *path = *p;
110
int is_dir = 0;
111
+ if (*path == '!')
112
+ path++;
113
if (*path == '/') {
114
path++;
115
is_dir = 1;
@@ -122,6 +125,28 @@ static void update_common_dir(struct strbuf *buf, int git_dir_len)
125
}
126
}
127
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
+
150
static void adjust_git_path(struct strbuf *buf, int git_dir_len)
151
{
152
const char *base = buf->buf + git_dir_len;