Re: [PATCH v3 01/11] sequencer.c: rework search for start of footer to improve clarity

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Brandon Casey wrote:

> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -1024,16 +1024,19 @@ int sequencer_pick_revisions(struct replay_opts *opts)
>  static int ends_rfc2822_footer(struct strbuf *sb, int ignore_footer)
>  {
>  	int ch;
> -	int hit = 0;
> +	int last_char_was_nl, this_char_is_nl;
>  	int i, j, k;
>  	int len = sb->len - ignore_footer;
>  	int first = 1;
>  	const char *buf = sb->buf;
>  
> +	/* find start of last paragraph */
> +	last_char_was_nl = 0;
>  	for (i = len - 1; i > 0; i--) {
> -		if (hit && buf[i] == '\n')
> +		this_char_is_nl = (buf[i] == '\n');
> +		if (last_char_was_nl && this_char_is_nl)
>  			break;
> -		hit = (buf[i] == '\n');
> +		last_char_was_nl = this_char_is_nl;

I would have been tempted to write

	char prev;

	prev = 0;
	for (i = len - 1; i > 0; i--) {
		char ch = buf[i];
		if (prev == '\n' && ch == '\n')	/* paragraph break */
			break;
		prev = ch;
	}

but your rewrite is just as clear.  For what it's worth,
Reviewed-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]