@@ -80,7 +80,6 @@ struct survey_report_object_size_summary {
80
80
typedef int (* survey_top_size_cmp )(struct survey_report_object_size_summary * s1 ,
81
81
struct survey_report_object_size_summary * s2 );
82
82
83
- MAYBE_UNUSED
84
83
static int cmp_by_nr (struct survey_report_object_size_summary * s1 ,
85
84
struct survey_report_object_size_summary * s2 )
86
85
{
@@ -91,7 +90,6 @@ static int cmp_by_nr(struct survey_report_object_size_summary *s1,
91
90
return 0 ;
92
91
}
93
92
94
- MAYBE_UNUSED
95
93
static int cmp_by_disk_size (struct survey_report_object_size_summary * s1 ,
96
94
struct survey_report_object_size_summary * s2 )
97
95
{
@@ -102,7 +100,6 @@ static int cmp_by_disk_size(struct survey_report_object_size_summary *s1,
102
100
return 0 ;
103
101
}
104
102
105
- MAYBE_UNUSED
106
103
static int cmp_by_inflated_size (struct survey_report_object_size_summary * s1 ,
107
104
struct survey_report_object_size_summary * s2 )
108
105
{
@@ -126,7 +123,6 @@ struct survey_report_top_sizes {
126
123
size_t alloc ;
127
124
};
128
125
129
- MAYBE_UNUSED
130
126
static void init_top_sizes (struct survey_report_top_sizes * top ,
131
127
size_t limit , const char * name ,
132
128
survey_top_size_cmp cmp )
@@ -146,7 +142,6 @@ static void clear_top_sizes(struct survey_report_top_sizes *top)
146
142
free (top -> data );
147
143
}
148
144
149
- MAYBE_UNUSED
150
145
static void maybe_insert_into_top_size (struct survey_report_top_sizes * top ,
151
146
struct survey_report_object_size_summary * summary )
152
147
{
@@ -182,6 +177,10 @@ struct survey_report {
182
177
struct survey_report_object_summary reachable_objects ;
183
178
184
179
struct survey_report_object_size_summary * by_type ;
180
+
181
+ struct survey_report_top_sizes * top_paths_by_count ;
182
+ struct survey_report_top_sizes * top_paths_by_disk ;
183
+ struct survey_report_top_sizes * top_paths_by_inflate ;
185
184
};
186
185
187
186
#define REPORT_TYPE_COMMIT 0
@@ -423,6 +422,13 @@ static void survey_report_object_sizes(const char *title,
423
422
clear_table (& table );
424
423
}
425
424
425
+ static void survey_report_plaintext_sorted_size (
426
+ struct survey_report_top_sizes * top )
427
+ {
428
+ survey_report_object_sizes (top -> name , _ ("Path" ),
429
+ top -> data , top -> nr );
430
+ }
431
+
426
432
static void survey_report_plaintext (struct survey_context * ctx )
427
433
{
428
434
printf ("GIT SURVEY for \"%s\"\n" , ctx -> repo -> worktree );
@@ -433,6 +439,21 @@ static void survey_report_plaintext(struct survey_context *ctx)
433
439
_ ("Object Type" ),
434
440
ctx -> report .by_type ,
435
441
REPORT_TYPE_COUNT );
442
+
443
+ survey_report_plaintext_sorted_size (
444
+ & ctx -> report .top_paths_by_count [REPORT_TYPE_TREE ]);
445
+ survey_report_plaintext_sorted_size (
446
+ & ctx -> report .top_paths_by_count [REPORT_TYPE_BLOB ]);
447
+
448
+ survey_report_plaintext_sorted_size (
449
+ & ctx -> report .top_paths_by_disk [REPORT_TYPE_TREE ]);
450
+ survey_report_plaintext_sorted_size (
451
+ & ctx -> report .top_paths_by_disk [REPORT_TYPE_BLOB ]);
452
+
453
+ survey_report_plaintext_sorted_size (
454
+ & ctx -> report .top_paths_by_inflate [REPORT_TYPE_TREE ]);
455
+ survey_report_plaintext_sorted_size (
456
+ & ctx -> report .top_paths_by_inflate [REPORT_TYPE_BLOB ]);
436
457
}
437
458
438
459
static void survey_report_json (struct survey_context * ctx UNUSED )
@@ -668,7 +689,8 @@ static void increment_totals(struct survey_context *ctx,
668
689
669
690
static void increment_object_totals (struct survey_context * ctx ,
670
691
struct oid_array * oids ,
671
- enum object_type type )
692
+ enum object_type type ,
693
+ const char * path )
672
694
{
673
695
struct survey_report_object_size_summary * total ;
674
696
struct survey_report_object_size_summary summary = { 0 };
@@ -696,9 +718,30 @@ static void increment_object_totals(struct survey_context *ctx,
696
718
total -> disk_size += summary .disk_size ;
697
719
total -> inflated_size += summary .inflated_size ;
698
720
total -> num_missing += summary .num_missing ;
721
+
722
+ if (type == OBJ_TREE || type == OBJ_BLOB ) {
723
+ int index = type == OBJ_TREE ?
724
+ REPORT_TYPE_TREE : REPORT_TYPE_BLOB ;
725
+ struct survey_report_top_sizes * top ;
726
+
727
+ /*
728
+ * Temporarily store (const char *) here, but it will
729
+ * be duped if inserted and will not be freed.
730
+ */
731
+ summary .label = (char * )path ;
732
+
733
+ top = ctx -> report .top_paths_by_count ;
734
+ maybe_insert_into_top_size (& top [index ], & summary );
735
+
736
+ top = ctx -> report .top_paths_by_disk ;
737
+ maybe_insert_into_top_size (& top [index ], & summary );
738
+
739
+ top = ctx -> report .top_paths_by_inflate ;
740
+ maybe_insert_into_top_size (& top [index ], & summary );
741
+ }
699
742
}
700
743
701
- static int survey_objects_path_walk_fn (const char * path UNUSED ,
744
+ static int survey_objects_path_walk_fn (const char * path ,
702
745
struct oid_array * oids ,
703
746
enum object_type type ,
704
747
void * data )
@@ -707,7 +750,7 @@ static int survey_objects_path_walk_fn(const char *path UNUSED,
707
750
708
751
increment_object_counts (& ctx -> report .reachable_objects ,
709
752
type , oids -> nr );
710
- increment_object_totals (ctx , oids , type );
753
+ increment_object_totals (ctx , oids , type , path );
711
754
712
755
ctx -> progress_nr += oids -> nr ;
713
756
display_progress (ctx -> progress , ctx -> progress_nr );
@@ -752,6 +795,34 @@ static int iterate_tag_chain(struct survey_context *ctx,
752
795
return -1 ;
753
796
}
754
797
798
+ static void initialize_report (struct survey_context * ctx )
799
+ {
800
+ const int top_limit = 100 ;
801
+
802
+ CALLOC_ARRAY (ctx -> report .by_type , REPORT_TYPE_COUNT );
803
+ ctx -> report .by_type [REPORT_TYPE_COMMIT ].label = xstrdup (_ ("Commits" ));
804
+ ctx -> report .by_type [REPORT_TYPE_TREE ].label = xstrdup (_ ("Trees" ));
805
+ ctx -> report .by_type [REPORT_TYPE_BLOB ].label = xstrdup (_ ("Blobs" ));
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 );
824
+ }
825
+
755
826
static void survey_phase_objects (struct survey_context * ctx )
756
827
{
757
828
struct rev_info revs ;
@@ -769,10 +840,7 @@ static void survey_phase_objects(struct survey_context *ctx)
769
840
info .blobs = 1 ;
770
841
info .tags = 1 ;
771
842
772
- CALLOC_ARRAY (ctx -> report .by_type , REPORT_TYPE_COUNT );
773
- ctx -> report .by_type [REPORT_TYPE_COMMIT ].label = xstrdup (_ ("Commits" ));
774
- ctx -> report .by_type [REPORT_TYPE_TREE ].label = xstrdup (_ ("Trees" ));
775
- ctx -> report .by_type [REPORT_TYPE_BLOB ].label = xstrdup (_ ("Blobs" ));
843
+ initialize_report (ctx );
776
844
777
845
repo_init_revisions (ctx -> repo , & revs , "" );
778
846
0 commit comments