@@ -768,6 +768,8 @@ struct write_commit_graph_context {
768768 unsigned append :1 ,
769769 report_progress :1 ,
770770 split :1 ;
771+
772+ const struct split_commit_graph_opts * split_opts ;
771773};
772774
773775static void write_graph_chunk_fanout (struct hashfile * f ,
@@ -1116,14 +1118,15 @@ static int add_ref_to_list(const char *refname,
11161118 return 0 ;
11171119}
11181120
1119- int write_commit_graph_reachable (const char * obj_dir , unsigned int flags )
1121+ int write_commit_graph_reachable (const char * obj_dir , unsigned int flags ,
1122+ const struct split_commit_graph_opts * split_opts )
11201123{
11211124 struct string_list list = STRING_LIST_INIT_DUP ;
11221125 int result ;
11231126
11241127 for_each_ref (add_ref_to_list , & list );
11251128 result = write_commit_graph (obj_dir , NULL , & list ,
1126- flags );
1129+ flags , split_opts );
11271130
11281131 string_list_clear (& list , 0 );
11291132 return result ;
@@ -1498,20 +1501,25 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
14981501 return 0 ;
14991502}
15001503
1501- static int split_strategy_max_commits = 64000 ;
1502- static float split_strategy_size_mult = 2.0f ;
1503-
15041504static void split_graph_merge_strategy (struct write_commit_graph_context * ctx )
15051505{
15061506 struct commit_graph * g = ctx -> r -> objects -> commit_graph ;
15071507 uint32_t num_commits = ctx -> commits .nr ;
15081508 uint32_t i ;
15091509
1510+ int max_commits = 0 ;
1511+ int size_mult = 2 ;
1512+
1513+ if (ctx -> split_opts ) {
1514+ max_commits = ctx -> split_opts -> max_commits ;
1515+ size_mult = ctx -> split_opts -> size_multiple ;
1516+ }
1517+
15101518 g = ctx -> r -> objects -> commit_graph ;
15111519 ctx -> num_commit_graphs_after = ctx -> num_commit_graphs_before + 1 ;
15121520
1513- while (g && (g -> num_commits <= split_strategy_size_mult * num_commits ||
1514- num_commits > split_strategy_max_commits )) {
1521+ while (g && (g -> num_commits <= size_mult * num_commits ||
1522+ ( max_commits && num_commits > max_commits ) )) {
15151523 if (strcmp (g -> obj_dir , ctx -> obj_dir ))
15161524 break ;
15171525
@@ -1675,7 +1683,10 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
16751683 DIR * dir ;
16761684 struct dirent * de ;
16771685 size_t dirnamelen ;
1678- time_t expire_time = time (NULL );
1686+ timestamp_t expire_time = time (NULL );
1687+
1688+ if (ctx -> split_opts && ctx -> split_opts -> expire_time )
1689+ expire_time -= ctx -> split_opts -> expire_time ;
16791690
16801691 strbuf_addstr (& path , ctx -> obj_dir );
16811692 strbuf_addstr (& path , "/info/commit-graphs" );
@@ -1719,7 +1730,8 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
17191730int write_commit_graph (const char * obj_dir ,
17201731 struct string_list * pack_indexes ,
17211732 struct string_list * commit_hex ,
1722- unsigned int flags )
1733+ unsigned int flags ,
1734+ const struct split_commit_graph_opts * split_opts )
17231735{
17241736 struct write_commit_graph_context * ctx ;
17251737 uint32_t i , count_distinct = 0 ;
@@ -1734,6 +1746,7 @@ int write_commit_graph(const char *obj_dir,
17341746 ctx -> append = flags & COMMIT_GRAPH_APPEND ? 1 : 0 ;
17351747 ctx -> report_progress = flags & COMMIT_GRAPH_PROGRESS ? 1 : 0 ;
17361748 ctx -> split = flags & COMMIT_GRAPH_SPLIT ? 1 : 0 ;
1749+ ctx -> split_opts = split_opts ;
17371750
17381751 if (ctx -> split ) {
17391752 struct commit_graph * g ;
@@ -1761,8 +1774,8 @@ int write_commit_graph(const char *obj_dir,
17611774 ctx -> approx_nr_objects = approximate_object_count ();
17621775 ctx -> oids .alloc = ctx -> approx_nr_objects / 32 ;
17631776
1764- if (ctx -> split && ctx -> oids .alloc > split_strategy_max_commits )
1765- ctx -> oids .alloc = split_strategy_max_commits ;
1777+ if (ctx -> split && split_opts && ctx -> oids .alloc > split_opts -> max_commits )
1778+ ctx -> oids .alloc = split_opts -> max_commits ;
17661779
17671780 if (ctx -> append ) {
17681781 prepare_commit_graph_one (ctx -> r , ctx -> obj_dir );
0 commit comments