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

Re: [PATCH 1/4] revision: make handle_dotdot() interface less confusing

From
Jeff King <peff@peff.net>
Date
Mar 26, 2026, 23:14 UTC
Message-ID
<20260326231415.GA420281@coredump.intra.peff.net>
In-Reply-To
<xmqqikaipf00.fsf@gitster.g>
On Thu, Mar 26, 2026 at 12:28:15PM -0700, Junio C Hamano wrote:
Show 7 quoted lines
> > There are two very subtle bits to the way we parse ".." (and "...")
> > range operators:
> >
> >  1. In handle_dotdot_1(), we assume that the incoming arguments "dotdot"
> >     and "arg" are part of the same string, with the first digit of the
> 
> "digit" -> "dot".
Oops, yeah.
Show 6 quoted lines
> OK.  I was hoping if we can do without a temporary allocation, but
> the const-string "..HEAD" example does make it clear that it is not
> something we can achieve easily.
> 
> And once we accept that it is inevitable to make a copy, everything
> else falls into the right place.

Yeah, I don't think there is another good option. We can drop the "const" from the interface, which would be more honest, but then callers that use string literals have to either make their own copy, or cast away the constness and pray.

The only "right" solution that avoids copying is if all of the lower-level functions learned to work with ptr/len pairs instead of NUL-terminated strings. But having done that sort of conversion before, it ends up quite messy and is prone to errors. Somebody is welcome to try tackling that if they want, but I don't. :)

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 10 of 24 in “ISOC23: quell warnings on discarding const”
  1. 0/6 ISOC23: quell warnings on discarding constMichael J Gruber, Mar 26, 2026
  2. 5/6 do not discard const: keep signatureMichael J Gruber, Mar 26, 2026
  3. Junio C HamanoMar 26, 2026
  4. 6/6 do not discard const: the ugly truthMichael J Gruber, Mar 26, 2026
  5. Junio C HamanoMar 26, 2026
  6. Jeff KingMar 26, 2026
  7. 0/4 fix const issues in revision parserJeff King, Mar 26, 2026
  8. 1/4 revision: make handle_dotdot() interface less confusingJeff King, Mar 26, 2026
  9. Junio C HamanoMar 26, 2026
  10. Jeff KingMar 26, 2026
  11. Junio C HamanoMar 27, 2026
  12. 2/4 rev-parse: simplify dotdot parsingJeff King, Mar 26, 2026
  13. 3/4 revision: avoid writing to const string for parent marksJeff King, Mar 26, 2026
  14. 4/4 rev-parse: avoid writing to const string for parent marksJeff King, Mar 26, 2026
  15. 1/6 do not discard const: the simple casesMichael J Gruber, Mar 26, 2026
  16. Jeff KingMar 26, 2026
  17. Junio C HamanoMar 26, 2026
  18. config: store allocated string in non-const pointerJeff King, Mar 26, 2026
  19. 4/6 do not discard const: declare const where we stay constMichael J Gruber, Mar 26, 2026
  20. 2/6 do not discard const: make git-compat-util ISOC23-likeMichael J Gruber, Mar 26, 2026
  21. 3/6 do not discard const: adjust to non-const data typesMichael J Gruber, Mar 26, 2026
  22. Junio C HamanoMar 26, 2026
  23. D. Ben KnobleMar 26, 2026
  24. Michael J GruberMar 27, 2026

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.