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

Re: [PATCH v2 6/8] t0021/rot13-filter: refactor checking final lf

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 7, 2017, 01:18 UTC
Message-ID
<xmqqk1z2hon0.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20171105213836.11717-7-chriscool@tuxfamily.org>
Christian Couder <christian.couder@gmail.com> writes:
Show 35 quoted lines
> As checking for a lf character at the end of a buffer
> will be useful in another function, let's refactor this
> functionality into a small remove_final_lf_or_die()
> helper function.
>
> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
> ---
>  t/t0021/rot13-filter.pl | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/t/t0021/rot13-filter.pl b/t/t0021/rot13-filter.pl
> index 2f74ab2e45..d47b7f5666 100644
> --- a/t/t0021/rot13-filter.pl
> +++ b/t/t0021/rot13-filter.pl
> @@ -93,12 +93,20 @@ sub packet_bin_read {
>  	}
>  }
>  
> -sub packet_txt_read {
> -	my ( $res, $buf ) = packet_bin_read();
> -	unless ( $res == -1 or $buf eq '' or $buf =~ s/\n$// ) {
> +sub remove_final_lf_or_die {
> +	my $buf = shift;
> +	unless ( $buf =~ s/\n$// ) {
>  		die "A non-binary line MUST be terminated by an LF.\n"
>  		    . "Received: '$buf'";
>  	}
> +	return $buf;
> +}
> +
> +sub packet_txt_read {
> +	my ( $res, $buf ) = packet_bin_read();
> +	unless ( $res == -1 or $buf eq '' ) {
> +		$buf = remove_final_lf_or_die($buf);
> +	}

After patch 2/8 I found the "unless" in packet_txt_read impossible to read, but this makes it a bit more understandable.

Previous: Christian CouderNext: Christian Couder
Message 13 of 14 in “Create Git/Packet.pm”
  1. 0/8 Create Git/Packet.pmChristian Couder, Nov 5, 2017
  2. 1/8 t0021/rot13-filter: fix list comparisonChristian Couder, Nov 5, 2017
  3. Junio C HamanoNov 7, 2017
  4. 2/8 t0021/rot13-filter: refactor packet reading functionsChristian Couder, Nov 5, 2017
  5. Junio C HamanoNov 7, 2017
  6. Christian CouderNov 7, 2017
  7. 8/8 Add Git/Packet.pm from parts of t0021/rot13-filter.plChristian Couder, Nov 5, 2017
  8. 5/8 t0021/rot13-filter: add packet_initialize()Christian Couder, Nov 5, 2017
  9. 3/8 t0021/rot13-filter: improve 'if .. elsif .. else' styleChristian Couder, Nov 5, 2017
  10. 7/8 t0021/rot13-filter: add capability functionsChristian Couder, Nov 5, 2017
  11. Junio C HamanoNov 7, 2017
  12. 6/8 t0021/rot13-filter: refactor checking final lfChristian Couder, Nov 5, 2017
  13. Junio C HamanoNov 7, 2017
  14. 4/8 t0021/rot13-filter: improve error messageChristian Couder, Nov 5, 2017

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.