Mercurial > hg
comparison rust/hg-cpython/src/revlog.rs @ 51231:5807e3a8865e
rust-python-index: don't panic on a corrupted index when calling from Python
This makes `test-verify.t` pass again. In an ideal world, we would find
the exact commit where this test breaks and amend part of this change there,
but this is a long enough series.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Tue, 31 Oct 2023 17:36:59 +0100 |
parents | 1b23aaf5eb7b |
children | 3551f2a1c963 |
comparison
equal
deleted
inserted
replaced
51230:f9a52a9603f9 | 51231:5807e3a8865e |
---|---|
673 bytes, | 673 bytes, |
674 IndexHeader::parse(&header.to_be_bytes()) | 674 IndexHeader::parse(&header.to_be_bytes()) |
675 .expect("default header is broken") | 675 .expect("default header is broken") |
676 .unwrap(), | 676 .unwrap(), |
677 ) | 677 ) |
678 .unwrap(), | 678 .map_err(|e| { |
679 revlog_error_with_msg(py, e.to_string().as_bytes()) | |
680 })?, | |
679 ), | 681 ), |
680 RefCell::new(None), | 682 RefCell::new(None), |
681 RefCell::new(None), | 683 RefCell::new(None), |
682 RefCell::new(None), | 684 RefCell::new(None), |
683 RefCell::new(Some(buf)), | 685 RefCell::new(Some(buf)), |
1050 cls.call(py, (py.None(),), None).ok().into_py_object(py), | 1052 cls.call(py, (py.None(),), None).ok().into_py_object(py), |
1051 ), | 1053 ), |
1052 } | 1054 } |
1053 } | 1055 } |
1054 | 1056 |
1057 fn revlog_error_with_msg(py: Python, msg: &[u8]) -> PyErr { | |
1058 match py | |
1059 .import("mercurial.error") | |
1060 .and_then(|m| m.get(py, "RevlogError")) | |
1061 { | |
1062 Err(e) => e, | |
1063 Ok(cls) => PyErr::from_instance( | |
1064 py, | |
1065 cls.call(py, (PyBytes::new(py, msg),), None) | |
1066 .ok() | |
1067 .into_py_object(py), | |
1068 ), | |
1069 } | |
1070 } | |
1071 | |
1055 fn graph_error(py: Python, _err: hg::GraphError) -> PyErr { | 1072 fn graph_error(py: Python, _err: hg::GraphError) -> PyErr { |
1056 // ParentOutOfRange is currently the only alternative | 1073 // ParentOutOfRange is currently the only alternative |
1057 // in `hg::GraphError`. The C index always raises this simple ValueError. | 1074 // in `hg::GraphError`. The C index always raises this simple ValueError. |
1058 PyErr::new::<ValueError, _>(py, "parent out of range") | 1075 PyErr::new::<ValueError, _>(py, "parent out of range") |
1059 } | 1076 } |