@@ -882,6 +882,40 @@ static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
882
882
return result ;
883
883
}
884
884
885
+ static int fill_packs_from_midx (struct write_midx_context * ctx ,
886
+ const char * preferred_pack_name , uint32_t flags )
887
+ {
888
+ uint32_t i ;
889
+
890
+ for (i = 0 ; i < ctx -> m -> num_packs ; i ++ ) {
891
+ ALLOC_GROW (ctx -> info , ctx -> nr + 1 , ctx -> alloc );
892
+
893
+ if (flags & MIDX_WRITE_REV_INDEX || preferred_pack_name ) {
894
+ /*
895
+ * If generating a reverse index, need to have
896
+ * packed_git's loaded to compare their
897
+ * mtimes and object count.
898
+ *
899
+ *
900
+ * If a preferred pack is specified, need to
901
+ * have packed_git's loaded to ensure the chosen
902
+ * preferred pack has a non-zero object count.
903
+ */
904
+ if (prepare_midx_pack (the_repository , ctx -> m , i ))
905
+ return error (_ ("could not load pack" ));
906
+
907
+ if (open_pack_index (ctx -> m -> packs [i ]))
908
+ die (_ ("could not open index for %s" ),
909
+ ctx -> m -> packs [i ]-> pack_name );
910
+ }
911
+
912
+ fill_pack_info (& ctx -> info [ctx -> nr ++ ], ctx -> m -> packs [i ],
913
+ ctx -> m -> pack_names [i ], i );
914
+ }
915
+
916
+ return 0 ;
917
+ }
918
+
885
919
static int write_midx_internal (const char * object_dir ,
886
920
struct string_list * packs_to_include ,
887
921
struct string_list * packs_to_drop ,
@@ -927,36 +961,10 @@ static int write_midx_internal(const char *object_dir,
927
961
ctx .info = NULL ;
928
962
ALLOC_ARRAY (ctx .info , ctx .alloc );
929
963
930
- if (ctx .m ) {
931
- for (i = 0 ; i < ctx .m -> num_packs ; i ++ ) {
932
- ALLOC_GROW (ctx .info , ctx .nr + 1 , ctx .alloc );
933
-
934
- if (flags & MIDX_WRITE_REV_INDEX ||
935
- preferred_pack_name ) {
936
- /*
937
- * If generating a reverse index, need to have
938
- * packed_git's loaded to compare their
939
- * mtimes and object count.
940
- *
941
- * If a preferred pack is specified,
942
- * need to have packed_git's loaded to
943
- * ensure the chosen preferred pack has
944
- * a non-zero object count.
945
- */
946
- if (prepare_midx_pack (the_repository , ctx .m , i )) {
947
- error (_ ("could not load pack" ));
948
- result = 1 ;
949
- goto cleanup ;
950
- }
951
-
952
- if (open_pack_index (ctx .m -> packs [i ]))
953
- die (_ ("could not open index for %s" ),
954
- ctx .m -> packs [i ]-> pack_name );
955
- }
956
-
957
- fill_pack_info (& ctx .info [ctx .nr ++ ], ctx .m -> packs [i ],
958
- ctx .m -> pack_names [i ], i );
959
- }
964
+ if (ctx .m && fill_packs_from_midx (& ctx , preferred_pack_name ,
965
+ flags ) < 0 ) {
966
+ result = 1 ;
967
+ goto cleanup ;
960
968
}
961
969
962
970
start_pack = ctx .nr ;
0 commit comments