rust/hg-cpython/src/parsers.rs
changeset 46439 68a15b5a7e58
parent 45610 496537c9c1b4
child 46440 776b97179c06
equal deleted inserted replaced
46438:39e9407820ac 46439:68a15b5a7e58
    13     exc, PyBytes, PyDict, PyErr, PyInt, PyModule, PyResult, PyTuple, Python,
    13     exc, PyBytes, PyDict, PyErr, PyInt, PyModule, PyResult, PyTuple, Python,
    14     PythonObject, ToPyObject,
    14     PythonObject, ToPyObject,
    15 };
    15 };
    16 use hg::{
    16 use hg::{
    17     pack_dirstate, parse_dirstate, utils::hg_path::HgPathBuf, DirstateEntry,
    17     pack_dirstate, parse_dirstate, utils::hg_path::HgPathBuf, DirstateEntry,
    18     DirstatePackError, DirstateParents, DirstateParseError, FastHashMap,
    18     DirstateParents, DirstateParseError, FastHashMap, PARENT_SIZE,
    19     PARENT_SIZE,
       
    20 };
    19 };
    21 use std::convert::TryInto;
    20 use std::convert::TryInto;
    22 
    21 
    23 use crate::dirstate::{extract_dirstate, make_dirstate_tuple};
    22 use crate::dirstate::{extract_dirstate, make_dirstate_tuple};
    24 use std::time::Duration;
    23 use std::time::Duration;
   126                     make_dirstate_tuple(py, &entry)?,
   125                     make_dirstate_tuple(py, &entry)?,
   127                 )?;
   126                 )?;
   128             }
   127             }
   129             Ok(PyBytes::new(py, &packed))
   128             Ok(PyBytes::new(py, &packed))
   130         }
   129         }
   131         Err(error) => Err(PyErr::new::<exc::ValueError, _>(
   130         Err(error) => {
   132             py,
   131             Err(PyErr::new::<exc::ValueError, _>(py, error.to_string()))
   133             match error {
   132         }
   134                 DirstatePackError::CorruptedParent => {
       
   135                     "expected a 20-byte hash".to_string()
       
   136                 }
       
   137                 DirstatePackError::CorruptedEntry(e) => e,
       
   138                 DirstatePackError::BadSize(expected, actual) => {
       
   139                     format!("bad dirstate size: {} != {}", actual, expected)
       
   140                 }
       
   141             },
       
   142         )),
       
   143     }
   133     }
   144 }
   134 }
   145 
   135 
   146 /// Create the module, with `__package__` given from parent
   136 /// Create the module, with `__package__` given from parent
   147 pub fn init_parsers_module(py: Python, package: &str) -> PyResult<PyModule> {
   137 pub fn init_parsers_module(py: Python, package: &str) -> PyResult<PyModule> {