@@ -960,15 +960,15 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
960
960
return 0 ;
961
961
962
962
if (use_editor ) {
963
- char index [PATH_MAX ];
964
- const char * env [2 ] = { NULL };
965
- env [0 ] = index ;
966
- snprintf (index , sizeof (index ), "GIT_INDEX_FILE=%s" , index_file );
967
- if (launch_editor (git_path_commit_editmsg (), NULL , env )) {
963
+ struct argv_array env = ARGV_ARRAY_INIT ;
964
+
965
+ argv_array_pushf (& env , "GIT_INDEX_FILE=%s" , index_file );
966
+ if (launch_editor (git_path_commit_editmsg (), NULL , env .argv )) {
968
967
fprintf (stderr ,
969
968
_ ("Please supply the message using either -m or -F option.\n" ));
970
969
exit (1 );
971
970
}
971
+ argv_array_clear (& env );
972
972
}
973
973
974
974
if (!no_verify &&
@@ -1525,12 +1525,10 @@ static int git_commit_config(const char *k, const char *v, void *cb)
1525
1525
static int run_rewrite_hook (const unsigned char * oldsha1 ,
1526
1526
const unsigned char * newsha1 )
1527
1527
{
1528
- /* oldsha1 SP newsha1 LF NUL */
1529
- static char buf [2 * 40 + 3 ];
1530
1528
struct child_process proc = CHILD_PROCESS_INIT ;
1531
1529
const char * argv [3 ];
1532
1530
int code ;
1533
- size_t n ;
1531
+ struct strbuf sb = STRBUF_INIT ;
1534
1532
1535
1533
argv [0 ] = find_hook ("post-rewrite" );
1536
1534
if (!argv [0 ])
@@ -1546,34 +1544,33 @@ static int run_rewrite_hook(const unsigned char *oldsha1,
1546
1544
code = start_command (& proc );
1547
1545
if (code )
1548
1546
return code ;
1549
- n = snprintf (buf , sizeof (buf ), "%s %s\n" ,
1550
- sha1_to_hex (oldsha1 ), sha1_to_hex (newsha1 ));
1547
+ strbuf_addf (& sb , "%s %s\n" , sha1_to_hex (oldsha1 ), sha1_to_hex (newsha1 ));
1551
1548
sigchain_push (SIGPIPE , SIG_IGN );
1552
- write_in_full (proc .in , buf , n );
1549
+ write_in_full (proc .in , sb . buf , sb . len );
1553
1550
close (proc .in );
1551
+ strbuf_release (& sb );
1554
1552
sigchain_pop (SIGPIPE );
1555
1553
return finish_command (& proc );
1556
1554
}
1557
1555
1558
1556
int run_commit_hook (int editor_is_used , const char * index_file , const char * name , ...)
1559
1557
{
1560
- const char * hook_env [3 ] = { NULL };
1561
- char index [PATH_MAX ];
1558
+ struct argv_array hook_env = ARGV_ARRAY_INIT ;
1562
1559
va_list args ;
1563
1560
int ret ;
1564
1561
1565
- snprintf (index , sizeof (index ), "GIT_INDEX_FILE=%s" , index_file );
1566
- hook_env [0 ] = index ;
1562
+ argv_array_pushf (& hook_env , "GIT_INDEX_FILE=%s" , index_file );
1567
1563
1568
1564
/*
1569
1565
* Let the hook know that no editor will be launched.
1570
1566
*/
1571
1567
if (!editor_is_used )
1572
- hook_env [ 1 ] = "GIT_EDITOR=:" ;
1568
+ argv_array_push ( & hook_env , "GIT_EDITOR=:" ) ;
1573
1569
1574
1570
va_start (args , name );
1575
- ret = run_hook_ve (hook_env , name , args );
1571
+ ret = run_hook_ve (hook_env . argv , name , args );
1576
1572
va_end (args );
1573
+ argv_array_clear (& hook_env );
1577
1574
1578
1575
return ret ;
1579
1576
}
0 commit comments