13
13
#include "string-list.h"
14
14
#include "sha1-array.h"
15
15
#include "connected.h"
16
+ #include "argv-array.h"
16
17
#include "version.h"
17
18
18
19
static const char receive_pack_usage [] = "git receive-pack <git-dir>" ;
@@ -822,8 +823,11 @@ static const char *pack_lockfile;
822
823
static const char * unpack (int err_fd )
823
824
{
824
825
struct pack_header hdr ;
826
+ struct argv_array av = ARGV_ARRAY_INIT ;
825
827
const char * hdr_err ;
828
+ int status ;
826
829
char hdr_arg [38 ];
830
+ struct child_process child ;
827
831
int fsck_objects = (receive_fsck_objects >= 0
828
832
? receive_fsck_objects
829
833
: transfer_fsck_objects >= 0
@@ -840,63 +844,49 @@ static const char *unpack(int err_fd)
840
844
"--pack_header=%" PRIu32 ",%" PRIu32 ,
841
845
ntohl (hdr .hdr_version ), ntohl (hdr .hdr_entries ));
842
846
847
+ memset (& child , 0 , sizeof (child ));
843
848
if (ntohl (hdr .hdr_entries ) < unpack_limit ) {
844
- int code , i = 0 ;
845
- struct child_process child ;
846
- const char * unpacker [5 ];
847
- unpacker [i ++ ] = "unpack-objects" ;
849
+ argv_array_pushl (& av , "unpack-objects" , hdr_arg , NULL );
848
850
if (quiet )
849
- unpacker [ i ++ ] = "-q" ;
851
+ argv_array_push ( & av , "-q" ) ;
850
852
if (fsck_objects )
851
- unpacker [i ++ ] = "--strict" ;
852
- unpacker [i ++ ] = hdr_arg ;
853
- unpacker [i ++ ] = NULL ;
854
- memset (& child , 0 , sizeof (child ));
855
- child .argv = unpacker ;
853
+ argv_array_push (& av , "--strict" );
854
+ child .argv = av .argv ;
856
855
child .no_stdout = 1 ;
857
856
child .err = err_fd ;
858
857
child .git_cmd = 1 ;
859
- code = run_command (& child );
860
- if (!code )
861
- return NULL ;
862
- return "unpack-objects abnormal exit" ;
858
+ status = run_command (& child );
859
+ if (status )
860
+ return "unpack-objects abnormal exit" ;
863
861
} else {
864
- const char * keeper [7 ];
865
- int s , status , i = 0 ;
862
+ int s ;
866
863
char keep_arg [256 ];
867
- struct child_process ip ;
868
864
869
865
s = sprintf (keep_arg , "--keep=receive-pack %" PRIuMAX " on " , (uintmax_t ) getpid ());
870
866
if (gethostname (keep_arg + s , sizeof (keep_arg ) - s ))
871
867
strcpy (keep_arg + s , "localhost" );
872
868
873
- keeper [ i ++ ] = "index-pack" ;
874
- keeper [ i ++ ] = "--stdin" ;
869
+ argv_array_pushl ( & av , "index-pack" ,
870
+ "--stdin" , hdr_arg , keep_arg , NULL ) ;
875
871
if (fsck_objects )
876
- keeper [ i ++ ] = "--strict" ;
872
+ argv_array_push ( & av , "--strict" ) ;
877
873
if (fix_thin )
878
- keeper [i ++ ] = "--fix-thin" ;
879
- keeper [i ++ ] = hdr_arg ;
880
- keeper [i ++ ] = keep_arg ;
881
- keeper [i ++ ] = NULL ;
882
- memset (& ip , 0 , sizeof (ip ));
883
- ip .argv = keeper ;
884
- ip .out = -1 ;
885
- ip .err = err_fd ;
886
- ip .git_cmd = 1 ;
887
- status = start_command (& ip );
888
- if (status ) {
874
+ argv_array_push (& av , "--fix-thin" );
875
+ child .argv = av .argv ;
876
+ child .out = -1 ;
877
+ child .err = err_fd ;
878
+ child .git_cmd = 1 ;
879
+ status = start_command (& child );
880
+ if (status )
889
881
return "index-pack fork failed" ;
890
- }
891
- pack_lockfile = index_pack_lockfile (ip .out );
892
- close (ip .out );
893
- status = finish_command (& ip );
894
- if (!status ) {
895
- reprepare_packed_git ();
896
- return NULL ;
897
- }
898
- return "index-pack abnormal exit" ;
882
+ pack_lockfile = index_pack_lockfile (child .out );
883
+ close (child .out );
884
+ status = finish_command (& child );
885
+ if (status )
886
+ return "index-pack abnormal exit" ;
887
+ reprepare_packed_git ();
899
888
}
889
+ return NULL ;
900
890
}
901
891
902
892
static const char * unpack_with_sideband (void )
0 commit comments