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

Re: [PATCH] add -p: fix counting empty context lines in edited patches

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jun 1, 2018, 20:03 UTC
Message-ID
<CAPig+cSSj2ETXfk8FYUc+=tE6bfoRuqF5Ld4kOgE4+DDpfL+BA@mail.gmail.com>
In-Reply-To
<20180601174644.13055-1-phillip.wood@talktalk.net>
On Fri, Jun 1, 2018 at 1:46 PM, Phillip Wood <phillip.wood@talktalk.net> wrote:
Show 13 quoted lines
> recount_edited_hunk() introduced in commit 2b8ea7f3c7 ("add -p:
> calculate offset delta for edited patches", 2018-03-05) required all
> context lines to start with a space, empty lines are not counted. This
> was intended to avoid any recounting problems if the user had
> introduced empty lines at the end when editing the patch. However this
> introduced a regression into 'git add -p' as it seems it is common for
> editors to strip the trailing whitespace from empty context lines when
> patches are edited thereby introducing empty lines that should be
> counted. 'git apply' knows how to deal with such empty lines and POSIX
> states that whether or not there is an space on an empty context line
> is implementation defined [1].
>
> Fix the regression by counting lines consist solely of a newline as

s/consist/&ing/ --or-- s/consist/that &/

Show 10 quoted lines
> well as lines starting with a space as context lines and add a test to
> prevent future regressions.
>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
>  git-add--interactive.perl  |  2 +-
> diff --git a/git-add--interactive.perl b/git-add--interactive.perl
> @@ -1047,7 +1047,7 @@ sub recount_edited_hunk {
> -               } elsif ($mode eq ' ') {
> +               } elsif ($mode eq ' ' or $_ eq "\n") {

Based upon a very cursory read of parts of git-add-interactive.perl, do I understand correctly that we don't have to worry about $_ ever being "\r\n" on Windows?

Show 28 quoted lines
> diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
> @@ -175,6 +175,49 @@ test_expect_success 'real edit works' '
> +test_expect_success 'setup file' '
> +       test_write_lines a "" b "" c >file &&
> +       git add file &&
> +       test_write_lines a "" d "" c >file
> +'
> +
> +test_expect_success 'setup patch' '
> +       SP=" " &&
> +       NULL="" &&
> +       cat >patch <<-EOF
> +       [...]
> +       EOF
> +'
> +
> +test_expect_success 'setup expected' '
> +       cat >expected <<-EOF
> +       [...]
> +       EOF
> +'
> +
> +test_expect_success 'edit can strip spaces from empty context lines' '
> +       test_write_lines e n q | git add -p 2>error &&
> +       test_must_be_empty error &&
> +       git diff >output &&
> +       diff_cmp expected output
> +'

I would have expected all the setup work to be contained directly in the sole test which needs it rather than spread over three tests (two of which are composed of a single command). Not a big deal, and not worth a re-roll.

Previous: Jacob KellerNext: Phillip Wood
Message 17 of 22 in “Regression in patch add?”
  1. mqudsi@neosmart.netApr 15, 2018
  2. Martin ÅgrenApr 15, 2018
  3. Phillip WoodApr 16, 2018
  4. Phillip WoodApr 16, 2018
  5. Oliver Joseph AshMay 10, 2018
  6. Martin ÅgrenMay 10, 2018
  7. Oliver Joseph AshMay 10, 2018
  8. Martin ÅgrenMay 10, 2018
  9. Phillip WoodMay 10, 2018
  10. Oliver Joseph AshMay 10, 2018
  11. Phillip WoodMay 10, 2018
  12. Junio C HamanoMay 11, 2018
  13. Phillip WoodMay 11, 2018
  14. Oliver Joseph AshMay 10, 2018
  15. add -p: fix counting empty context lines in edited patchesPhillip Wood, Jun 1, 2018
  16. Jacob KellerJun 1, 2018
  17. Eric SunshineJun 1, 2018
  18. Phillip WoodJun 4, 2018
  19. Eric SunshineJun 4, 2018
  20. add -p: fix counting empty context lines in edited patchesPhillip Wood, Jun 11, 2018
  21. Jeff FelchnerJul 11, 2018
  22. Junio C HamanoJul 11, 2018

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.