@@ -331,7 +331,7 @@ static int checkout_path(unsigned mode, struct object_id *oid,
331
331
}
332
332
333
333
static int run_dir_diff (const char * extcmd , int symlinks , const char * prefix ,
334
- int argc , const char * * argv )
334
+ struct child_process * child )
335
335
{
336
336
char tmpdir [PATH_MAX ];
337
337
struct strbuf info = STRBUF_INIT , lpath = STRBUF_INIT ;
@@ -352,7 +352,6 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
352
352
struct index_state wtindex ;
353
353
struct checkout lstate , rstate ;
354
354
int rc , flags = RUN_GIT_CMD , err = 0 ;
355
- struct child_process child = CHILD_PROCESS_INIT ;
356
355
const char * helper_argv [] = { "difftool--helper" , NULL , NULL , NULL };
357
356
struct hashmap wt_modified , tmp_modified ;
358
357
int indices_loaded = 0 ;
@@ -387,19 +386,15 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
387
386
rdir_len = rdir .len ;
388
387
wtdir_len = wtdir .len ;
389
388
390
- child .no_stdin = 1 ;
391
- child .git_cmd = 1 ;
392
- child .use_shell = 0 ;
393
- child .clean_on_exit = 1 ;
394
- child .dir = prefix ;
395
- child .out = -1 ;
396
- strvec_pushl (& child .args , "diff" , "--raw" , "--no-abbrev" , "-z" ,
397
- NULL );
398
- for (i = 0 ; i < argc ; i ++ )
399
- strvec_push (& child .args , argv [i ]);
400
- if (start_command (& child ))
389
+ child -> no_stdin = 1 ;
390
+ child -> git_cmd = 1 ;
391
+ child -> use_shell = 0 ;
392
+ child -> clean_on_exit = 1 ;
393
+ child -> dir = prefix ;
394
+ child -> out = -1 ;
395
+ if (start_command (child ))
401
396
die ("could not obtain raw diff" );
402
- fp = xfdopen (child . out , "r" );
397
+ fp = xfdopen (child -> out , "r" );
403
398
404
399
/* Build index info for left and right sides of the diff */
405
400
i = 0 ;
@@ -525,7 +520,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
525
520
526
521
fclose (fp );
527
522
fp = NULL ;
528
- if (finish_command (& child )) {
523
+ if (finish_command (child )) {
529
524
ret = error ("error occurred running diff --raw" );
530
525
goto finish ;
531
526
}
@@ -668,25 +663,23 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
668
663
}
669
664
670
665
static int run_file_diff (int prompt , const char * prefix ,
671
- int argc , const char * * argv )
666
+ struct child_process * child )
672
667
{
673
- struct strvec args = STRVEC_INIT ;
674
668
const char * env [] = {
675
669
"GIT_PAGER=" , "GIT_EXTERNAL_DIFF=git-difftool--helper" , NULL ,
676
670
NULL
677
671
};
678
- int i ;
679
672
680
673
if (prompt > 0 )
681
674
env [2 ] = "GIT_DIFFTOOL_PROMPT=true" ;
682
675
else if (!prompt )
683
676
env [2 ] = "GIT_DIFFTOOL_NO_PROMPT=true" ;
684
677
678
+ child -> git_cmd = 1 ;
679
+ child -> dir = prefix ;
680
+ strvec_pushv (& child -> env_array , env );
685
681
686
- strvec_push (& args , "diff" );
687
- for (i = 0 ; i < argc ; i ++ )
688
- strvec_push (& args , argv [i ]);
689
- return run_command_v_opt_cd_env (args .v , RUN_GIT_CMD , prefix , env );
682
+ return run_command (child );
690
683
}
691
684
692
685
int cmd_difftool (int argc , const char * * argv , const char * prefix )
@@ -716,9 +709,10 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
716
709
"tool returns a non - zero exit code" )),
717
710
OPT_STRING ('x' , "extcmd" , & extcmd , N_ ("command" ),
718
711
N_ ("specify a custom command for viewing diffs" )),
719
- OPT_ARGUMENT ( "no-index" , & no_index , N_ ("passed to `diff`" )),
712
+ OPT_BOOL ( 0 , "no-index" , & no_index , N_ ("passed to `diff`" )),
720
713
OPT_END ()
721
714
};
715
+ struct child_process child = CHILD_PROCESS_INIT ;
722
716
723
717
git_config (difftool_config , NULL );
724
718
symlinks = has_symlinks ;
@@ -768,7 +762,14 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
768
762
* will invoke a separate instance of 'git-difftool--helper' for
769
763
* each file that changed.
770
764
*/
765
+ strvec_push (& child .args , "diff" );
766
+ if (no_index )
767
+ strvec_push (& child .args , "--no-index" );
768
+ if (dir_diff )
769
+ strvec_pushl (& child .args , "--raw" , "--no-abbrev" , "-z" , NULL );
770
+ strvec_pushv (& child .args , argv );
771
+
771
772
if (dir_diff )
772
- return run_dir_diff (extcmd , symlinks , prefix , argc , argv );
773
- return run_file_diff (prompt , prefix , argc , argv );
773
+ return run_dir_diff (extcmd , symlinks , prefix , & child );
774
+ return run_file_diff (prompt , prefix , & child );
774
775
}
0 commit comments