@@ -238,6 +238,7 @@ struct repo_structure {
238238
239239struct stats_table {
240240 struct string_list rows ;
241+ struct string_list annotations ;
241242
242243 int name_col_width ;
243244 int value_col_width ;
@@ -250,6 +251,8 @@ struct stats_table {
250251struct stats_table_entry {
251252 char * value ;
252253 const char * unit ;
254+ size_t index ;
255+ struct object_id * oid ;
253256};
254257
255258static void stats_table_vaddf (struct stats_table * table ,
@@ -272,6 +275,12 @@ static void stats_table_vaddf(struct stats_table *table,
272275 table -> name_col_width = name_width ;
273276 if (!entry )
274277 return ;
278+ if (entry -> oid ) {
279+ entry -> index = table -> annotations .nr + 1 ;
280+ strbuf_addf (& buf , "[%" PRIuMAX "] %s" , (uintmax_t )entry -> index ,
281+ oid_to_hex (entry -> oid ));
282+ string_list_append_nodup (& table -> annotations , strbuf_detach (& buf , NULL ));
283+ }
275284 if (entry -> value ) {
276285 int value_width = utf8_strwidth (entry -> value );
277286 if (value_width > table -> value_col_width )
@@ -282,6 +291,8 @@ static void stats_table_vaddf(struct stats_table *table,
282291 if (unit_width > table -> unit_col_width )
283292 table -> unit_col_width = unit_width ;
284293 }
294+
295+ strbuf_release (& buf );
285296}
286297
287298static void stats_table_addf (struct stats_table * table , const char * format , ...)
@@ -321,6 +332,27 @@ static void stats_table_size_addf(struct stats_table *table, size_t value,
321332 va_end (ap );
322333}
323334
335+ static void stats_table_object_size_addf (struct stats_table * table ,
336+ struct object_id * oid , size_t value ,
337+ const char * format , ...)
338+ {
339+ struct stats_table_entry * entry ;
340+ va_list ap ;
341+
342+ CALLOC_ARRAY (entry , 1 );
343+ humanise_bytes (value , & entry -> value , & entry -> unit , HUMANISE_COMPACT );
344+
345+ /*
346+ * A NULL OID should not have a table annotation.
347+ */
348+ if (!is_null_oid (oid ))
349+ entry -> oid = oid ;
350+
351+ va_start (ap , format );
352+ stats_table_vaddf (table , entry , format , ap );
353+ va_end (ap );
354+ }
355+
324356static inline size_t get_total_reference_count (struct ref_stats * stats )
325357{
326358 return stats -> branches + stats -> remotes + stats -> tags + stats -> others ;
@@ -389,19 +421,29 @@ static void stats_table_setup_structure(struct stats_table *table,
389421 stats_table_addf (table , "" );
390422 stats_table_addf (table , "* %s" , _ ("Largest objects" ));
391423 stats_table_addf (table , " * %s" , _ ("Commits" ));
392- stats_table_size_addf (table , objects -> largest .commit_size .value ,
393- " * %s" , _ ("Maximum size" ));
424+ stats_table_object_size_addf (table ,
425+ & objects -> largest .commit_size .oid ,
426+ objects -> largest .commit_size .value ,
427+ " * %s" , _ ("Maximum size" ));
394428 stats_table_addf (table , " * %s" , _ ("Trees" ));
395- stats_table_size_addf (table , objects -> largest .tree_size .value ,
396- " * %s" , _ ("Maximum size" ));
429+ stats_table_object_size_addf (table ,
430+ & objects -> largest .tree_size .oid ,
431+ objects -> largest .tree_size .value ,
432+ " * %s" , _ ("Maximum size" ));
397433 stats_table_addf (table , " * %s" , _ ("Blobs" ));
398- stats_table_size_addf (table , objects -> largest .blob_size .value ,
399- " * %s" , _ ("Maximum size" ));
434+ stats_table_object_size_addf (table ,
435+ & objects -> largest .blob_size .oid ,
436+ objects -> largest .blob_size .value ,
437+ " * %s" , _ ("Maximum size" ));
400438 stats_table_addf (table , " * %s" , _ ("Tags" ));
401- stats_table_size_addf (table , objects -> largest .tag_size .value ,
402- " * %s" , _ ("Maximum size" ));
439+ stats_table_object_size_addf (table ,
440+ & objects -> largest .tag_size .oid ,
441+ objects -> largest .tag_size .value ,
442+ " * %s" , _ ("Maximum size" ));
403443}
404444
445+ #define INDEX_WIDTH 4
446+
405447static void stats_table_print_structure (const struct stats_table * table )
406448{
407449 const char * name_col_title = _ ("Repository structure" );
@@ -420,15 +462,16 @@ static void stats_table_print_structure(const struct stats_table *table)
420462 value_col_width = title_value_width - unit_col_width ;
421463
422464 strbuf_addstr (& buf , "| " );
423- strbuf_utf8_align (& buf , ALIGN_LEFT , name_col_width , name_col_title );
465+ strbuf_utf8_align (& buf , ALIGN_LEFT , name_col_width + INDEX_WIDTH ,
466+ name_col_title );
424467 strbuf_addstr (& buf , " | " );
425468 strbuf_utf8_align (& buf , ALIGN_LEFT ,
426469 value_col_width + unit_col_width + 1 , value_col_title );
427470 strbuf_addstr (& buf , " |" );
428471 printf ("%s\n" , buf .buf );
429472
430473 printf ("| " );
431- for (int i = 0 ; i < name_col_width ; i ++ )
474+ for (int i = 0 ; i < name_col_width + INDEX_WIDTH ; i ++ )
432475 putchar ('-' );
433476 printf (" | " );
434477 for (int i = 0 ; i < value_col_width + unit_col_width + 1 ; i ++ )
@@ -450,6 +493,13 @@ static void stats_table_print_structure(const struct stats_table *table)
450493 strbuf_reset (& buf );
451494 strbuf_addstr (& buf , "| " );
452495 strbuf_utf8_align (& buf , ALIGN_LEFT , name_col_width , item -> string );
496+
497+ if (entry && entry -> oid )
498+ strbuf_addf (& buf , " [%" PRIuMAX "]" ,
499+ (uintmax_t )entry -> index );
500+ else
501+ strbuf_addchars (& buf , ' ' , INDEX_WIDTH );
502+
453503 strbuf_addstr (& buf , " | " );
454504 strbuf_utf8_align (& buf , ALIGN_RIGHT , value_col_width , value );
455505 strbuf_addch (& buf , ' ' );
@@ -458,6 +508,12 @@ static void stats_table_print_structure(const struct stats_table *table)
458508 printf ("%s\n" , buf .buf );
459509 }
460510
511+ if (table -> annotations .nr ) {
512+ printf ("\n" );
513+ for_each_string_list_item (item , & table -> annotations )
514+ printf ("%s\n" , item -> string );
515+ }
516+
461517 strbuf_release (& buf );
462518}
463519
@@ -473,6 +529,7 @@ static void stats_table_clear(struct stats_table *table)
473529 }
474530
475531 string_list_clear (& table -> rows , 1 );
532+ string_list_clear (& table -> annotations , 1 );
476533}
477534
478535static inline void print_keyvalue (const char * key , char key_delim , size_t value ,
@@ -702,6 +759,7 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,
702759{
703760 struct stats_table table = {
704761 .rows = STRING_LIST_INIT_DUP ,
762+ .annotations = STRING_LIST_INIT_DUP ,
705763 };
706764 enum output_format format = FORMAT_TABLE ;
707765 struct repo_structure stats = { 0 };
0 commit comments