Thread (3 messages) 3 messages, 3 authors, 2026-02-22

Re: [PATCH 1/4] ref-filter: factor out refname component counting

From: Junio C Hamano <hidden>
Date: 2026-02-17 18:07:32

Jeff King [off-list ref] writes:
quoted hunk
+	if (len < 0) {
+		int i;
+		const char *p = refname;
+
+		/* Find total no of '/' separated path-components */
+		for (i = 0; p[i]; p[i] == '/' ? i++ : *p++)
+			;
Sorry, but I have no idea what this loop (copied verbatim from the
original) is trying to do.

We start at the beginning of the refname string, and while we are in
the leading run of '/' we increment i to find the end of that
run. E.g., we start with refname="///foo", p points at the leftmost
'/', i runs from 0 to 3 at which point p[i] points at the first
non-'/' character, at which point we do *p++, to make p point at the
second slash?  Is the dereferencing of the pointer in *p++ a no-op
that is there only to confuse readers?

And then p moves to the right until p[i] points at the end of the
string.  It does count the number of slashes in 'i', but there is no
satisfying simple answer to this question: "what does p mean while
this loop runs?".

Anyway, the conversion looks very faithful to the original.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help