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

Re: [PATCH 4/3] archive: specfile syntax change: "$Format:%PLCHLDR$" instead of just "%PLCHLDR"

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Sep 6, 2007, 20:35 UTC
Message-ID
<46E0647A.10000@lsrfire.ath.cx>
In-Reply-To
<Pine.LNX.4.64.0709061803590.28586@racer.site>
Johannes Schindelin schrieb:
Show 5 quoted lines
>> +static void *format_specfile(const struct commit *commit, const char *format,
>> +                             unsigned long *sizep)
> 
> Should this not be "char *buffer" instead of "const char *format"?  Or 
> even better: a "struct strbuf *"?

const is correct, because the data in the buffer shouldn't be (and isn't) modified.

"buffer" is a generic term; "format" on the other hand indicates the meaning of the data within the buffer.

Input and output might indeed be passed along as struct strbuf, even more so since the new API encourages its use as generic buffer (format can contain NULs).

Show 11 quoted lines
>> +{
>> +	unsigned long len = *sizep, result_len = 0;
>> +	const char *a = format;
>> +	char *result = NULL;
>> +
>> +	for (;;) {
>> +		const char *b, *c;
>> +		char *fmt, *formatted = NULL;
>> +		unsigned long a_len, fmt_len, formatted_len, allocated = 0;
> 
> Maybe initialise formatted_len, just to be on the safe side?

I wish I could use C99 syntax and move its declaration down to its first use, then it would be obvious that formatted_len is never used without initialization.

Show 6 quoted lines
>> +
>> +		b = memchr(a, '$', len);
>> +		if (!b || a + len < b + 9 || memcmp(b + 1, "Format:", 7))
>> +			break;
> 
> Wouldn't memmem(buffer, len, "$Format:", 8) be better here?

Oh, that's a nice GNU extension, didn't know it before. We might import it to compat etc., but I think that's better left for a follow-up patch.

> A general comment: since you plan to output the result into a file anyway, 
> it should be even easier to avoid realloc(), and do a 
> print_formatted_specfile() instead of a format_specfile(), no?

Hmm, not sure what you mean. At least archive-tar needs the expanded contents in a buffer (not immediately written to stdout) because it tries to mimic a real tar and always writes in blocks of 10k and therefore needs to buffer the output.

Thanks! René

Previous: Johannes SchindelinNext: René Scharfe
Message 13 of 25 in “archive: specfile support (--pretty=format: in archive files)”
  1. 2/3 archive: specfile support (--pretty=format: in archive files)René Scharfe, Sep 3, 2007
  2. Johannes SchindelinSep 3, 2007
  3. David KastrupSep 3, 2007
  4. René ScharfeSep 4, 2007
  5. Junio C HamanoSep 3, 2007
  6. Andreas EricssonSep 4, 2007
  7. Johannes SchindelinSep 4, 2007
  8. René ScharfeSep 4, 2007
  9. Johannes SchindelinSep 5, 2007
  10. Junio C HamanoSep 5, 2007
  11. 4/3 archive: specfile syntax change: "$Format:%PLCHLDR$" instead of just "%PLCHLDR"René Scharfe, Sep 6, 2007
  12. Johannes SchindelinSep 6, 2007
  13. René ScharfeSep 6, 2007
  14. René ScharfeSep 6, 2007
  15. Junio C HamanoSep 6, 2007
  16. Johannes SchindelinSep 7, 2007
  17. 5/3 add memmem()René Scharfe, Sep 6, 2007
  18. 4/3 archive: specfile syntax change: "$Format:%PLCHLDR$" instead of just "%PLCHLDR" (take 2)René Scharfe, Sep 6, 2007
  19. 5/3 archive: rename attribute specfile to export-substRené Scharfe, Sep 6, 2007
  20. Johannes SchindelinSep 6, 2007
  21. René ScharfeSep 6, 2007
  22. Junio C HamanoSep 6, 2007
  23. Johannes SchindelinSep 7, 2007
  24. René ScharfeSep 4, 2007
  25. Junio C HamanoSep 5, 2007

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.