On Tue, Dec 3, 2013 at 8:26 PM, Zoltan Klinger <zoltan.klin...@gmail.com> wrote:
> diff --git a/diff.c b/diff.c
> index e34bf97..c4078af 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -2899,11 +2899,18 @@ static void run_external_diff(const char *pgm,
>                               struct diff_filespec *one,
>                               struct diff_filespec *two,
>                               const char *xfrm_msg,
> -                             int complete_rewrite)
> +                             int complete_rewrite,
> +                             struct diff_options *o)
>  {
>         const char *spawn_arg[10];
>         int retval;
>         const char **arg = &spawn_arg[0];
> +       struct diff_queue_struct *q = &diff_queued_diff;
> +
> +       struct strbuf counterstr = STRBUF_INIT;
> +       struct strbuf totalstr = STRBUF_INIT;
> +       strbuf_addf(&counterstr, "%d", ++o->diff_path_counter);
> +       strbuf_addf(&totalstr, "%d", q->nr);
>
>         if (one && two) {
>                 struct diff_tempfile *temp_one, *temp_two;
> @@ -2928,8 +2935,14 @@ static void run_external_diff(const char *pgm,
>         }
>         *arg = NULL;
>         fflush(NULL);
> +
> +       setenv ("GIT_DIFF_PATH_COUNTER", counterstr.buf, 1);
> +       setenv ("GIT_DIFF_PATH_TOTAL", totalstr.buf, 1);
> +
>         retval = run_command_v_opt(spawn_arg, RUN_USING_SHELL);

Would run_command_v_opt_cd_env() be more appropriate than setenv() +
run_command_v_opt() done here?

>         remove_tempfile();
> +       strbuf_release(&counterstr);
> +       strbuf_release(&totalstr);
>         if (retval) {
>                 fprintf(stderr, "external diff died, stopping at %s.\n", 
> name);
>                 exit(1);
> diff --git a/t/t4020-diff-external.sh b/t/t4020-diff-external.sh
> index 8a30979..4935fc4 100755
> --- a/t/t4020-diff-external.sh
> +++ b/t/t4020-diff-external.sh
> @@ -193,6 +193,22 @@ test_expect_success 'GIT_EXTERNAL_DIFF with more than 
> one changed files' '
>         GIT_EXTERNAL_DIFF=echo git diff
>  '
>
> +echo "#!$SHELL_PATH" >external-diff.sh
> +cat >> external-diff.sh <<\EOF
> +echo $GIT_DIFF_PATH_COUNTER of $GIT_DIFF_PATH_TOTAL >>counter.txt
> +EOF
> +chmod a+x external-diff.sh

Perhaps write_script()?

> +test_expect_success 'GIT_EXTERNAL_DIFF path counter/total' '
> +       GIT_EXTERNAL_DIFF=./external-diff.sh git diff &&
> +       echo "1 of 2" >expect &&
> +       head -n 1 counter.txt >actual &&
> +       test_cmp expect actual &&
> +       echo "2 of 2" >expect &&
> +       tail -n 1 counter.txt >actual &&
> +       test_cmp expect actual
> +'
> +
>  test_expect_success 'GIT_EXTERNAL_DIFF generates pretty paths' '
>         touch file.ext &&
>         git add file.ext &&
> --
> 1.8.4.4
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to