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