D3456: revlog: extract function for getting node from known-to-exist rev

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Tue May 8 08:47:01 EDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHGa91f31a1e281: revlog: extract function for getting node from known-to-exist rev (authored by martinvonz, committed by ).

CHANGED PRIOR TO COMMIT
  https://phab.mercurial-scm.org/D3456?vs=8481&id=8510#toc

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3456?vs=8481&id=8510

REVISION DETAIL
  https://phab.mercurial-scm.org/D3456

AFFECTED FILES
  mercurial/cext/revlog.c

CHANGE DETAILS

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -248,6 +248,20 @@
 	return data ? data + 32 : NULL;
 }
 
+/*
+ * Return the 20-byte SHA of the node corresponding to the given rev. The
+ * rev is assumed to be existing. If not, an exception is set.
+ */
+static const char *index_node_existing(indexObject *self, Py_ssize_t pos)
+{
+	const char *node = index_node(self, pos);
+	if (node == NULL) {
+		PyErr_Format(PyExc_IndexError, "could not access rev %d",
+		             (int)pos);
+	}
+	return node;
+}
+
 static int nt_insert(indexObject *self, const char *node, int rev);
 
 static int node_check(PyObject *obj, char **node, Py_ssize_t *nodelen)
@@ -1282,10 +1296,8 @@
 		return PyBytes_FromStringAndSize(nullid, 20);
 	}
 
-	fullnode = index_node(self, rev);
+	fullnode = index_node_existing(self, rev);
 	if (fullnode == NULL) {
-		PyErr_Format(PyExc_IndexError,
-			     "could not access rev %d", rev);
 		return NULL;
 	}
 	return PyBytes_FromStringAndSize(fullnode, 20);



To: martinvonz, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list