@@ -783,7 +783,8 @@ struct write_commit_graph_context {
783783
784784 unsigned append :1 ,
785785 report_progress :1 ,
786- split :1 ;
786+ split :1 ,
787+ check_oids :1 ;
787788
788789 const struct split_commit_graph_opts * split_opts ;
789790};
@@ -1134,7 +1135,8 @@ static int add_ref_to_list(const char *refname,
11341135 return 0 ;
11351136}
11361137
1137- int write_commit_graph_reachable (const char * obj_dir , unsigned int flags ,
1138+ int write_commit_graph_reachable (const char * obj_dir ,
1139+ enum commit_graph_write_flags flags ,
11381140 const struct split_commit_graph_opts * split_opts )
11391141{
11401142 struct string_list list = STRING_LIST_INIT_DUP ;
@@ -1193,8 +1195,8 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
11931195 return 0 ;
11941196}
11951197
1196- static void fill_oids_from_commit_hex (struct write_commit_graph_context * ctx ,
1197- struct string_list * commit_hex )
1198+ static int fill_oids_from_commit_hex (struct write_commit_graph_context * ctx ,
1199+ struct string_list * commit_hex )
11981200{
11991201 uint32_t i ;
12001202 struct strbuf progress_title = STRBUF_INIT ;
@@ -1215,20 +1217,21 @@ static void fill_oids_from_commit_hex(struct write_commit_graph_context *ctx,
12151217 struct commit * result ;
12161218
12171219 display_progress (ctx -> progress , i + 1 );
1218- if (commit_hex -> items [i ].string &&
1219- parse_oid_hex (commit_hex -> items [i ].string , & oid , & end ))
1220- continue ;
1221-
1222- result = lookup_commit_reference_gently (ctx -> r , & oid , 1 );
1223-
1224- if (result ) {
1220+ if (!parse_oid_hex (commit_hex -> items [i ].string , & oid , & end ) &&
1221+ (result = lookup_commit_reference_gently (ctx -> r , & oid , 1 ))) {
12251222 ALLOC_GROW (ctx -> oids .list , ctx -> oids .nr + 1 , ctx -> oids .alloc );
12261223 oidcpy (& ctx -> oids .list [ctx -> oids .nr ], & (result -> object .oid ));
12271224 ctx -> oids .nr ++ ;
1225+ } else if (ctx -> check_oids ) {
1226+ error (_ ("invalid commit object id: %s" ),
1227+ commit_hex -> items [i ].string );
1228+ return -1 ;
12281229 }
12291230 }
12301231 stop_progress (& ctx -> progress );
12311232 strbuf_release (& progress_title );
1233+
1234+ return 0 ;
12321235}
12331236
12341237static void fill_oids_from_all_packs (struct write_commit_graph_context * ctx )
@@ -1752,7 +1755,7 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
17521755int write_commit_graph (const char * obj_dir ,
17531756 struct string_list * pack_indexes ,
17541757 struct string_list * commit_hex ,
1755- unsigned int flags ,
1758+ enum commit_graph_write_flags flags ,
17561759 const struct split_commit_graph_opts * split_opts )
17571760{
17581761 struct write_commit_graph_context * ctx ;
@@ -1773,9 +1776,10 @@ int write_commit_graph(const char *obj_dir,
17731776 if (len && ctx -> obj_dir [len - 1 ] == '/' )
17741777 ctx -> obj_dir [len - 1 ] = 0 ;
17751778
1776- ctx -> append = flags & COMMIT_GRAPH_APPEND ? 1 : 0 ;
1777- ctx -> report_progress = flags & COMMIT_GRAPH_PROGRESS ? 1 : 0 ;
1778- ctx -> split = flags & COMMIT_GRAPH_SPLIT ? 1 : 0 ;
1779+ ctx -> append = flags & COMMIT_GRAPH_WRITE_APPEND ? 1 : 0 ;
1780+ ctx -> report_progress = flags & COMMIT_GRAPH_WRITE_PROGRESS ? 1 : 0 ;
1781+ ctx -> split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0 ;
1782+ ctx -> check_oids = flags & COMMIT_GRAPH_WRITE_CHECK_OIDS ? 1 : 0 ;
17791783 ctx -> split_opts = split_opts ;
17801784
17811785 if (ctx -> split ) {
@@ -1830,8 +1834,10 @@ int write_commit_graph(const char *obj_dir,
18301834 goto cleanup ;
18311835 }
18321836
1833- if (commit_hex )
1834- fill_oids_from_commit_hex (ctx , commit_hex );
1837+ if (commit_hex ) {
1838+ if ((res = fill_oids_from_commit_hex (ctx , commit_hex )))
1839+ goto cleanup ;
1840+ }
18351841
18361842 if (!pack_indexes && !commit_hex )
18371843 fill_oids_from_all_packs (ctx );
0 commit comments