@@ -806,6 +806,36 @@ static void remove_redundant_bitmaps(struct string_list *include,
806
806
strbuf_release (& path );
807
807
}
808
808
809
+ static int finish_pack_objects_cmd (struct child_process * cmd ,
810
+ struct string_list * names ,
811
+ int local )
812
+ {
813
+ FILE * out ;
814
+ struct strbuf line = STRBUF_INIT ;
815
+
816
+ out = xfdopen (cmd -> out , "r" );
817
+ while (strbuf_getline_lf (& line , out ) != EOF ) {
818
+ struct string_list_item * item ;
819
+
820
+ if (line .len != the_hash_algo -> hexsz )
821
+ die (_ ("repack: Expecting full hex object ID lines only "
822
+ "from pack-objects." ));
823
+ /*
824
+ * Avoid putting packs written outside of the repository in the
825
+ * list of names.
826
+ */
827
+ if (local ) {
828
+ item = string_list_append (names , line .buf );
829
+ item -> util = populate_pack_exts (line .buf );
830
+ }
831
+ }
832
+ fclose (out );
833
+
834
+ strbuf_release (& line );
835
+
836
+ return finish_command (cmd );
837
+ }
838
+
809
839
static int write_cruft_pack (const struct pack_objects_args * args ,
810
840
const char * destination ,
811
841
const char * pack_prefix ,
@@ -814,9 +844,8 @@ static int write_cruft_pack(const struct pack_objects_args *args,
814
844
struct existing_packs * existing )
815
845
{
816
846
struct child_process cmd = CHILD_PROCESS_INIT ;
817
- struct strbuf line = STRBUF_INIT ;
818
847
struct string_list_item * item ;
819
- FILE * in , * out ;
848
+ FILE * in ;
820
849
int ret ;
821
850
const char * scratch ;
822
851
int local = skip_prefix (destination , packdir , & scratch );
@@ -861,27 +890,7 @@ static int write_cruft_pack(const struct pack_objects_args *args,
861
890
fprintf (in , "%s.pack\n" , item -> string );
862
891
fclose (in );
863
892
864
- out = xfdopen (cmd .out , "r" );
865
- while (strbuf_getline_lf (& line , out ) != EOF ) {
866
- struct string_list_item * item ;
867
-
868
- if (line .len != the_hash_algo -> hexsz )
869
- die (_ ("repack: Expecting full hex object ID lines only "
870
- "from pack-objects." ));
871
- /*
872
- * avoid putting packs written outside of the repository in the
873
- * list of names
874
- */
875
- if (local ) {
876
- item = string_list_append (names , line .buf );
877
- item -> util = populate_pack_exts (line .buf );
878
- }
879
- }
880
- fclose (out );
881
-
882
- strbuf_release (& line );
883
-
884
- return finish_command (& cmd );
893
+ return finish_pack_objects_cmd (& cmd , names , local );
885
894
}
886
895
887
896
int cmd_repack (int argc , const char * * argv , const char * prefix )
@@ -891,10 +900,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
891
900
struct string_list names = STRING_LIST_INIT_DUP ;
892
901
struct existing_packs existing = EXISTING_PACKS_INIT ;
893
902
struct pack_geometry geometry = { 0 };
894
- struct strbuf line = STRBUF_INIT ;
895
903
struct tempfile * refs_snapshot = NULL ;
896
904
int i , ext , ret ;
897
- FILE * out ;
898
905
int show_progress ;
899
906
900
907
/* variables to be filled by option parsing */
@@ -1124,18 +1131,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
1124
1131
fclose (in );
1125
1132
}
1126
1133
1127
- out = xfdopen (cmd .out , "r" );
1128
- while (strbuf_getline_lf (& line , out ) != EOF ) {
1129
- struct string_list_item * item ;
1130
-
1131
- if (line .len != the_hash_algo -> hexsz )
1132
- die (_ ("repack: Expecting full hex object ID lines only from pack-objects." ));
1133
- item = string_list_append (& names , line .buf );
1134
- item -> util = populate_pack_exts (item -> string );
1135
- }
1136
- strbuf_release (& line );
1137
- fclose (out );
1138
- ret = finish_command (& cmd );
1134
+ ret = finish_pack_objects_cmd (& cmd , & names , 1 );
1139
1135
if (ret )
1140
1136
goto cleanup ;
1141
1137
0 commit comments