13
13
#include "commit-graph.h"
14
14
#include "object-store.h"
15
15
#include "alloc.h"
16
+ #include "progress.h"
16
17
17
18
#define GRAPH_SIGNATURE 0x43475048 /* "CGPH" */
18
19
#define GRAPH_CHUNKID_OIDFANOUT 0x4f494446 /* "OIDF" */
@@ -567,6 +568,8 @@ struct packed_oid_list {
567
568
struct object_id * list ;
568
569
int nr ;
569
570
int alloc ;
571
+ struct progress * progress ;
572
+ int progress_done ;
570
573
};
571
574
572
575
static int add_packed_commits (const struct object_id * oid ,
@@ -579,6 +582,9 @@ static int add_packed_commits(const struct object_id *oid,
579
582
off_t offset = nth_packed_object_offset (pack , pos );
580
583
struct object_info oi = OBJECT_INFO_INIT ;
581
584
585
+ if (list -> progress )
586
+ display_progress (list -> progress , ++ list -> progress_done );
587
+
582
588
oi .typep = & type ;
583
589
if (packed_object_info (the_repository , pack , offset , & oi ) < 0 )
584
590
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
606
612
}
607
613
}
608
614
609
- static void close_reachable (struct packed_oid_list * oids )
615
+ static void close_reachable (struct packed_oid_list * oids , int report_progress )
610
616
{
611
617
int i ;
612
618
struct commit * commit ;
619
+ struct progress * progress = NULL ;
620
+ int j = 0 ;
613
621
622
+ if (report_progress )
623
+ progress = start_delayed_progress (
624
+ _ ("Annotating commits in commit graph" ), 0 );
614
625
for (i = 0 ; i < oids -> nr ; i ++ ) {
626
+ display_progress (progress , ++ j );
615
627
commit = lookup_commit (the_repository , & oids -> list [i ]);
616
628
if (commit )
617
629
commit -> object .flags |= UNINTERESTING ;
@@ -623,26 +635,36 @@ static void close_reachable(struct packed_oid_list *oids)
623
635
* closure.
624
636
*/
625
637
for (i = 0 ; i < oids -> nr ; i ++ ) {
638
+ display_progress (progress , ++ j );
626
639
commit = lookup_commit (the_repository , & oids -> list [i ]);
627
640
628
641
if (commit && !parse_commit (commit ))
629
642
add_missing_parents (oids , commit );
630
643
}
631
644
632
645
for (i = 0 ; i < oids -> nr ; i ++ ) {
646
+ display_progress (progress , ++ j );
633
647
commit = lookup_commit (the_repository , & oids -> list [i ]);
634
648
635
649
if (commit )
636
650
commit -> object .flags &= ~UNINTERESTING ;
637
651
}
652
+ stop_progress (& progress );
638
653
}
639
654
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 )
641
657
{
642
658
int i ;
643
659
struct commit_list * list = NULL ;
660
+ struct progress * progress = NULL ;
644
661
662
+ if (report_progress )
663
+ progress = start_progress (
664
+ _ ("Computing commit graph generation numbers" ),
665
+ commits -> nr );
645
666
for (i = 0 ; i < commits -> nr ; i ++ ) {
667
+ display_progress (progress , i + 1 );
646
668
if (commits -> list [i ]-> generation != GENERATION_NUMBER_INFINITY &&
647
669
commits -> list [i ]-> generation != GENERATION_NUMBER_ZERO )
648
670
continue ;
@@ -674,6 +696,7 @@ static void compute_generation_numbers(struct packed_commit_list* commits)
674
696
}
675
697
}
676
698
}
699
+ stop_progress (& progress );
677
700
}
678
701
679
702
static int add_ref_to_list (const char * refname ,
@@ -686,19 +709,20 @@ static int add_ref_to_list(const char *refname,
686
709
return 0 ;
687
710
}
688
711
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 )
690
714
{
691
715
struct string_list list ;
692
716
693
717
string_list_init (& list , 1 );
694
718
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 );
696
720
}
697
721
698
722
void write_commit_graph (const char * obj_dir ,
699
723
struct string_list * pack_indexes ,
700
724
struct string_list * commit_hex ,
701
- int append )
725
+ int append , int report_progress )
702
726
{
703
727
struct packed_oid_list oids ;
704
728
struct packed_commit_list commits ;
@@ -711,9 +735,12 @@ void write_commit_graph(const char *obj_dir,
711
735
int num_chunks ;
712
736
int num_extra_edges ;
713
737
struct commit_list * parent ;
738
+ struct progress * progress = NULL ;
714
739
715
740
oids .nr = 0 ;
716
741
oids .alloc = approximate_object_count () / 4 ;
742
+ oids .progress = NULL ;
743
+ oids .progress_done = 0 ;
717
744
718
745
if (append ) {
719
746
prepare_commit_graph_one (the_repository , obj_dir );
@@ -740,6 +767,11 @@ void write_commit_graph(const char *obj_dir,
740
767
int dirlen ;
741
768
strbuf_addf (& packname , "%s/pack/" , obj_dir );
742
769
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
+ }
743
775
for (i = 0 ; i < pack_indexes -> nr ; i ++ ) {
744
776
struct packed_git * p ;
745
777
strbuf_setlen (& packname , dirlen );
@@ -752,15 +784,21 @@ void write_commit_graph(const char *obj_dir,
752
784
for_each_object_in_pack (p , add_packed_commits , & oids , 0 );
753
785
close_pack (p );
754
786
}
787
+ stop_progress (& oids .progress );
755
788
strbuf_release (& packname );
756
789
}
757
790
758
791
if (commit_hex ) {
792
+ if (report_progress )
793
+ progress = start_delayed_progress (
794
+ _ ("Finding commits for commit graph" ),
795
+ commit_hex -> nr );
759
796
for (i = 0 ; i < commit_hex -> nr ; i ++ ) {
760
797
const char * end ;
761
798
struct object_id oid ;
762
799
struct commit * result ;
763
800
801
+ display_progress (progress , i + 1 );
764
802
if (commit_hex -> items [i ].string &&
765
803
parse_oid_hex (commit_hex -> items [i ].string , & oid , & end ))
766
804
continue ;
@@ -773,12 +811,18 @@ void write_commit_graph(const char *obj_dir,
773
811
oids .nr ++ ;
774
812
}
775
813
}
814
+ stop_progress (& progress );
776
815
}
777
816
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 );
779
821
for_each_packed_object (add_packed_commits , & oids , 0 );
822
+ stop_progress (& oids .progress );
823
+ }
780
824
781
- close_reachable (& oids );
825
+ close_reachable (& oids , report_progress );
782
826
783
827
QSORT (oids .list , oids .nr , commit_compare );
784
828
@@ -818,7 +862,7 @@ void write_commit_graph(const char *obj_dir,
818
862
if (commits .nr >= GRAPH_PARENT_MISSING )
819
863
die (_ ("too many commits to write graph" ));
820
864
821
- compute_generation_numbers (& commits );
865
+ compute_generation_numbers (& commits , report_progress );
822
866
823
867
graph_name = get_commit_graph_filename (obj_dir );
824
868
if (safe_create_leading_directories (graph_name ))
@@ -897,6 +941,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
897
941
int generation_zero = 0 ;
898
942
struct hashfile * f ;
899
943
int devnull ;
944
+ struct progress * progress = NULL ;
900
945
901
946
if (!g ) {
902
947
graph_report ("no commit-graph file loaded" );
@@ -964,11 +1009,14 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
964
1009
if (verify_commit_graph_error & ~VERIFY_COMMIT_GRAPH_ERROR_HASH )
965
1010
return verify_commit_graph_error ;
966
1011
1012
+ progress = start_progress (_ ("Verifying commits in commit graph" ),
1013
+ g -> num_commits );
967
1014
for (i = 0 ; i < g -> num_commits ; i ++ ) {
968
1015
struct commit * graph_commit , * odb_commit ;
969
1016
struct commit_list * graph_parents , * odb_parents ;
970
1017
uint32_t max_generation = 0 ;
971
1018
1019
+ display_progress (progress , i + 1 );
972
1020
hashcpy (cur_oid .hash , g -> chunk_oid_lookup + g -> hash_len * i );
973
1021
974
1022
graph_commit = lookup_commit (r , & cur_oid );
@@ -1045,6 +1093,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
1045
1093
graph_commit -> date ,
1046
1094
odb_commit -> date );
1047
1095
}
1096
+ stop_progress (& progress );
1048
1097
1049
1098
return verify_commit_graph_error ;
1050
1099
}
0 commit comments