git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] difftool: Change prompt to display the number of files in the diff queue

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Dec 4, 2013, 04:34 UTC
Message-ID
<CAPig+cTUB=UbY-j8mtz6QsvJKoA2T41u-wiR7Di596pM3t+k=Q@mail.gmail.com>
In-Reply-To
<1386120387-25300-1-git-send-email-zoltan.klinger@gmail.com>
On Tue, Dec 3, 2013 at 8:26 PM, Zoltan Klinger <zoltan.klinger@gmail.com> wrote:
Show 33 quoted lines
> 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?

Show 19 quoted lines
>         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()?
Show 15 quoted lines
> +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
Previous: Zoltan KlingerNext: Junio C Hamano
Message 2 of 3 in “difftool: Change prompt to display the number of files in the diff queue”
  1. difftool: Change prompt to display the number of files in the diff queueZoltan Klinger, Dec 4, 2013
  2. Eric SunshineDec 4, 2013
  3. Junio C HamanoDec 4, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.