@@ -992,6 +992,39 @@ static int dir_file_stats(struct object_directory *object_dir, void *data)
992992 return 0 ;
993993}
994994
995+ static void dir_stats (struct strbuf * buf , const char * path )
996+ {
997+ DIR * dir = opendir (path );
998+ struct dirent * e ;
999+ struct stat e_stat ;
1000+ struct strbuf file_path = STRBUF_INIT ;
1001+ size_t base_path_len ;
1002+
1003+ if (!dir )
1004+ return ;
1005+
1006+ strbuf_addstr (buf , "Contents of " );
1007+ strbuf_add_absolute_path (buf , path );
1008+ strbuf_addstr (buf , ":\n" );
1009+
1010+ strbuf_add_absolute_path (& file_path , path );
1011+ strbuf_addch (& file_path , '/' );
1012+ base_path_len = file_path .len ;
1013+
1014+ while ((e = readdir (dir )) != NULL )
1015+ if (!is_dot_or_dotdot (e -> d_name ) && e -> d_type == DT_REG ) {
1016+ strbuf_setlen (& file_path , base_path_len );
1017+ strbuf_addstr (& file_path , e -> d_name );
1018+ if (!stat (file_path .buf , & e_stat ))
1019+ strbuf_addf (buf , "%-70s %16" PRIuMAX "\n" ,
1020+ e -> d_name ,
1021+ (uintmax_t )e_stat .st_size );
1022+ }
1023+
1024+ strbuf_release (& file_path );
1025+ closedir (dir );
1026+ }
1027+
9951028static int count_files (char * path )
9961029{
9971030 DIR * dir = opendir (path );
@@ -1133,6 +1166,39 @@ static int cmd_diagnose(int argc, const char **argv)
11331166 (res = add_directory_to_archiver (& archiver_args , ".git/objects/info" , 0 )))
11341167 goto diagnose_cleanup ;
11351168
1169+ if (shared_cache ) {
1170+ strbuf_reset (& buf );
1171+ strbuf_addf (& path , "%s/pack" , shared_cache );
1172+ strbuf_reset (& buf );
1173+ strbuf_addstr (& buf , "--add-virtual-file=packs-cached.txt:" );
1174+ dir_stats (& buf , path .buf );
1175+ strvec_push (& archiver_args , buf .buf );
1176+
1177+ strbuf_reset (& buf );
1178+ strbuf_addstr (& buf , "--add-virtual-file=objects-cached.txt:" );
1179+ loose_objs_stats (& buf , shared_cache );
1180+ strvec_push (& archiver_args , buf .buf );
1181+
1182+ strbuf_reset (& path );
1183+ strbuf_addf (& path , "%s/info" , shared_cache );
1184+ if (is_directory (path .buf )) {
1185+ DIR * dir = opendir (path .buf );
1186+ struct dirent * e ;
1187+
1188+ while ((e = readdir (dir ))) {
1189+ if (!strcmp ("." , e -> d_name ) || !strcmp (".." , e -> d_name ))
1190+ continue ;
1191+
1192+ strbuf_reset (& buf );
1193+ strbuf_addf (& buf , "--add-virtual-file=info/%s:" , e -> d_name );
1194+ if (strbuf_read_file (& buf , path .buf , 0 ) < 0 )
1195+ goto diagnose_cleanup ;
1196+ strvec_push (& archiver_args , buf .buf );
1197+ }
1198+ closedir (dir );
1199+ }
1200+ }
1201+
11361202 strvec_pushl (& archiver_args , "--prefix=" ,
11371203 oid_to_hex (the_hash_algo -> empty_tree ), "--" , NULL );
11381204
0 commit comments