@@ -80,6 +80,19 @@ static int arg_show_object_names = 1;
8080
8181#define DEFAULT_OIDSET_SIZE (16*1024)
8282
83+ static int show_disk_usage ;
84+ static off_t total_disk_usage ;
85+
86+ static off_t get_object_disk_usage (struct object * obj )
87+ {
88+ off_t size ;
89+ struct object_info oi = OBJECT_INFO_INIT ;
90+ oi .disk_sizep = & size ;
91+ if (oid_object_info_extended (the_repository , & obj -> oid , & oi , 0 ) < 0 )
92+ die (_ ("unable to get disk usage of %s" ), oid_to_hex (& obj -> oid ));
93+ return size ;
94+ }
95+
8396static void finish_commit (struct commit * commit );
8497static void show_commit (struct commit * commit , void * data )
8598{
@@ -88,6 +101,9 @@ static void show_commit(struct commit *commit, void *data)
88101
89102 display_progress (progress , ++ progress_counter );
90103
104+ if (show_disk_usage )
105+ total_disk_usage += get_object_disk_usage (& commit -> object );
106+
91107 if (info -> flags & REV_LIST_QUIET ) {
92108 finish_commit (commit );
93109 return ;
@@ -258,6 +274,8 @@ static void show_object(struct object *obj, const char *name, void *cb_data)
258274 if (finish_object (obj , name , cb_data ))
259275 return ;
260276 display_progress (progress , ++ progress_counter );
277+ if (show_disk_usage )
278+ total_disk_usage += get_object_disk_usage (obj );
261279 if (info -> flags & REV_LIST_QUIET )
262280 return ;
263281
@@ -452,6 +470,23 @@ static int try_bitmap_traversal(struct rev_info *revs,
452470 return 0 ;
453471}
454472
473+ static int try_bitmap_disk_usage (struct rev_info * revs ,
474+ struct list_objects_filter_options * filter )
475+ {
476+ struct bitmap_index * bitmap_git ;
477+
478+ if (!show_disk_usage )
479+ return -1 ;
480+
481+ bitmap_git = prepare_bitmap_walk (revs , filter );
482+ if (!bitmap_git )
483+ return -1 ;
484+
485+ printf ("%" PRIuMAX "\n" ,
486+ (uintmax_t )get_disk_usage_from_bitmap (bitmap_git , revs ));
487+ return 0 ;
488+ }
489+
455490int cmd_rev_list (int argc , const char * * argv , const char * prefix )
456491{
457492 struct rev_info revs ;
@@ -584,6 +619,12 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
584619 continue ;
585620 }
586621
622+ if (!strcmp (arg , "--disk-usage" )) {
623+ show_disk_usage = 1 ;
624+ info .flags |= REV_LIST_QUIET ;
625+ continue ;
626+ }
627+
587628 usage (rev_list_usage );
588629
589630 }
@@ -626,6 +667,8 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
626667 if (use_bitmap_index ) {
627668 if (!try_bitmap_count (& revs , & filter_options ))
628669 return 0 ;
670+ if (!try_bitmap_disk_usage (& revs , & filter_options ))
671+ return 0 ;
629672 if (!try_bitmap_traversal (& revs , & filter_options ))
630673 return 0 ;
631674 }
@@ -690,5 +733,8 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
690733 printf ("%d\n" , revs .count_left + revs .count_right );
691734 }
692735
736+ if (show_disk_usage )
737+ printf ("%" PRIuMAX "\n" , (uintmax_t )total_disk_usage );
738+
693739 return 0 ;
694740}
0 commit comments