Thread (1 message) 1 message, 1 author, 2019-06-11

Re: [PATCH v2 1/1] ref-filter: sort detached HEAD lines firstly

From: Junio C Hamano <hidden>
Date: 2019-06-11 20:10:48

Matthew DeVore [off-list ref] writes:
-	if (s->version)
+	if (s->version) {
 		cmp = versioncmp(va->s, vb->s);
-	else if (cmp_type == FIELD_STR)
-		cmp = cmp_fn(va->s, vb->s);
-	else {
Ah, this must be the patch noise Jonathan was (half) complaining
about.  It does make it a bit distracting to read the patch but the
resulting code is of course easier to follow ;-).
+	} else if (cmp_type == FIELD_STR) {
+		const int a_detached = a->kind & FILTER_REFS_DETACHED_HEAD;
+
+		/*
+		 * When sorting by name, we should put "detached" head lines,
+		 * which are all the lines in parenthesis, before all others.
+		 * This usually is automatic, since "(" is before "refs/" and
+		 * "remotes/", but this does not hold for zh_CN, which uses
+		 * full-width parenthesis, so make the ordering explicit.
+		 */
+		if (a_detached != (b->kind & FILTER_REFS_DETACHED_HEAD))
+			cmp = a_detached ? -1 : 1;
So, comparing a detached and an undetached ones, the detached side
always sorts lower.  Good.  And ...
+		else
+			cmp = cmp_fn(va->s, vb->s);
... otherwise we compare the string using the given function.

Sounds sensible.  Will queue.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help