mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 01:07:15 +03:00
treemanifest: add exception handling to newtreeiter.next
Summary: While debugging I noticed newtreeiter_iternext doesn't handle c++ exceptions. Let's handle it so the process doesn't crash entirely. Test Plan: Ran the tests. This kind of exception shouldn't be possible in normal execution, so there's not really a test to write. Reviewers: #mercurial, stash Reviewed By: stash Subscribers: mjpieters Differential Revision: https://phabricator.intern.facebook.com/D4880068 Signature: t1:4880068:1492590284:87f986dc9fa3650524d8c71f69c28971e2552640
This commit is contained in:
parent
f2405cda64
commit
b0e5a8d613
@ -222,29 +222,34 @@ static PyObject *newtreeiter_iternext(py_newtreeiter *self) {
|
||||
ManifestNode *p2 = NULL;
|
||||
std::string raw;
|
||||
std::string p1raw;
|
||||
while (iterator.next(&path, &result, &p1, &p2)) {
|
||||
result->manifest->serialize(raw);
|
||||
try {
|
||||
while (iterator.next(&path, &result, &p1, &p2)) {
|
||||
result->manifest->serialize(raw);
|
||||
|
||||
if (memcmp(p1->node, NULLID, BIN_NODE_SIZE) == 0) {
|
||||
p1raw.erase();
|
||||
} else {
|
||||
p1->manifest->serialize(p1raw);
|
||||
if (memcmp(p1->node, NULLID, BIN_NODE_SIZE) == 0) {
|
||||
p1raw.erase();
|
||||
} else {
|
||||
p1->manifest->serialize(p1raw);
|
||||
}
|
||||
|
||||
if (path->size() == 0) {
|
||||
// Record the root hash. This marks the tree as final and immutable.
|
||||
std::string hexnode;
|
||||
hexfrombin(result->node, hexnode);
|
||||
self->treemf->tm.root.update(hexnode.c_str(), MANIFEST_DIRECTORY_FLAGPTR);
|
||||
}
|
||||
|
||||
return Py_BuildValue("(s#s#s#s#s#s#)",
|
||||
path->c_str(), (Py_ssize_t)path->size(),
|
||||
result->node, (Py_ssize_t)BIN_NODE_SIZE,
|
||||
raw.c_str(), (Py_ssize_t)raw.size(),
|
||||
p1raw.c_str(), (Py_ssize_t)p1raw.size(),
|
||||
p1->node, (Py_ssize_t)BIN_NODE_SIZE,
|
||||
p2->node, (Py_ssize_t)BIN_NODE_SIZE);
|
||||
}
|
||||
|
||||
if (path->size() == 0) {
|
||||
// Record the root hash. This marks the tree as final and immutable.
|
||||
std::string hexnode;
|
||||
hexfrombin(result->node, hexnode);
|
||||
self->treemf->tm.root.update(hexnode.c_str(), MANIFEST_DIRECTORY_FLAGPTR);
|
||||
}
|
||||
|
||||
return Py_BuildValue("(s#s#s#s#s#s#)",
|
||||
path->c_str(), (Py_ssize_t)path->size(),
|
||||
result->node, (Py_ssize_t)BIN_NODE_SIZE,
|
||||
raw.c_str(), (Py_ssize_t)raw.size(),
|
||||
p1raw.c_str(), (Py_ssize_t)p1raw.size(),
|
||||
p1->node, (Py_ssize_t)BIN_NODE_SIZE,
|
||||
p2->node, (Py_ssize_t)BIN_NODE_SIZE);
|
||||
} catch (const std::exception &ex) {
|
||||
PyErr_SetString(PyExc_RuntimeError, ex.what());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user