rust/hg-cpython/src/filepatterns.rs
branchstable
changeset 43466 4f1cddd1939e
parent 43465 a264e8a91798
child 43467 b06cf2809ec3
equal deleted inserted replaced
43465:a264e8a91798 43466:4f1cddd1939e
    13 //!
    13 //!
    14 use crate::exceptions::{PatternError, PatternFileError};
    14 use crate::exceptions::{PatternError, PatternFileError};
    15 use cpython::{
    15 use cpython::{
    16     PyBytes, PyDict, PyModule, PyObject, PyResult, PyTuple, Python, ToPyObject,
    16     PyBytes, PyDict, PyModule, PyObject, PyResult, PyTuple, Python, ToPyObject,
    17 };
    17 };
    18 use hg::{
    18 use hg::utils::files;
    19     build_single_regex, read_pattern_file, utils::files::get_path_from_bytes,
    19 use hg::{build_single_regex, read_pattern_file, LineNumber, PatternTuple};
    20     LineNumber, PatternTuple,
       
    21 };
       
    22 use std::path::PathBuf;
    20 use std::path::PathBuf;
    23 
    21 
    24 /// Rust does not like functions with different return signatures.
    22 /// Rust does not like functions with different return signatures.
    25 /// The 3-tuple version is always returned by the hg-core function,
    23 /// The 3-tuple version is always returned by the hg-core function,
    26 /// the (potential) conversion is handled at this level since it is not likely
    24 /// the (potential) conversion is handled at this level since it is not likely
    36     file_path: PyObject,
    34     file_path: PyObject,
    37     warn: bool,
    35     warn: bool,
    38     source_info: bool,
    36     source_info: bool,
    39 ) -> PyResult<PyTuple> {
    37 ) -> PyResult<PyTuple> {
    40     let bytes = file_path.extract::<PyBytes>(py)?;
    38     let bytes = file_path.extract::<PyBytes>(py)?;
    41     let path = get_path_from_bytes(bytes.data(py));
    39     let path = files::get_path_from_bytes(bytes.data(py));
    42     match read_pattern_file(path, warn) {
    40     match read_pattern_file(path, warn) {
    43         Ok((patterns, warnings)) => {
    41         Ok((patterns, warnings)) => {
    44             if source_info {
    42             if source_info {
    45                 let itemgetter = |x: &PatternTuple| {
    43                 let itemgetter = |x: &PatternTuple| {
    46                     (PyBytes::new(py, &x.0), x.1, PyBytes::new(py, &x.2))
    44                     (PyBytes::new(py, &x.0), x.1, PyBytes::new(py, &x.2))