From: Jeff King Date: Thu, 26 Mar 2026 23:14:15 GMT Subject: Re: [PATCH 1/4] revision: make handle_dotdot() interface less confusing Message-ID: <20260326231415.GA420281@coredump.intra.peff.net> In-Reply-To: On Thu, Mar 26, 2026 at 12:28:15PM -0700, Junio C Hamano wrote: > > 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. > 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