rust/hg-cpython/src/revlog.rs
changeset 51228 5807e3a8865e
parent 51226 1b23aaf5eb7b
child 51229 3551f2a1c963
equal deleted inserted replaced
51227:f9a52a9603f9 51228: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 }