shithub: Nail

Download patch

ref: 40df1e7a2bd21ecb5d81e303c705a9084d8bc3bf
parent: 1b2c1454a339e5fc8a1a619fe50031e2d2741d01
author: Ori Bernstein <[email protected]>
date: Sun Nov 8 00:45:12 EST 2020

fix mesglineno: handle nested threads

--- a/mbox.c
+++ b/mbox.c
@@ -124,31 +124,33 @@
 static int
 mesglineno(Mesg *msg, int *depth)
 {
-	Mesg *r, *m;
+	Mesg *p, *m;
 	int i, o, n, d;
 
 	o = 0;
 	d = 0;
 	n = 1;
-	r = msg;
-	if(msg->parent != nil) {
-		m = msg->parent;
-		for(i = 0; i < m->nchild; i++){
-			if(m->child[i] == msg)
+
+	/* Walk up to root, counting depth in the thread */
+	p = msg;
+	while(p->parent != nil){
+		m = p;
+		p = p->parent;
+		for(i = 0; i < p->nchild; i++){
+			if(p->child[i] == m)
 				break;
-			o += m->child[i]->nsub + 1;
+			o += p->child[i]->nsub + 1;
 		}
+		if(p->flags & Fdummy)
+			break;
+		o++;
+		d++;
 	}
-	while(r->parent != nil){
-		r = r->parent;
-		if(!(r->flags & Fdummy)){
-			o++;
-			d++;
-		}
-	}
+
+	/* Find the thread in the thread list */
 	for(i = 0; i < mbox.nmesg; i++){
 		m = mbox.mesg[i];
-		if(m == r)
+		if(m == p)
 			break;
 		if(m->parent == nil){
 			n += mbox.mesg[i]->nsub;