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

Re: [PATCH v3] commit.c: use skip_prefix() instead of starts_with()

From
Max Horn <max@quendi.de>
Date
Mar 4, 2014, 19:16 UTC
Message-ID
<8CB399B0-6781-4702-9EC5-0D0A0CCC3450@quendi.de>
In-Reply-To
<1393922540-13156-1-git-send-email-tanayabh@gmail.com>
On 04.03.2014, at 09:42, Tanay Abhra <tanayabh@gmail.com> wrote:
[...]
Show 7 quoted lines
> commit.c | 17 +++++++++--------
> 1 file changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/commit.c b/commit.c
> index 6bf4fe0..6c92acb 100644
> --- a/commit.c
> +++ b/commit.c
[...]
Show 20 quoted lines
> @@ -566,14 +566,16 @@ static void record_author_date(struct author_date_slab *author_date,
> 	     buf;
> 	     buf = line_end + 1) {
> 		line_end = strchrnul(buf, '\n');
> -		if (!starts_with(buf, "author ")) {
> +		ident_line = skip_prefix(buf, "author ");
> +		if (!ident_line) {
> 			if (!line_end[0] || line_end[1] == '\n')
> 				return; /* end of header */
> 			continue;
> 		}
> +		buf = ident_line;
> 		if (split_ident_line(&ident,
> -				     buf + strlen("author "),
> -				     line_end - (buf + strlen("author "))) ||
> +				     buf,
> +				     line_end - buf) ||
> 		    !ident.date_begin || !ident.date_end)
> 			goto fail_exit; /* malformed "author" line */
> 		break;
Why not get rid of that assignment to "buf", and use ident_line instead of buf below? That seems like it would be more readable, wouldn't it?
Show 10 quoted lines
> @@ -1193,10 +1195,9 @@ static void parse_gpg_output(struct signature_check *sigc)
> 	for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
> 		const char *found, *next;
> 
> -		if (starts_with(buf, sigcheck_gpg_status[i].check + 1)) {
> -			/* At the very beginning of the buffer */
> -			found = buf + strlen(sigcheck_gpg_status[i].check + 1);
> -		} else {
> +		found = skip_prefix(buf, sigcheck_gpg_status[i].check + 1);
> +		/* At the very beginning of the buffer */
Do we really need that comment, and in that spot? The code seemed clear enough to me without it. But if you think keeping is better, perhaps move it to *before* the skip_prefix, and add a trailing "?"
> +		if(!found) {
> 			found = strstr(buf, sigcheck_gpg_status[i].check);
> 			if (!found)
> 				continue;
Previous: Tanay AbhraNext: Junio C Hamano
Message 2 of 4 in “commit.c: use skip_prefix() instead of starts_with()”
  1. commit.c: use skip_prefix() instead of starts_with()Tanay Abhra, Mar 4, 2014
  2. Max HornMar 4, 2014
  3. Junio C HamanoMar 4, 2014
  4. Junio C HamanoMar 4, 2014

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.