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

Re: [PATCH 2/2] fast-import: duplicate into history rather than passing ownership

From
René Scharfe <l.s.r@web.de>
Date
Aug 25, 2019, 14:21 UTC
Message-ID
<248c5f9f-ba44-6dec-6f30-f7d193bc22bb@web.de>
In-Reply-To
<20190825100213.fssjydohathfhhe5@glandium.org>
Am 25.08.19 um 12:02 schrieb Mike Hommey:
Show 22 quoted lines
> On Sun, Aug 25, 2019 at 04:10:55AM -0400, Jeff King wrote:
>> diff --git a/fast-import.c b/fast-import.c
>> index ee7258037a..1f9160b645 100644
>> --- a/fast-import.c
>> +++ b/fast-import.c
>> @@ -1763,7 +1763,6 @@ static int read_next_command(void)
>>  		} else {
>>  			struct recent_command *rc;
>>
>> -			strbuf_detach(&command_buf, NULL);
>>  			stdin_eof = strbuf_getline_lf(&command_buf, stdin);
>>  			if (stdin_eof)
>>  				return EOF;
>> @@ -1784,7 +1783,7 @@ static int read_next_command(void)
>>  				free(rc->buf);
>>  			}
>>
>> -			rc->buf = command_buf.buf;
>> +			rc->buf = xstrdup(command_buf.buf);
>
> You could xstrndup(command_buf.buf, command_buf.len), which would avoid
> a hidden strlen.

xstrndup() also searches for NUL, albeit with memchr(3). xmemdupz() would copy without checking.

I suspect the simplicity of xstrdup() outweighs the benefits of the alternatives, but didn't do any measurements..

René
Previous: Mike HommeyNext: Jeff King
Message 11 of 15 in “fast-import: Reinitialize command_buf rather than detach it.”
  1. fast-import: Reinitialize command_buf rather than detach it.Mike Hommey, Aug 25, 2019
  2. Jeff KingAug 25, 2019
  3. Mike HommeyAug 25, 2019
  4. Jeff KingAug 25, 2019
  5. 0/2 fast-import input string handling bugsJeff King, Aug 25, 2019
  6. 1/2 fast-import: duplicate parsed encoding stringJeff King, Aug 25, 2019
  7. Elijah NewrenAug 26, 2019
  8. Jeff KingAug 26, 2019
  9. 2/2 fast-import: duplicate into history rather than passing ownershipJeff King, Aug 25, 2019
  10. Mike HommeyAug 25, 2019
  11. René ScharfeAug 25, 2019
  12. Jeff KingAug 26, 2019
  13. Junio C HamanoAug 26, 2019
  14. Elijah NewrenAug 26, 2019
  15. René ScharfeAug 25, 2019

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.