44#include "environment.h"
55#include "parse-options.h"
66#include "path-walk.h"
7+ #include "progress.h"
78#include "quote.h"
89#include "ref-filter.h"
910#include "refs.h"
@@ -359,10 +360,10 @@ static void structure_keyvalue_print(struct repo_structure *stats,
359360 fflush (stdout );
360361}
361362
362-
363363struct count_references_data {
364364 struct ref_stats * stats ;
365365 struct rev_info * revs ;
366+ struct progress * progress ;
366367};
367368
368369static int count_references (const char * refname ,
@@ -372,6 +373,7 @@ static int count_references(const char *refname,
372373{
373374 struct count_references_data * data = cb_data ;
374375 struct ref_stats * stats = data -> stats ;
376+ size_t ref_count ;
375377
376378 switch (ref_kind_from_refname (refname )) {
377379 case FILTER_REFS_BRANCHES :
@@ -396,26 +398,41 @@ static int count_references(const char *refname,
396398 */
397399 add_pending_oid (data -> revs , NULL , oid , 0 );
398400
401+ ref_count = get_total_reference_count (stats );
402+ display_progress (data -> progress , ref_count );
403+
399404 return 0 ;
400405}
401406
402407static void structure_count_references (struct ref_stats * stats ,
403408 struct rev_info * revs ,
404- struct repository * repo )
409+ struct repository * repo ,
410+ int show_progress )
405411{
406412 struct count_references_data data = {
407413 .stats = stats ,
408414 .revs = revs ,
409415 };
410416
417+ if (show_progress )
418+ data .progress = start_delayed_progress (repo ,
419+ _ ("Counting references" ), 0 );
420+
411421 refs_for_each_ref (get_main_ref_store (repo ), count_references , & data );
422+ stop_progress (& data .progress );
412423}
413424
425+ struct count_objects_data {
426+ struct object_stats * stats ;
427+ struct progress * progress ;
428+ };
414429
415430static int count_objects (const char * path UNUSED , struct oid_array * oids ,
416431 enum object_type type , void * cb_data )
417432{
418- struct object_stats * stats = cb_data ;
433+ struct count_objects_data * data = cb_data ;
434+ struct object_stats * stats = data -> stats ;
435+ size_t object_count ;
419436
420437 switch (type ) {
421438 case OBJ_TAG :
@@ -434,20 +451,31 @@ static int count_objects(const char *path UNUSED, struct oid_array *oids,
434451 BUG ("invalid object type" );
435452 }
436453
454+ object_count = get_total_object_count (stats );
455+ display_progress (data -> progress , object_count );
456+
437457 return 0 ;
438458}
439459
440460static void structure_count_objects (struct object_stats * stats ,
441- struct rev_info * revs )
461+ struct rev_info * revs ,
462+ struct repository * repo , int show_progress )
442463{
443464 struct path_walk_info info = PATH_WALK_INFO_INIT ;
465+ struct count_objects_data data = {
466+ .stats = stats ,
467+ };
444468
445469 info .revs = revs ;
446470 info .path_fn = count_objects ;
447- info .path_fn_data = stats ;
471+ info .path_fn_data = & data ;
472+
473+ if (show_progress )
474+ data .progress = start_delayed_progress (repo , _ ("Counting objects" ), 0 );
448475
449476 walk_objects_by_path (& info );
450477 path_walk_info_clear (& info );
478+ stop_progress (& data .progress );
451479}
452480
453481static int cmd_repo_structure (int argc , const char * * argv , const char * prefix ,
@@ -459,10 +487,12 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,
459487 enum output_format format = FORMAT_TABLE ;
460488 struct repo_structure stats = { 0 };
461489 struct rev_info revs ;
490+ int show_progress = -1 ;
462491 struct option options [] = {
463492 OPT_CALLBACK_F (0 , "format" , & format , N_ ("format" ),
464493 N_ ("output format" ),
465494 PARSE_OPT_NONEG , parse_format_cb ),
495+ OPT_BOOL (0 , "progress" , & show_progress , N_ ("show progress" )),
466496 OPT_END ()
467497 };
468498
@@ -472,8 +502,11 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,
472502
473503 repo_init_revisions (repo , & revs , prefix );
474504
475- structure_count_references (& stats .refs , & revs , repo );
476- structure_count_objects (& stats .objects , & revs );
505+ if (show_progress < 0 )
506+ show_progress = isatty (2 );
507+
508+ structure_count_references (& stats .refs , & revs , repo , show_progress );
509+ structure_count_objects (& stats .objects , & revs , repo , show_progress );
477510
478511 switch (format ) {
479512 case FORMAT_TABLE :
0 commit comments