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

Re: [PATCH 5/5] patch-id: tighten code to detect the patch header

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 29, 2024, 20:12 UTC
Message-ID
<xmqqwml4gdol.fsf@gitster.g>
In-Reply-To
<ZqeGBJrqIrU2A4jl@tanuki>
Patrick Steinhardt <ps@pks.im> writes:
Show 18 quoted lines
> On Fri, Jun 21, 2024 at 04:18:26PM -0700, Junio C Hamano wrote:
>> @@ -196,11 +211,13 @@ static void generate_id_list(unsigned flags)
>>  	struct strbuf line_buf = STRBUF_INIT;
>>  
>>  	oidclr(&oid);
>> +	flags |= GOPID_FIND_HEADER;
>>  	while (!feof(stdin)) {
>>  		patchlen = get_one_patchid(&n, &result, &line_buf, flags);
>>  		if (patchlen)
>>  			flush_current_id(&oid, &result);
>>  		oidcpy(&oid, &n);
>> +		flags &= ~GOPID_FIND_HEADER;
>>  	}
>
> I think I'm missing the obvious. But why don't we have to set
> `GOPID_FIND_HEADER` when we have flushed the current patch ID? Is this
> because we know that `get_one_patchid()` stops once it finds the next
> line starting with a commit?

Yup the original control flow is rather convoluted. The first call stops when it finds the header that begins the log message part and returns, but the subsequent calls are to (1) skip the log message and then (2) parse and hash the diff part, until it finds another header that begins the log message part of the _next_ patch and return. GOPID_FIND_HEADER bit is used to tell the callee when we haven't found the header (hence we can stop at a line whose beginning looks like a hash) or the previous round already found the header and we positively know we are now in the "skip the log message" phase (hence a line whose beginning looks like a hash is not a new header).

> Makes me wonder what happens when there is
> non-diff garbage between patches for which we are about to generate
> patch IDs.

"Skip non-diff garbage until we see a patch" is the mechanism used to skip the log message, so it would be a reasonable thing to skip such no-diff garbage between patches, no?

Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 9 of 20 in “Tighten patch header parsing in patch-id”
  1. 0/5 Tighten patch header parsing in patch-idJunio C Hamano, Jun 21, 2024
  2. 1/5 t4204: patch-id supports various input formatJunio C Hamano, Jun 21, 2024
  3. 2/5 patch-id: call flush_current_id() only when neededJunio C Hamano, Jun 21, 2024
  4. 3/5 patch-id: make get_one_patchid() more extensibleJunio C Hamano, Jun 21, 2024
  5. Patrick SteinhardtJul 29, 2024
  6. Junio C HamanoJul 29, 2024
  7. 5/5 patch-id: tighten code to detect the patch headerJunio C Hamano, Jun 21, 2024
  8. Patrick SteinhardtJul 29, 2024
  9. Junio C HamanoJul 29, 2024
  10. Patrick SteinhardtJul 30, 2024
  11. Patrick SteinhardtJul 30, 2024
  12. 4/5 patch-id: rewrite code that detects the beginning of a patchJunio C Hamano, Jun 21, 2024
  13. Patrick SteinhardtJul 29, 2024
  14. 0/5 Tighten patch header parsing in patch-idJunio C Hamano, Jul 30, 2024
  15. 1/5 t4204: patch-id supports various input formatJunio C Hamano, Jul 30, 2024
  16. 2/5 patch-id: call flush_current_id() only when neededJunio C Hamano, Jul 30, 2024
  17. 3/5 patch-id: make get_one_patchid() more extensibleJunio C Hamano, Jul 30, 2024
  18. 4/5 patch-id: rewrite code that detects the beginning of a patchJunio C Hamano, Jul 30, 2024
  19. 5/5 patch-id: tighten code to detect the patch headerJunio C Hamano, Jul 30, 2024
  20. Patrick SteinhardtJul 30, 2024

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.