@@ -46,6 +46,7 @@ static const char rev_list_usage[] =
46
46
" --parents\n"
47
47
" --children\n"
48
48
" --objects | --objects-edge\n"
49
+ " --disk-usage[=human]\n"
49
50
" --unpacked\n"
50
51
" --header | --pretty\n"
51
52
" --[no-]object-names\n"
@@ -81,6 +82,7 @@ static int arg_show_object_names = 1;
81
82
82
83
static int show_disk_usage ;
83
84
static off_t total_disk_usage ;
85
+ static int human_readable ;
84
86
85
87
static off_t get_object_disk_usage (struct object * obj )
86
88
{
@@ -368,6 +370,17 @@ static int show_object_fast(
368
370
return 1 ;
369
371
}
370
372
373
+ static void print_disk_usage (off_t size )
374
+ {
375
+ struct strbuf sb = STRBUF_INIT ;
376
+ if (human_readable )
377
+ strbuf_humanise_bytes (& sb , size );
378
+ else
379
+ strbuf_addf (& sb , "%" PRIuMAX , (uintmax_t )size );
380
+ puts (sb .buf );
381
+ strbuf_release (& sb );
382
+ }
383
+
371
384
static inline int parse_missing_action_value (const char * value )
372
385
{
373
386
if (!strcmp (value , "error" )) {
@@ -473,6 +486,7 @@ static int try_bitmap_disk_usage(struct rev_info *revs,
473
486
int filter_provided_objects )
474
487
{
475
488
struct bitmap_index * bitmap_git ;
489
+ off_t size_from_bitmap ;
476
490
477
491
if (!show_disk_usage )
478
492
return -1 ;
@@ -481,8 +495,8 @@ static int try_bitmap_disk_usage(struct rev_info *revs,
481
495
if (!bitmap_git )
482
496
return -1 ;
483
497
484
- printf ( "%" PRIuMAX "\n" ,
485
- ( uintmax_t ) get_disk_usage_from_bitmap ( bitmap_git , revs ) );
498
+ size_from_bitmap = get_disk_usage_from_bitmap ( bitmap_git , revs );
499
+ print_disk_usage ( size_from_bitmap );
486
500
return 0 ;
487
501
}
488
502
@@ -624,7 +638,21 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
624
638
continue ;
625
639
}
626
640
627
- if (!strcmp (arg , "--disk-usage" )) {
641
+ if (skip_prefix (arg , "--disk-usage" , & arg )) {
642
+ if (* arg == '=' ) {
643
+ if (!strcmp (++ arg , "human" )) {
644
+ human_readable = 1 ;
645
+ } else
646
+ die (_ ("invalid value for '%s': '%s', the only allowed format is '%s'" ),
647
+ "--disk-usage=<format>" , arg , "human" );
648
+ } else if (* arg ) {
649
+ /*
650
+ * Arguably should goto a label to continue chain of ifs?
651
+ * Doesn't matter unless we try to add --disk-usage-foo
652
+ * afterwards.
653
+ */
654
+ usage (rev_list_usage );
655
+ }
628
656
show_disk_usage = 1 ;
629
657
info .flags |= REV_LIST_QUIET ;
630
658
continue ;
@@ -753,7 +781,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
753
781
}
754
782
755
783
if (show_disk_usage )
756
- printf ( "%" PRIuMAX "\n" , ( uintmax_t ) total_disk_usage );
784
+ print_disk_usage ( total_disk_usage );
757
785
758
786
cleanup :
759
787
release_revisions (& revs );
0 commit comments