@@ -223,13 +223,15 @@ struct stats_table {
223223
224224 int name_col_width ;
225225 int value_col_width ;
226+ int unit_col_width ;
226227};
227228
228229/*
229230 * Holds column data that gets stored for each row.
230231 */
231232struct stats_table_entry {
232233 char * value ;
234+ const char * unit ;
233235};
234236
235237static void stats_table_vaddf (struct stats_table * table ,
@@ -250,11 +252,18 @@ static void stats_table_vaddf(struct stats_table *table,
250252
251253 if (name_width > table -> name_col_width )
252254 table -> name_col_width = name_width ;
253- if (entry ) {
255+ if (!entry )
256+ return ;
257+ if (entry -> value ) {
254258 int value_width = utf8_strwidth (entry -> value );
255259 if (value_width > table -> value_col_width )
256260 table -> value_col_width = value_width ;
257261 }
262+ if (entry -> unit ) {
263+ int unit_width = utf8_strwidth (entry -> unit );
264+ if (unit_width > table -> unit_col_width )
265+ table -> unit_col_width = unit_width ;
266+ }
258267}
259268
260269static void stats_table_addf (struct stats_table * table , const char * format , ...)
@@ -273,7 +282,7 @@ static void stats_table_count_addf(struct stats_table *table, size_t value,
273282 va_list ap ;
274283
275284 CALLOC_ARRAY (entry , 1 );
276- entry -> value = xstrfmt ( "%" PRIuMAX , ( uintmax_t ) value );
285+ humanise_count ( value , & entry -> value , & entry -> unit );
277286
278287 va_start (ap , format );
279288 stats_table_vaddf (table , entry , format , ap );
@@ -324,45 +333,54 @@ static void stats_table_print_structure(const struct stats_table *table)
324333{
325334 const char * name_col_title = _ ("Repository structure" );
326335 const char * value_col_title = _ ("Value" );
327- int name_col_width = utf8_strwidth (name_col_title );
328- int value_col_width = utf8_strwidth (value_col_title );
336+ int title_name_width = utf8_strwidth (name_col_title );
337+ int title_value_width = utf8_strwidth (value_col_title );
338+ int name_col_width = table -> name_col_width ;
339+ int value_col_width = table -> value_col_width ;
340+ int unit_col_width = table -> unit_col_width ;
329341 struct string_list_item * item ;
330342 struct strbuf buf = STRBUF_INIT ;
331343
332- if (table -> name_col_width > name_col_width )
333- name_col_width = table -> name_col_width ;
334- if (table -> value_col_width > value_col_width )
335- value_col_width = table -> value_col_width ;
344+ if (title_name_width > name_col_width )
345+ name_col_width = title_name_width ;
346+ if (title_value_width > value_col_width + unit_col_width + 1 )
347+ value_col_width = title_value_width - unit_col_width ;
336348
337349 strbuf_addstr (& buf , "| " );
338350 strbuf_utf8_align (& buf , ALIGN_LEFT , name_col_width , name_col_title );
339351 strbuf_addstr (& buf , " | " );
340- strbuf_utf8_align (& buf , ALIGN_LEFT , value_col_width , value_col_title );
352+ strbuf_utf8_align (& buf , ALIGN_LEFT ,
353+ value_col_width + unit_col_width + 1 , value_col_title );
341354 strbuf_addstr (& buf , " |" );
342355 printf ("%s\n" , buf .buf );
343356
344357 printf ("| " );
345358 for (int i = 0 ; i < name_col_width ; i ++ )
346359 putchar ('-' );
347360 printf (" | " );
348- for (int i = 0 ; i < value_col_width ; i ++ )
361+ for (int i = 0 ; i < value_col_width + unit_col_width + 1 ; i ++ )
349362 putchar ('-' );
350363 printf (" |\n" );
351364
352365 for_each_string_list_item (item , & table -> rows ) {
353366 struct stats_table_entry * entry = item -> util ;
354367 const char * value = "" ;
368+ const char * unit = "" ;
355369
356370 if (entry ) {
357371 struct stats_table_entry * entry = item -> util ;
358372 value = entry -> value ;
373+ if (entry -> unit )
374+ unit = entry -> unit ;
359375 }
360376
361377 strbuf_reset (& buf );
362378 strbuf_addstr (& buf , "| " );
363379 strbuf_utf8_align (& buf , ALIGN_LEFT , name_col_width , item -> string );
364380 strbuf_addstr (& buf , " | " );
365381 strbuf_utf8_align (& buf , ALIGN_RIGHT , value_col_width , value );
382+ strbuf_addch (& buf , ' ' );
383+ strbuf_utf8_align (& buf , ALIGN_LEFT , unit_col_width , unit );
366384 strbuf_addstr (& buf , " |" );
367385 printf ("%s\n" , buf .buf );
368386 }
0 commit comments