# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 2018-05-05 05:04:44
# Node ID a9d9802d577e8c73e0d4316d178474d700f37bbd
# Parent  a91f31a1e2815c6fa065b9b501ddbbd02ebd2b73

revlog: don't say "not found" on internal error

If index_node() returned NULL, then index_find_node() and and
nt_partialmatch() used to return -2 to signal that the node was not
found. However, we were passing in a revnum to index_node() that we
knew should exist, so the only reason it could return NULL was due to
some internal error or perhaps out of memory. Let's not use "not
found" for these cases. I suppose we never noticed this because these
error never happen in practice.

I think there are more places where we should error out instead of
reporting that the node was not found, but the cases mentioned above
were all I cared about right now (because using the same error code
for all failures simplified some future patches).

Differential Revision: https://phab.mercurial-scm.org/D3457

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -1151,9 +1151,9 @@ static int index_find_node(indexObject *
 	 */
 	if (self->ntmisses++ < 4) {
 		for (rev = self->ntrev - 1; rev >= 0; rev--) {
-			const char *n = index_node(self, rev);
+			const char *n = index_node_existing(self, rev);
 			if (n == NULL)
-				return -2;
+				return -3;
 			if (memcmp(node, n, nodelen > 20 ? 20 : nodelen) == 0) {
 				if (nt_insert(self, n, rev) == -1)
 					return -3;
@@ -1162,11 +1162,9 @@ static int index_find_node(indexObject *
 		}
 	} else {
 		for (rev = self->ntrev - 1; rev >= 0; rev--) {
-			const char *n = index_node(self, rev);
-			if (n == NULL) {
-				self->ntrev = rev + 1;
-				return -2;
-			}
+			const char *n = index_node_existing(self, rev);
+			if (n == NULL)
+				return -3;
 			if (nt_insert(self, n, rev) == -1) {
 				self->ntrev = rev + 1;
 				return -3;
@@ -1243,9 +1241,9 @@ static int nt_partialmatch(indexObject *
 	if (self->ntrev > 0) {
 		/* ensure that the radix tree is fully populated */
 		for (rev = self->ntrev - 1; rev >= 0; rev--) {
-			const char *n = index_node(self, rev);
+			const char *n = index_node_existing(self, rev);
 			if (n == NULL)
-				return -2;
+				return -3;
 			if (nt_insert(self, n, rev) == -1)
 				return -3;
 		}