Re: [PATCH 1/4] revision: make handle_dotdot() interface less confusing
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 27, 2026, 15:55 UTC
- Message-ID
- <xmqqv7ehmfmh.fsf@gitster.g>
- In-Reply-To
- <20260326231415.GA420281@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 13 quoted lines
>> 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. :)
We would need to call out to a library function or system call eventually down the callchain, at which point you'd need to somehow come up with a NUL-terminated equivalent of that <ptr, len> pair.
So I would avoid going down that path, unless the language itself has already abstracted that difference away, and C is not among those languages.