shithub: git9

Download patch

ref: d69ce1ddfee9542e2163df305c22a15d5f62638c
parent: 5da4024d1a6b7cff917fea91db4ab3af99ae45da
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Jan 28 19:09:39 EST 2021

git/send: correct findref() (thanks igor.boehm)

Findref used to never return an error, which
was wrong. This makes it return an error, and
makes the code around it handle the error.

--- a/send.c
+++ b/send.c
@@ -27,8 +27,8 @@
 
 	for(i = 0; i < nr; i++)
 		if(strcmp(r[i], ref) == 0)
-			break;
-	return i;
+			return i;
+	return -1;
 }
 
 int
@@ -57,11 +57,9 @@
 			pfx = "";
 		if((r = smprint("%s%s", pfx, removed[i])) == nil)
 			sysfatal("smprint: %r");
-		if((idx = findref(ref, nu, r)) == nu)
-			nu = idx;
-		else
-			free(r);
-		memcpy(&tail[idx], &Zhash, sizeof(Hash));
+		if((idx = findref(ref, nu, r)) != -1)
+			memcpy(&tail[idx], &Zhash, sizeof(Hash));
+		free(r);
 	}
 	*tailp = tail;
 	*refp = ref;