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