@@ -74,6 +74,39 @@ static int dir_file_stats(struct object_directory *object_dir, void *data)
74
74
return 0 ;
75
75
}
76
76
77
+ static void dir_stats (struct strbuf * buf , const char * path )
78
+ {
79
+ DIR * dir = opendir (path );
80
+ struct dirent * e ;
81
+ struct stat e_stat ;
82
+ struct strbuf file_path = STRBUF_INIT ;
83
+ size_t base_path_len ;
84
+
85
+ if (!dir )
86
+ return ;
87
+
88
+ strbuf_addstr (buf , "Contents of " );
89
+ strbuf_add_absolute_path (buf , path );
90
+ strbuf_addstr (buf , ":\n" );
91
+
92
+ strbuf_add_absolute_path (& file_path , path );
93
+ strbuf_addch (& file_path , '/' );
94
+ base_path_len = file_path .len ;
95
+
96
+ while ((e = readdir (dir )) != NULL )
97
+ if (!is_dot_or_dotdot (e -> d_name ) && e -> d_type == DT_REG ) {
98
+ strbuf_setlen (& file_path , base_path_len );
99
+ strbuf_addstr (& file_path , e -> d_name );
100
+ if (!stat (file_path .buf , & e_stat ))
101
+ strbuf_addf (buf , "%-70s %16" PRIuMAX "\n" ,
102
+ e -> d_name ,
103
+ (uintmax_t )e_stat .st_size );
104
+ }
105
+
106
+ strbuf_release (& file_path );
107
+ closedir (dir );
108
+ }
109
+
77
110
static int count_files (struct strbuf * path )
78
111
{
79
112
DIR * dir = opendir (path -> buf );
@@ -187,7 +220,7 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
187
220
char * * argv_copy = NULL ;
188
221
int stdout_fd = -1 , archiver_fd = -1 ;
189
222
char * cache_server_url = NULL , * shared_cache = NULL ;
190
- struct strbuf buf = STRBUF_INIT ;
223
+ struct strbuf buf = STRBUF_INIT , path = STRBUF_INIT ;
191
224
int res , i ;
192
225
struct archive_dir archive_dirs [] = {
193
226
{ ".git" , 0 },
@@ -259,6 +292,52 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
259
292
}
260
293
}
261
294
295
+ if (shared_cache ) {
296
+ size_t path_len ;
297
+
298
+ strbuf_reset (& buf );
299
+ strbuf_addf (& path , "%s/pack" , shared_cache );
300
+ strbuf_reset (& buf );
301
+ strbuf_addstr (& buf , "--add-virtual-file=packs-cached.txt:" );
302
+ dir_stats (& buf , path .buf );
303
+ strvec_push (& archiver_args , buf .buf );
304
+
305
+ strbuf_reset (& buf );
306
+ strbuf_addstr (& buf , "--add-virtual-file=objects-cached.txt:" );
307
+ loose_objs_stats (& buf , shared_cache );
308
+ strvec_push (& archiver_args , buf .buf );
309
+
310
+ strbuf_reset (& path );
311
+ strbuf_addf (& path , "%s/info" , shared_cache );
312
+ path_len = path .len ;
313
+
314
+ if (is_directory (path .buf )) {
315
+ DIR * dir = opendir (path .buf );
316
+ struct dirent * e ;
317
+
318
+ while ((e = readdir (dir ))) {
319
+ if (!strcmp ("." , e -> d_name ) || !strcmp (".." , e -> d_name ))
320
+ continue ;
321
+ if (e -> d_type == DT_DIR )
322
+ continue ;
323
+
324
+ strbuf_reset (& buf );
325
+ strbuf_addf (& buf , "--add-virtual-file=info/%s:" , e -> d_name );
326
+
327
+ strbuf_setlen (& path , path_len );
328
+ strbuf_addch (& path , '/' );
329
+ strbuf_addstr (& path , e -> d_name );
330
+
331
+ if (strbuf_read_file (& buf , path .buf , 0 ) < 0 ) {
332
+ res = error_errno (_ ("could not read '%s'" ), path .buf );
333
+ goto diagnose_cleanup ;
334
+ }
335
+ strvec_push (& archiver_args , buf .buf );
336
+ }
337
+ closedir (dir );
338
+ }
339
+ }
340
+
262
341
strvec_pushl (& archiver_args , "--prefix=" ,
263
342
oid_to_hex (the_hash_algo -> empty_tree ), "--" , NULL );
264
343
0 commit comments