@@ -80,7 +80,6 @@ struct survey_report_object_size_summary {
80
80
81
81
typedef int (* survey_top_cmp )(void * v1 , void * v2 );
82
82
83
- MAYBE_UNUSED
84
83
static int cmp_by_nr (void * v1 , void * v2 )
85
84
{
86
85
struct survey_report_object_size_summary * s1 = v1 ;
@@ -93,7 +92,6 @@ static int cmp_by_nr(void *v1, void *v2)
93
92
return 0 ;
94
93
}
95
94
96
- MAYBE_UNUSED
97
95
static int cmp_by_disk_size (void * v1 , void * v2 )
98
96
{
99
97
struct survey_report_object_size_summary * s1 = v1 ;
@@ -106,7 +104,6 @@ static int cmp_by_disk_size(void *v1, void *v2)
106
104
return 0 ;
107
105
}
108
106
109
- MAYBE_UNUSED
110
107
static int cmp_by_inflated_size (void * v1 , void * v2 )
111
108
{
112
109
struct survey_report_object_size_summary * s1 = v1 ;
@@ -137,7 +134,6 @@ struct survey_report_top_table {
137
134
void * data ;
138
135
};
139
136
140
- MAYBE_UNUSED
141
137
static void init_top_sizes (struct survey_report_top_table * top ,
142
138
size_t limit , const char * name ,
143
139
survey_top_cmp cmp )
@@ -163,7 +159,6 @@ static void clear_top_sizes(struct survey_report_top_table *top)
163
159
free (sz_array );
164
160
}
165
161
166
- MAYBE_UNUSED
167
162
static void maybe_insert_into_top_size (struct survey_report_top_table * top ,
168
163
struct survey_report_object_size_summary * summary )
169
164
{
@@ -200,6 +195,10 @@ struct survey_report {
200
195
struct survey_report_object_summary reachable_objects ;
201
196
202
197
struct survey_report_object_size_summary * by_type ;
198
+
199
+ struct survey_report_top_table * top_paths_by_count ;
200
+ struct survey_report_top_table * top_paths_by_disk ;
201
+ struct survey_report_top_table * top_paths_by_inflate ;
203
202
};
204
203
205
204
#define REPORT_TYPE_COMMIT 0
@@ -451,6 +450,13 @@ static void survey_report_object_sizes(const char *title,
451
450
clear_table (& table );
452
451
}
453
452
453
+ static void survey_report_plaintext_sorted_size (
454
+ struct survey_report_top_table * top )
455
+ {
456
+ survey_report_object_sizes (top -> name , _ ("Path" ),
457
+ top -> data , top -> nr );
458
+ }
459
+
454
460
static void survey_report_plaintext (struct survey_context * ctx )
455
461
{
456
462
printf ("GIT SURVEY for \"%s\"\n" , ctx -> repo -> worktree );
@@ -461,6 +467,21 @@ static void survey_report_plaintext(struct survey_context *ctx)
461
467
_ ("Object Type" ),
462
468
ctx -> report .by_type ,
463
469
REPORT_TYPE_COUNT );
470
+
471
+ survey_report_plaintext_sorted_size (
472
+ & ctx -> report .top_paths_by_count [REPORT_TYPE_TREE ]);
473
+ survey_report_plaintext_sorted_size (
474
+ & ctx -> report .top_paths_by_count [REPORT_TYPE_BLOB ]);
475
+
476
+ survey_report_plaintext_sorted_size (
477
+ & ctx -> report .top_paths_by_disk [REPORT_TYPE_TREE ]);
478
+ survey_report_plaintext_sorted_size (
479
+ & ctx -> report .top_paths_by_disk [REPORT_TYPE_BLOB ]);
480
+
481
+ survey_report_plaintext_sorted_size (
482
+ & ctx -> report .top_paths_by_inflate [REPORT_TYPE_TREE ]);
483
+ survey_report_plaintext_sorted_size (
484
+ & ctx -> report .top_paths_by_inflate [REPORT_TYPE_BLOB ]);
464
485
}
465
486
466
487
/*
@@ -701,7 +722,8 @@ static void increment_totals(struct survey_context *ctx,
701
722
702
723
static void increment_object_totals (struct survey_context * ctx ,
703
724
struct oid_array * oids ,
704
- enum object_type type )
725
+ enum object_type type ,
726
+ const char * path )
705
727
{
706
728
struct survey_report_object_size_summary * total ;
707
729
struct survey_report_object_size_summary summary = { 0 };
@@ -733,9 +755,30 @@ static void increment_object_totals(struct survey_context *ctx,
733
755
total -> disk_size += summary .disk_size ;
734
756
total -> inflated_size += summary .inflated_size ;
735
757
total -> num_missing += summary .num_missing ;
758
+
759
+ if (type == OBJ_TREE || type == OBJ_BLOB ) {
760
+ int index = type == OBJ_TREE ?
761
+ REPORT_TYPE_TREE : REPORT_TYPE_BLOB ;
762
+ struct survey_report_top_table * top ;
763
+
764
+ /*
765
+ * Temporarily store (const char *) here, but it will
766
+ * be duped if inserted and will not be freed.
767
+ */
768
+ summary .label = (char * )path ;
769
+
770
+ top = ctx -> report .top_paths_by_count ;
771
+ maybe_insert_into_top_size (& top [index ], & summary );
772
+
773
+ top = ctx -> report .top_paths_by_disk ;
774
+ maybe_insert_into_top_size (& top [index ], & summary );
775
+
776
+ top = ctx -> report .top_paths_by_inflate ;
777
+ maybe_insert_into_top_size (& top [index ], & summary );
778
+ }
736
779
}
737
780
738
- static int survey_objects_path_walk_fn (const char * path UNUSED ,
781
+ static int survey_objects_path_walk_fn (const char * path ,
739
782
struct oid_array * oids ,
740
783
enum object_type type ,
741
784
void * data )
@@ -744,7 +787,7 @@ static int survey_objects_path_walk_fn(const char *path UNUSED,
744
787
745
788
increment_object_counts (& ctx -> report .reachable_objects ,
746
789
type , oids -> nr );
747
- increment_object_totals (ctx , oids , type );
790
+ increment_object_totals (ctx , oids , type , path );
748
791
749
792
ctx -> progress_nr += oids -> nr ;
750
793
display_progress (ctx -> progress , ctx -> progress_nr );
@@ -754,11 +797,31 @@ static int survey_objects_path_walk_fn(const char *path UNUSED,
754
797
755
798
static void initialize_report (struct survey_context * ctx )
756
799
{
800
+ const int top_limit = 100 ;
801
+
757
802
CALLOC_ARRAY (ctx -> report .by_type , REPORT_TYPE_COUNT );
758
803
ctx -> report .by_type [REPORT_TYPE_COMMIT ].label = xstrdup (_ ("Commits" ));
759
804
ctx -> report .by_type [REPORT_TYPE_TREE ].label = xstrdup (_ ("Trees" ));
760
805
ctx -> report .by_type [REPORT_TYPE_BLOB ].label = xstrdup (_ ("Blobs" ));
761
806
ctx -> report .by_type [REPORT_TYPE_TAG ].label = xstrdup (_ ("Tags" ));
807
+
808
+ CALLOC_ARRAY (ctx -> report .top_paths_by_count , REPORT_TYPE_COUNT );
809
+ init_top_sizes (& ctx -> report .top_paths_by_count [REPORT_TYPE_TREE ],
810
+ top_limit , _ ("TOP DIRECTORIES BY COUNT" ), cmp_by_nr );
811
+ init_top_sizes (& ctx -> report .top_paths_by_count [REPORT_TYPE_BLOB ],
812
+ top_limit , _ ("TOP FILES BY COUNT" ), cmp_by_nr );
813
+
814
+ CALLOC_ARRAY (ctx -> report .top_paths_by_disk , REPORT_TYPE_COUNT );
815
+ init_top_sizes (& ctx -> report .top_paths_by_disk [REPORT_TYPE_TREE ],
816
+ top_limit , _ ("TOP DIRECTORIES BY DISK SIZE" ), cmp_by_disk_size );
817
+ init_top_sizes (& ctx -> report .top_paths_by_disk [REPORT_TYPE_BLOB ],
818
+ top_limit , _ ("TOP FILES BY DISK SIZE" ), cmp_by_disk_size );
819
+
820
+ CALLOC_ARRAY (ctx -> report .top_paths_by_inflate , REPORT_TYPE_COUNT );
821
+ init_top_sizes (& ctx -> report .top_paths_by_inflate [REPORT_TYPE_TREE ],
822
+ top_limit , _ ("TOP DIRECTORIES BY INFLATED SIZE" ), cmp_by_inflated_size );
823
+ init_top_sizes (& ctx -> report .top_paths_by_inflate [REPORT_TYPE_BLOB ],
824
+ top_limit , _ ("TOP FILES BY INFLATED SIZE" ), cmp_by_inflated_size );
762
825
}
763
826
764
827
static void survey_phase_objects (struct survey_context * ctx )
0 commit comments