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

Re: [PATCH v2 3/4] stripspace: Implement --count-lines option

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Oct 17, 2015, 23:57 UTC
Message-ID
<CAPig+cQ=8FO8yFY4sHUwr0mYuyvMu4d-eizHZeadE9f0BgpXpQ@mail.gmail.com>
In-Reply-To
<1445008605-16534-4-git-send-email-tklauser@distanz.ch>
On Fri, Oct 16, 2015 at 11:16 AM, Tobias Klauser <tklauser@distanz.ch> wrote:
> Implement the --count-lines options for git stripspace [...]
>
> This will make it easier to port git-rebase--interactive.sh to C later
> on.

Is there any application beyond git-rebase--interactive where a --count-lines options is expected to be useful? It's not obvious from the commit message that this change is necessarily a win for later porting of git-rebase--interactive to C since the amount of extra code and support material added by this patch probably outweighs the amount of code a C version of git-rebase--interactive would need to count the lines itself.

Stated differently, are the two or three instances of piping through 'wc' in git-rebase--interactive sufficient justification for introducing extra complexity into git-stripspace and its documentation and tests?

More below.
Show 17 quoted lines
> Furthermore, add the corresponding documentation and tests.
>
> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
> ---
> diff --git a/t/t0030-stripspace.sh b/t/t0030-stripspace.sh
> index 29e91d8..9c00cb9 100755
> --- a/t/t0030-stripspace.sh
> +++ b/t/t0030-stripspace.sh
> @@ -438,4 +438,40 @@ test_expect_success 'avoid SP-HT sequence in commented line' '
>         test_cmp expect actual
>  '
>
> +test_expect_success '--count-lines with newline only' '
> +       printf "0\n" >expect &&
> +       printf "\n" | git stripspace --count-lines >actual &&
> +       test_cmp expect actual
> +'

What is the expected behavior when the input is an empty file, a file with content but no newline, a file with one or more lines but lacking a newline on the final line? Should these cases be tested, as well?

Show 33 quoted lines
> +test_expect_success '--count-lines with single line' '
> +       printf "1\n" >expect &&
> +       printf "foo\n" | git stripspace --count-lines >actual &&
> +       test_cmp expect actual
> +'
> +
> +test_expect_success '--count-lines with single line preceeded by empty line' '
> +       printf "1\n" >expect &&
> +       printf "\nfoo" | git stripspace --count-lines >actual &&
> +       test_cmp expect actual
> +'
> +
> +test_expect_success '--count-lines with single line followed by empty line' '
> +       printf "1\n" >expect &&
> +       printf "foo\n\n" | git stripspace --count-lines >actual &&
> +       test_cmp expect actual
> +'
> +
> +test_expect_success '--count-lines with multiple lines and consecutive newlines' '
> +       printf "5\n" >expect &&
> +       printf "\none\n\n\nthree\nfour\nfive\n" | git stripspace --count-lines >actual &&
> +       test_cmp expect actual
> +'
> +
> +test_expect_success '--count-lines combined with --strip-comments' '
> +       printf "5\n" >expect &&
> +       printf "\n# stripped\none\n#stripped\n\nthree\nfour\nfive\n" | git stripspace -s --count-lines >actual &&
> +       test_cmp expect actual
> +'
> +
>  test_done
> --
> 2.6.1.148.g7927db1
Previous: Tobias KlauserNext: Junio C Hamano
Message 12 of 23 in “stripspace: Implement and use --count-lines option”
  1. 0/4 stripspace: Implement and use --count-lines optionTobias Klauser, Oct 16, 2015
  2. 1/4 strbuf: make stripspace() part of strbufTobias Klauser, Oct 16, 2015
  3. 2/4 stripspace: Use parse-options for command-line parsingTobias Klauser, Oct 16, 2015
  4. Junio C HamanoOct 16, 2015
  5. Junio C HamanoOct 16, 2015
  6. Tobias KlauserOct 17, 2015
  7. Junio C HamanoOct 17, 2015
  8. Tobias KlauserOct 20, 2015
  9. Junio C HamanoOct 20, 2015
  10. Tobias KlauserOct 17, 2015
  11. 3/4 stripspace: Implement --count-lines optionTobias Klauser, Oct 16, 2015
  12. Eric SunshineOct 17, 2015
  13. Junio C HamanoOct 18, 2015
  14. Tobias KlauserOct 19, 2015
  15. Christian CouderOct 19, 2015
  16. Eric SunshineOct 19, 2015
  17. Matthieu MoyOct 19, 2015
  18. Tobias KlauserOct 19, 2015
  19. 4/4 git rebase -i: Use newly added --count-lines option for stripspaceTobias Klauser, Oct 16, 2015
  20. Junio C HamanoOct 16, 2015
  21. Tobias KlauserOct 17, 2015
  22. Matthieu MoyOct 16, 2015
  23. Tobias KlauserOct 17, 2015

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.