@@ -75,7 +75,6 @@ struct survey_report_object_size_summary {
75
75
76
76
typedef int (* survey_top_cmp )(void * v1 , void * v2 );
77
77
78
- MAYBE_UNUSED
79
78
static int cmp_by_nr (void * v1 , void * v2 )
80
79
{
81
80
struct survey_report_object_size_summary * s1 = v1 ;
@@ -88,7 +87,6 @@ static int cmp_by_nr(void *v1, void *v2)
88
87
return 0 ;
89
88
}
90
89
91
- MAYBE_UNUSED
92
90
static int cmp_by_disk_size (void * v1 , void * v2 )
93
91
{
94
92
struct survey_report_object_size_summary * s1 = v1 ;
@@ -101,7 +99,6 @@ static int cmp_by_disk_size(void *v1, void *v2)
101
99
return 0 ;
102
100
}
103
101
104
- MAYBE_UNUSED
105
102
static int cmp_by_inflated_size (void * v1 , void * v2 )
106
103
{
107
104
struct survey_report_object_size_summary * s1 = v1 ;
@@ -132,7 +129,6 @@ struct survey_report_top_table {
132
129
void * data ;
133
130
};
134
131
135
- MAYBE_UNUSED
136
132
static void init_top_sizes (struct survey_report_top_table * top ,
137
133
size_t limit , const char * name ,
138
134
survey_top_cmp cmp )
@@ -158,7 +154,6 @@ static void clear_top_sizes(struct survey_report_top_table *top)
158
154
free (sz_array );
159
155
}
160
156
161
- MAYBE_UNUSED
162
157
static void maybe_insert_into_top_size (struct survey_report_top_table * top ,
163
158
struct survey_report_object_size_summary * summary )
164
159
{
@@ -195,6 +190,10 @@ struct survey_report {
195
190
struct survey_report_object_summary reachable_objects ;
196
191
197
192
struct survey_report_object_size_summary * by_type ;
193
+
194
+ struct survey_report_top_table * top_paths_by_count ;
195
+ struct survey_report_top_table * top_paths_by_disk ;
196
+ struct survey_report_top_table * top_paths_by_inflate ;
198
197
};
199
198
200
199
#define REPORT_TYPE_COMMIT 0
@@ -446,6 +445,13 @@ static void survey_report_object_sizes(const char *title,
446
445
clear_table (& table );
447
446
}
448
447
448
+ static void survey_report_plaintext_sorted_size (
449
+ struct survey_report_top_table * top )
450
+ {
451
+ survey_report_object_sizes (top -> name , _ ("Path" ),
452
+ top -> data , top -> nr );
453
+ }
454
+
449
455
static void survey_report_plaintext (struct survey_context * ctx )
450
456
{
451
457
printf ("GIT SURVEY for \"%s\"\n" , ctx -> repo -> worktree );
@@ -456,6 +462,21 @@ static void survey_report_plaintext(struct survey_context *ctx)
456
462
_ ("Object Type" ),
457
463
ctx -> report .by_type ,
458
464
REPORT_TYPE_COUNT );
465
+
466
+ survey_report_plaintext_sorted_size (
467
+ & ctx -> report .top_paths_by_count [REPORT_TYPE_TREE ]);
468
+ survey_report_plaintext_sorted_size (
469
+ & ctx -> report .top_paths_by_count [REPORT_TYPE_BLOB ]);
470
+
471
+ survey_report_plaintext_sorted_size (
472
+ & ctx -> report .top_paths_by_disk [REPORT_TYPE_TREE ]);
473
+ survey_report_plaintext_sorted_size (
474
+ & ctx -> report .top_paths_by_disk [REPORT_TYPE_BLOB ]);
475
+
476
+ survey_report_plaintext_sorted_size (
477
+ & ctx -> report .top_paths_by_inflate [REPORT_TYPE_TREE ]);
478
+ survey_report_plaintext_sorted_size (
479
+ & ctx -> report .top_paths_by_inflate [REPORT_TYPE_BLOB ]);
459
480
}
460
481
461
482
/*
@@ -697,7 +718,8 @@ static void increment_totals(struct survey_context *ctx,
697
718
698
719
static void increment_object_totals (struct survey_context * ctx ,
699
720
struct oid_array * oids ,
700
- enum object_type type )
721
+ enum object_type type ,
722
+ const char * path )
701
723
{
702
724
struct survey_report_object_size_summary * total ;
703
725
struct survey_report_object_size_summary summary = { 0 };
@@ -729,6 +751,27 @@ static void increment_object_totals(struct survey_context *ctx,
729
751
total -> disk_size += summary .disk_size ;
730
752
total -> inflated_size += summary .inflated_size ;
731
753
total -> num_missing += summary .num_missing ;
754
+
755
+ if (type == OBJ_TREE || type == OBJ_BLOB ) {
756
+ int index = type == OBJ_TREE ?
757
+ REPORT_TYPE_TREE : REPORT_TYPE_BLOB ;
758
+ struct survey_report_top_table * top ;
759
+
760
+ /*
761
+ * Temporarily store (const char *) here, but it will
762
+ * be duped if inserted and will not be freed.
763
+ */
764
+ summary .label = (char * )path ;
765
+
766
+ top = ctx -> report .top_paths_by_count ;
767
+ maybe_insert_into_top_size (& top [index ], & summary );
768
+
769
+ top = ctx -> report .top_paths_by_disk ;
770
+ maybe_insert_into_top_size (& top [index ], & summary );
771
+
772
+ top = ctx -> report .top_paths_by_inflate ;
773
+ maybe_insert_into_top_size (& top [index ], & summary );
774
+ }
732
775
}
733
776
734
777
static int survey_objects_path_walk_fn (const char * path ,
@@ -740,7 +783,7 @@ static int survey_objects_path_walk_fn(const char *path,
740
783
741
784
increment_object_counts (& ctx -> report .reachable_objects ,
742
785
type , oids -> nr );
743
- increment_object_totals (ctx , oids , type );
786
+ increment_object_totals (ctx , oids , type , path );
744
787
745
788
ctx -> progress_nr += oids -> nr ;
746
789
display_progress (ctx -> progress , ctx -> progress_nr );
@@ -750,11 +793,31 @@ static int survey_objects_path_walk_fn(const char *path,
750
793
751
794
static void initialize_report (struct survey_context * ctx )
752
795
{
796
+ const int top_limit = 100 ;
797
+
753
798
CALLOC_ARRAY (ctx -> report .by_type , REPORT_TYPE_COUNT );
754
799
ctx -> report .by_type [REPORT_TYPE_COMMIT ].label = xstrdup (_ ("Commits" ));
755
800
ctx -> report .by_type [REPORT_TYPE_TREE ].label = xstrdup (_ ("Trees" ));
756
801
ctx -> report .by_type [REPORT_TYPE_BLOB ].label = xstrdup (_ ("Blobs" ));
757
802
ctx -> report .by_type [REPORT_TYPE_TAG ].label = xstrdup (_ ("Tags" ));
803
+
804
+ CALLOC_ARRAY (ctx -> report .top_paths_by_count , REPORT_TYPE_COUNT );
805
+ init_top_sizes (& ctx -> report .top_paths_by_count [REPORT_TYPE_TREE ],
806
+ top_limit , _ ("TOP DIRECTORIES BY COUNT" ), cmp_by_nr );
807
+ init_top_sizes (& ctx -> report .top_paths_by_count [REPORT_TYPE_BLOB ],
808
+ top_limit , _ ("TOP FILES BY COUNT" ), cmp_by_nr );
809
+
810
+ CALLOC_ARRAY (ctx -> report .top_paths_by_disk , REPORT_TYPE_COUNT );
811
+ init_top_sizes (& ctx -> report .top_paths_by_disk [REPORT_TYPE_TREE ],
812
+ top_limit , _ ("TOP DIRECTORIES BY DISK SIZE" ), cmp_by_disk_size );
813
+ init_top_sizes (& ctx -> report .top_paths_by_disk [REPORT_TYPE_BLOB ],
814
+ top_limit , _ ("TOP FILES BY DISK SIZE" ), cmp_by_disk_size );
815
+
816
+ CALLOC_ARRAY (ctx -> report .top_paths_by_inflate , REPORT_TYPE_COUNT );
817
+ init_top_sizes (& ctx -> report .top_paths_by_inflate [REPORT_TYPE_TREE ],
818
+ top_limit , _ ("TOP DIRECTORIES BY INFLATED SIZE" ), cmp_by_inflated_size );
819
+ init_top_sizes (& ctx -> report .top_paths_by_inflate [REPORT_TYPE_BLOB ],
820
+ top_limit , _ ("TOP FILES BY INFLATED SIZE" ), cmp_by_inflated_size );
758
821
}
759
822
760
823
static void survey_phase_objects (struct survey_context * ctx )
0 commit comments