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

Re: [PATCH] rebase: use strvec_pushf() for format-patch revisions

From
René Scharfe <l.s.r@web.de>
Date
Dec 20, 2023, 08:04 UTC
Message-ID
<47089803-c45b-4f33-b542-146c313f0902@web.de>
In-Reply-To
<xmqqmsu6ce0u.fsf@gitster.g>
Am 19.12.23 um 18:12 schrieb Junio C Hamano:
Show 14 quoted lines
> René Scharfe <l.s.r@web.de> writes:
>
>> In run_am(), a strbuf is used to create a revision argument that is then
>> added to the argument list for git format-patch using strvec_push().
>> Use strvec_pushf() to add it directly instead, simplifying the code.
>>
>> Signed-off-by: René Scharfe <l.s.r@web.de>
>> ---
>
> Makes sense.  Between the location of the original strbuf_addf()
> call and the new strvec_pushf() call, nobody mucks with *opts so
> this change won't affect the correctness.  We no longer use the
> extra strbuf, and upon failing to open the rebased-patches file,
> we no longer leak the contents of it.  Good.

Ha! I didn't even notice that leak on error. Perhaps the two release calls at the end gave me the illusion of cleanliness? Or more likely the opportunity to use strvec_pushf() grabbed my full attention (tunnel vision).

Show 55 quoted lines
>
>> @@ -615,34 +614,32 @@ static int run_am(struct rebase_options *opts)
>>  		return run_command(&am);
>>  	}
>>
>> -	strbuf_addf(&revisions, "%s...%s",
>> -		    oid_to_hex(opts->root ?
>> -			       /* this is now equivalent to !opts->upstream */
>> -			       &opts->onto->object.oid :
>> -			       &opts->upstream->object.oid),
>> -		    oid_to_hex(&opts->orig_head->object.oid));
>> -
>>  	rebased_patches = xstrdup(git_path("rebased-patches"));
>>  	format_patch.out = open(rebased_patches,
>>  				O_WRONLY | O_CREAT | O_TRUNC, 0666);
>>  	if (format_patch.out < 0) {
>>  		status = error_errno(_("could not open '%s' for writing"),
>>  				     rebased_patches);
>>  		free(rebased_patches);
>>  		strvec_clear(&am.args);
>>  		return status;
>>  	}
>>
>>  	format_patch.git_cmd = 1;
>>  	strvec_pushl(&format_patch.args, "format-patch", "-k", "--stdout",
>>  		     "--full-index", "--cherry-pick", "--right-only",
>>  		     "--default-prefix", "--no-renames",
>>  		     "--no-cover-letter", "--pretty=mboxrd", "--topo-order",
>>  		     "--no-base", NULL);
>>  	if (opts->git_format_patch_opt.len)
>>  		strvec_split(&format_patch.args,
>>  			     opts->git_format_patch_opt.buf);
>> -	strvec_push(&format_patch.args, revisions.buf);
>> +	strvec_pushf(&format_patch.args, "%s...%s",
>> +		     oid_to_hex(opts->root ?
>> +				/* this is now equivalent to !opts->upstream */
>> +				&opts->onto->object.oid :
>> +				&opts->upstream->object.oid),
>> +		     oid_to_hex(&opts->orig_head->object.oid));
>>  	if (opts->restrict_revision)
>>  		strvec_pushf(&format_patch.args, "^%s",
>>  			     oid_to_hex(&opts->restrict_revision->object.oid));
>> @@ -665,10 +662,8 @@ static int run_am(struct rebase_options *opts)
>>  			"As a result, git cannot rebase them."),
>>  		      opts->revisions);
>>
>> -		strbuf_release(&revisions);
>>  		return status;
>>  	}
>> -	strbuf_release(&revisions);
>>
>>  	am.in = open(rebased_patches, O_RDONLY);
>>  	if (am.in < 0) {
>> --
>> 2.43.0
Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 6 in “rebase: use strvec_pushf() for format-patch revisions”
  1. rebase: use strvec_pushf() for format-patch revisionsRené Scharfe, Dec 19, 2023
  2. Phillip WoodDec 19, 2023
  3. Patrick SteinhardtDec 19, 2023
  4. Junio C HamanoDec 19, 2023
  5. René ScharfeDec 20, 2023
  6. Junio C HamanoDec 20, 2023

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.