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

Re: [PATCH] Re-re-re-fix common tail optimization

From
Jeff King <peff@peff.net>
Date
Dec 16, 2007, 22:15 UTC
Message-ID
<20071216221545.GA32596@coredump.intra.peff.net>
In-Reply-To
<7v3au2joo2.fsf_-_@gitster.siamese.dyndns.org>
On Sun, Dec 16, 2007 at 01:49:17PM -0800, Junio C Hamano wrote:
> Kind'a embarrassing that both of us cannot get this right without so
> many rounds, isn't it?
Good thing we can just delete the emails and nobody will be the wiser...
> +echo >expect <<\EOF
This would probably work better as 'cat'.
> +test_expect_success 'diff -U0' '
> +
> +	git diff -U0 | sed -e "/^index/d" -e "s/$z2047/Z/g" >actual &&
> +	diff -u expect actual
Aren't we using "git diff" for the second diff there nowadays?
Show 5 quoted lines
> -	while (recovered < trimmed && ctx)
> +	while (recovered < trimmed && 0 <= ctx)
>  		if (ap[recovered++] == '\n')
>  			ctx--;
>  	a->size -= (trimmed - recovered);

Oops (I think maybe I misunderstood what you were asking in the last email). This fix is correct, though the code is now kind of subtle. I think it would be more obvious as:

  /* finish off any changed line we are in */
  while (recovered < trimmed && ap[recovered++] != '\n')
    /* nothing */;
  /* recover context lines */
  while (recovered < trimmed && ctx)
    if (ap[recovered++] == '\n')
      ctx--;

Your loop does both actions in the same loop, which is correct, but took me 10 minutes of thinking and staring to realize what was going on.

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 10 of 30 in “trim_common_tail bug?”
  1. Jeff KingDec 15, 2007
  2. Jeff KingDec 15, 2007
  3. Junio C HamanoDec 15, 2007
  4. Jeff KingDec 15, 2007
  5. Jeff KingDec 16, 2007
  6. Junio C HamanoDec 16, 2007
  7. Junio C HamanoDec 16, 2007
  8. Jeff KingDec 16, 2007
  9. Re-re-re-fix common tail optimizationJunio C Hamano, Dec 16, 2007
  10. Jeff KingDec 16, 2007
  11. Junio C HamanoDec 16, 2007
  12. Junio C HamanoDec 16, 2007
  13. Jeff KingDec 16, 2007
  14. Wincent ColaiutaDec 17, 2007
  15. Johannes SchindelinDec 17, 2007
  16. Wincent ColaiutaDec 17, 2007
  17. Johannes SchindelinDec 17, 2007
  18. Wincent ColaiutaDec 17, 2007
  19. Jeff KingDec 17, 2007
  20. Johannes SixtDec 17, 2007
  21. Johannes SchindelinDec 17, 2007
  22. Junio C HamanoDec 17, 2007
  23. Johannes SchindelinDec 17, 2007
  24. Charles BaileyDec 19, 2007
  25. Jeff KingDec 19, 2007
  26. Charles BaileyDec 19, 2007
  27. Junio C HamanoDec 20, 2007
  28. Wincent ColaiutaDec 20, 2007
  29. Charles BaileyDec 20, 2007
  30. Junio C HamanoDec 20, 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.