##// END OF EJS Templates
rust-dirs: address failing tests for `dirs` impl with a temporary fix...
Raphaël Gomès -
r44227:1fe2e574 default
parent child Browse files
Show More
@@ -65,14 +65,20 b' impl DirsMultiset {'
65 65 /// Increases the count of deepest directory contained in the path.
66 66 ///
67 67 /// If the directory is not yet in the map, adds its parents.
68 pub fn add_path(&mut self, path: &HgPath) {
68 pub fn add_path(&mut self, path: &HgPath) -> Result<(), DirstateMapError> {
69 69 for subpath in files::find_dirs(path) {
70 if subpath.as_bytes().last() == Some(&b'/') {
71 // TODO Remove this once PathAuditor is certified
72 // as the only entrypoint for path data
73 return Err(DirstateMapError::ConsecutiveSlashes);
74 }
70 75 if let Some(val) = self.inner.get_mut(subpath) {
71 76 *val += 1;
72 77 break;
73 78 }
74 79 self.inner.insert(subpath.to_owned(), 1);
75 80 }
81 Ok(())
76 82 }
77 83
78 84 /// Decreases the count of deepest directory contained in the path.
@@ -83,16 +83,16 b' impl DirstateMap {'
83 83 filename: &HgPath,
84 84 old_state: EntryState,
85 85 entry: DirstateEntry,
86 ) {
86 ) -> Result<(), DirstateMapError> {
87 87 if old_state == EntryState::Unknown || old_state == EntryState::Removed
88 88 {
89 89 if let Some(ref mut dirs) = self.dirs {
90 dirs.add_path(filename)
90 dirs.add_path(filename)?;
91 91 }
92 92 }
93 93 if old_state == EntryState::Unknown {
94 94 if let Some(ref mut all_dirs) = self.all_dirs {
95 all_dirs.add_path(filename)
95 all_dirs.add_path(filename)?;
96 96 }
97 97 }
98 98 self.state_map.insert(filename.to_owned(), entry.to_owned());
@@ -104,6 +104,7 b' impl DirstateMap {'
104 104 if entry.size == SIZE_FROM_OTHER_PARENT {
105 105 self.other_parent_set.insert(filename.to_owned());
106 106 }
107 Ok(())
107 108 }
108 109
109 110 /// Mark a file as removed in the dirstate.
@@ -101,6 +101,20 b' impl From<std::io::Error> for DirstatePa'
101 101 pub enum DirstateMapError {
102 102 PathNotFound(HgPathBuf),
103 103 EmptyPath,
104 ConsecutiveSlashes,
105 }
106
107 impl ToString for DirstateMapError {
108 fn to_string(&self) -> String {
109 use crate::DirstateMapError::*;
110 match self {
111 PathNotFound(_) => "expected a value, found none".to_string(),
112 EmptyPath => "Overflow in dirstate.".to_string(),
113 ConsecutiveSlashes => {
114 "found invalid consecutive slashes in path".to_string()
115 }
116 }
117 }
104 118 }
105 119
106 120 pub enum DirstateError {
@@ -68,8 +68,19 b' py_class!(pub class Dirs |py| {'
68 68 def addpath(&self, path: PyObject) -> PyResult<PyObject> {
69 69 self.inner_shared(py).borrow_mut()?.add_path(
70 70 HgPath::new(path.extract::<PyBytes>(py)?.data(py)),
71 );
72 Ok(py.None())
71 ).and(Ok(py.None())).or_else(|e| {
72 match e {
73 DirstateMapError::EmptyPath => {
74 Ok(py.None())
75 },
76 e => {
77 Err(PyErr::new::<exc::ValueError, _>(
78 py,
79 e.to_string(),
80 ))
81 }
82 }
83 })
73 84 }
74 85
75 86 def delpath(&self, path: PyObject) -> PyResult<PyObject> {
@@ -79,15 +90,15 b' py_class!(pub class Dirs |py| {'
79 90 .and(Ok(py.None()))
80 91 .or_else(|e| {
81 92 match e {
82 DirstateMapError::PathNotFound(_p) => {
93 DirstateMapError::EmptyPath => {
94 Ok(py.None())
95 },
96 e => {
83 97 Err(PyErr::new::<exc::ValueError, _>(
84 98 py,
85 "expected a value, found none".to_string(),
99 e.to_string(),
86 100 ))
87 101 }
88 DirstateMapError::EmptyPath => {
89 Ok(py.None())
90 }
91 102 }
92 103 })
93 104 }
@@ -25,8 +25,8 b' use crate::{'
25 25 use hg::{
26 26 utils::hg_path::{HgPath, HgPathBuf},
27 27 DirsMultiset, DirstateEntry, DirstateMap as RustDirstateMap,
28 DirstateParents, DirstateParseError, EntryState, StateMapIter,
29 PARENT_SIZE,
28 DirstateMapError, DirstateParents, DirstateParseError, EntryState,
29 StateMapIter, PARENT_SIZE,
30 30 };
31 31
32 32 // TODO
@@ -97,8 +97,9 b' py_class!(pub class DirstateMap |py| {'
97 97 size: size.extract(py)?,
98 98 mtime: mtime.extract(py)?,
99 99 },
100 );
101 Ok(py.None())
100 ).and(Ok(py.None())).or_else(|e: DirstateMapError| {
101 Err(PyErr::new::<exc::ValueError, _>(py, e.to_string()))
102 })
102 103 }
103 104
104 105 def removefile(
General Comments 0
You need to be logged in to leave comments. Login now