1313#include "commit-graph.h"
1414#include "object-store.h"
1515#include "alloc.h"
16+ #include "progress.h"
1617
1718#define GRAPH_SIGNATURE 0x43475048 /* "CGPH" */
1819#define GRAPH_CHUNKID_OIDFANOUT 0x4f494446 /* "OIDF" */
@@ -567,6 +568,8 @@ struct packed_oid_list {
567568 struct object_id * list ;
568569 int nr ;
569570 int alloc ;
571+ struct progress * progress ;
572+ int progress_done ;
570573};
571574
572575static int add_packed_commits (const struct object_id * oid ,
@@ -579,6 +582,9 @@ static int add_packed_commits(const struct object_id *oid,
579582 off_t offset = nth_packed_object_offset (pack , pos );
580583 struct object_info oi = OBJECT_INFO_INIT ;
581584
585+ if (list -> progress )
586+ display_progress (list -> progress , ++ list -> progress_done );
587+
582588 oi .typep = & type ;
583589 if (packed_object_info (the_repository , pack , offset , & oi ) < 0 )
584590 die (_ ("unable to get type of object %s" ), oid_to_hex (oid ));
@@ -606,12 +612,18 @@ static void add_missing_parents(struct packed_oid_list *oids, struct commit *com
606612 }
607613}
608614
609- static void close_reachable (struct packed_oid_list * oids )
615+ static void close_reachable (struct packed_oid_list * oids , int report_progress )
610616{
611617 int i ;
612618 struct commit * commit ;
619+ struct progress * progress = NULL ;
620+ int j = 0 ;
613621
622+ if (report_progress )
623+ progress = start_delayed_progress (
624+ _ ("Annotating commits in commit graph" ), 0 );
614625 for (i = 0 ; i < oids -> nr ; i ++ ) {
626+ display_progress (progress , ++ j );
615627 commit = lookup_commit (the_repository , & oids -> list [i ]);
616628 if (commit )
617629 commit -> object .flags |= UNINTERESTING ;
@@ -623,26 +635,36 @@ static void close_reachable(struct packed_oid_list *oids)
623635 * closure.
624636 */
625637 for (i = 0 ; i < oids -> nr ; i ++ ) {
638+ display_progress (progress , ++ j );
626639 commit = lookup_commit (the_repository , & oids -> list [i ]);
627640
628641 if (commit && !parse_commit (commit ))
629642 add_missing_parents (oids , commit );
630643 }
631644
632645 for (i = 0 ; i < oids -> nr ; i ++ ) {
646+ display_progress (progress , ++ j );
633647 commit = lookup_commit (the_repository , & oids -> list [i ]);
634648
635649 if (commit )
636650 commit -> object .flags &= ~UNINTERESTING ;
637651 }
652+ stop_progress (& progress );
638653}
639654
640- static void compute_generation_numbers (struct packed_commit_list * commits )
655+ static void compute_generation_numbers (struct packed_commit_list * commits ,
656+ int report_progress )
641657{
642658 int i ;
643659 struct commit_list * list = NULL ;
660+ struct progress * progress = NULL ;
644661
662+ if (report_progress )
663+ progress = start_progress (
664+ _ ("Computing commit graph generation numbers" ),
665+ commits -> nr );
645666 for (i = 0 ; i < commits -> nr ; i ++ ) {
667+ display_progress (progress , i + 1 );
646668 if (commits -> list [i ]-> generation != GENERATION_NUMBER_INFINITY &&
647669 commits -> list [i ]-> generation != GENERATION_NUMBER_ZERO )
648670 continue ;
@@ -674,6 +696,7 @@ static void compute_generation_numbers(struct packed_commit_list* commits)
674696 }
675697 }
676698 }
699+ stop_progress (& progress );
677700}
678701
679702static int add_ref_to_list (const char * refname ,
@@ -686,19 +709,20 @@ static int add_ref_to_list(const char *refname,
686709 return 0 ;
687710}
688711
689- void write_commit_graph_reachable (const char * obj_dir , int append )
712+ void write_commit_graph_reachable (const char * obj_dir , int append ,
713+ int report_progress )
690714{
691715 struct string_list list ;
692716
693717 string_list_init (& list , 1 );
694718 for_each_ref (add_ref_to_list , & list );
695- write_commit_graph (obj_dir , NULL , & list , append );
719+ write_commit_graph (obj_dir , NULL , & list , append , report_progress );
696720}
697721
698722void write_commit_graph (const char * obj_dir ,
699723 struct string_list * pack_indexes ,
700724 struct string_list * commit_hex ,
701- int append )
725+ int append , int report_progress )
702726{
703727 struct packed_oid_list oids ;
704728 struct packed_commit_list commits ;
@@ -711,9 +735,12 @@ void write_commit_graph(const char *obj_dir,
711735 int num_chunks ;
712736 int num_extra_edges ;
713737 struct commit_list * parent ;
738+ struct progress * progress = NULL ;
714739
715740 oids .nr = 0 ;
716741 oids .alloc = approximate_object_count () / 4 ;
742+ oids .progress = NULL ;
743+ oids .progress_done = 0 ;
717744
718745 if (append ) {
719746 prepare_commit_graph_one (the_repository , obj_dir );
@@ -740,6 +767,11 @@ void write_commit_graph(const char *obj_dir,
740767 int dirlen ;
741768 strbuf_addf (& packname , "%s/pack/" , obj_dir );
742769 dirlen = packname .len ;
770+ if (report_progress ) {
771+ oids .progress = start_delayed_progress (
772+ _ ("Finding commits for commit graph" ), 0 );
773+ oids .progress_done = 0 ;
774+ }
743775 for (i = 0 ; i < pack_indexes -> nr ; i ++ ) {
744776 struct packed_git * p ;
745777 strbuf_setlen (& packname , dirlen );
@@ -752,15 +784,21 @@ void write_commit_graph(const char *obj_dir,
752784 for_each_object_in_pack (p , add_packed_commits , & oids , 0 );
753785 close_pack (p );
754786 }
787+ stop_progress (& oids .progress );
755788 strbuf_release (& packname );
756789 }
757790
758791 if (commit_hex ) {
792+ if (report_progress )
793+ progress = start_delayed_progress (
794+ _ ("Finding commits for commit graph" ),
795+ commit_hex -> nr );
759796 for (i = 0 ; i < commit_hex -> nr ; i ++ ) {
760797 const char * end ;
761798 struct object_id oid ;
762799 struct commit * result ;
763800
801+ display_progress (progress , i + 1 );
764802 if (commit_hex -> items [i ].string &&
765803 parse_oid_hex (commit_hex -> items [i ].string , & oid , & end ))
766804 continue ;
@@ -773,12 +811,18 @@ void write_commit_graph(const char *obj_dir,
773811 oids .nr ++ ;
774812 }
775813 }
814+ stop_progress (& progress );
776815 }
777816
778- if (!pack_indexes && !commit_hex )
817+ if (!pack_indexes && !commit_hex ) {
818+ if (report_progress )
819+ oids .progress = start_delayed_progress (
820+ _ ("Finding commits for commit graph" ), 0 );
779821 for_each_packed_object (add_packed_commits , & oids , 0 );
822+ stop_progress (& oids .progress );
823+ }
780824
781- close_reachable (& oids );
825+ close_reachable (& oids , report_progress );
782826
783827 QSORT (oids .list , oids .nr , commit_compare );
784828
@@ -818,7 +862,7 @@ void write_commit_graph(const char *obj_dir,
818862 if (commits .nr >= GRAPH_PARENT_MISSING )
819863 die (_ ("too many commits to write graph" ));
820864
821- compute_generation_numbers (& commits );
865+ compute_generation_numbers (& commits , report_progress );
822866
823867 graph_name = get_commit_graph_filename (obj_dir );
824868 if (safe_create_leading_directories (graph_name ))
@@ -897,6 +941,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
897941 int generation_zero = 0 ;
898942 struct hashfile * f ;
899943 int devnull ;
944+ struct progress * progress = NULL ;
900945
901946 if (!g ) {
902947 graph_report ("no commit-graph file loaded" );
@@ -964,11 +1009,14 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
9641009 if (verify_commit_graph_error & ~VERIFY_COMMIT_GRAPH_ERROR_HASH )
9651010 return verify_commit_graph_error ;
9661011
1012+ progress = start_progress (_ ("Verifying commits in commit graph" ),
1013+ g -> num_commits );
9671014 for (i = 0 ; i < g -> num_commits ; i ++ ) {
9681015 struct commit * graph_commit , * odb_commit ;
9691016 struct commit_list * graph_parents , * odb_parents ;
9701017 uint32_t max_generation = 0 ;
9711018
1019+ display_progress (progress , i + 1 );
9721020 hashcpy (cur_oid .hash , g -> chunk_oid_lookup + g -> hash_len * i );
9731021
9741022 graph_commit = lookup_commit (r , & cur_oid );
@@ -1045,6 +1093,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
10451093 graph_commit -> date ,
10461094 odb_commit -> date );
10471095 }
1096+ stop_progress (& progress );
10481097
10491098 return verify_commit_graph_error ;
10501099}
0 commit comments