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

Re: [PATCH v3 2/7] bisect--helper: reimplement `bisect_replay` shell function in C

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 24, 2021, 05:13 UTC
Message-ID
<xmqqr1ma29z7.fsf@gitster.c.googlers.com>
In-Reply-To
<xmqq35yr2nh0.fsf@gitster.c.googlers.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 23 quoted lines
> Miriam Rubio <mirucam@gmail.com> writes:
>
>> From: Pranit Bauva <pranit.bauva@gmail.com>
>>
>> Reimplement the `bisect_replay` shell function in C and also add
>> `--bisect-replay` subcommand to `git bisect--helper` to call it from
>> git-bisect.sh
>> ...
>> +static int process_replay_line(struct bisect_terms *terms, struct strbuf *line)
>> +{
>> +	const char *p = line->buf + strspn(line->buf, " \t");
>> +
>> +	if ((!skip_prefix(p, "git bisect", &p) &&
>> +	!skip_prefix(p, "git-bisect", &p)) || !isspace(*p))
>> +		return 0;
>> +	p += strspn(p, " \t");
>> +
>> +	char *word_end = (char*)p + strcspn(p, " \t");
>> +	char *rev = word_end + strspn(word_end, " \t");
>
> Are these lines new in this round?
>
> These break builds with -Werror=declaration-after-statement.

The following fix-up is tentatively queued at the tip of the topic in tonight's pushout. There might be better way to do what this function is doing (especially I am skeptical about the way the code casts const away), so please don't blindly trust it, but at least it should please the compiler.

(char*) should be spelled (char *), by the way.
Thanks.
diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
index 3b0a6a7d0c..c673f87795 100644
--- a/builtin/bisect--helper.c
+++ b/builtin/bisect--helper.c
@@ -918,14 +918,15 @@ static enum bisect_error bisect_log(void)
 static int process_replay_line(struct bisect_terms *terms, struct strbuf *line)
 {
 	const char *p = line->buf + strspn(line->buf, " \t");
+	char *word_end, *rev;
 
 	if ((!skip_prefix(p, "git bisect", &p) &&
 	!skip_prefix(p, "git-bisect", &p)) || !isspace(*p))
 		return 0;
 	p += strspn(p, " \t");
 
-	char *word_end = (char*)p + strcspn(p, " \t");
-	char *rev = word_end + strspn(word_end, " \t");
+	word_end = (char*)p + strcspn(p, " \t");
+	rev = word_end + strspn(word_end, " \t");
 	*word_end = '\0'; /* NUL-terminate the word */
 
 	get_terms(terms);
-- 
2.30.0-492-gde1138eff7
Previous: Junio C HamanoNext: Miriam R.
Message 10 of 19 in “Finish converting git bisect to C part 3”
  1. 0/7 Finish converting git bisect to C part 3Miriam Rubio, Jan 23, 2021
  2. 1/7 bisect--helper: reimplement `bisect_log` shell function in CMiriam Rubio, Jan 23, 2021
  3. Rafael SilvaJan 24, 2021
  4. Miriam R.Jan 25, 2021
  5. Junio C HamanoJan 26, 2021
  6. Miriam R.Jan 27, 2021
  7. 3/7 bisect--helper: retire `--bisect-write` subcommandMiriam Rubio, Jan 23, 2021
  8. 2/7 bisect--helper: reimplement `bisect_replay` shell function in CMiriam Rubio, Jan 23, 2021
  9. Junio C HamanoJan 24, 2021
  10. Junio C HamanoJan 24, 2021
  11. Miriam R.Jan 25, 2021
  12. 5/7 bisect--helper: retire `--bisect-auto-next` subcommandMiriam Rubio, Jan 23, 2021
  13. 4/7 bisect--helper: use `res` instead of return in BISECT_RESET case optionMiriam Rubio, Jan 23, 2021
  14. 6/7 bisect--helper: reimplement `bisect_skip` shell function in CMiriam Rubio, Jan 23, 2021
  15. 7/7 bisect--helper: retire `--check-and-set-terms` subcommandMiriam Rubio, Jan 23, 2021
  16. Junio C HamanoJan 26, 2021
  17. Miriam R.Jan 26, 2021
  18. Junio C HamanoJan 26, 2021
  19. Miriam R.Jan 27, 2021

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.