Show More
@@ -65,14 +65,20 b' impl DirsMultiset {' | |||||
65 | /// Increases the count of deepest directory contained in the path. |
|
65 | /// Increases the count of deepest directory contained in the path. | |
66 | /// |
|
66 | /// | |
67 | /// If the directory is not yet in the map, adds its parents. |
|
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 | for subpath in files::find_dirs(path) { |
|
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 | if let Some(val) = self.inner.get_mut(subpath) { |
|
75 | if let Some(val) = self.inner.get_mut(subpath) { | |
71 | *val += 1; |
|
76 | *val += 1; | |
72 | break; |
|
77 | break; | |
73 | } |
|
78 | } | |
74 | self.inner.insert(subpath.to_owned(), 1); |
|
79 | self.inner.insert(subpath.to_owned(), 1); | |
75 | } |
|
80 | } | |
|
81 | Ok(()) | |||
76 | } |
|
82 | } | |
77 |
|
83 | |||
78 | /// Decreases the count of deepest directory contained in the path. |
|
84 | /// Decreases the count of deepest directory contained in the path. |
@@ -83,16 +83,16 b' impl DirstateMap {' | |||||
83 | filename: &HgPath, |
|
83 | filename: &HgPath, | |
84 | old_state: EntryState, |
|
84 | old_state: EntryState, | |
85 | entry: DirstateEntry, |
|
85 | entry: DirstateEntry, | |
86 | ) { |
|
86 | ) -> Result<(), DirstateMapError> { | |
87 | if old_state == EntryState::Unknown || old_state == EntryState::Removed |
|
87 | if old_state == EntryState::Unknown || old_state == EntryState::Removed | |
88 | { |
|
88 | { | |
89 | if let Some(ref mut dirs) = self.dirs { |
|
89 | if let Some(ref mut dirs) = self.dirs { | |
90 | dirs.add_path(filename) |
|
90 | dirs.add_path(filename)?; | |
91 | } |
|
91 | } | |
92 | } |
|
92 | } | |
93 | if old_state == EntryState::Unknown { |
|
93 | if old_state == EntryState::Unknown { | |
94 | if let Some(ref mut all_dirs) = self.all_dirs { |
|
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 | self.state_map.insert(filename.to_owned(), entry.to_owned()); |
|
98 | self.state_map.insert(filename.to_owned(), entry.to_owned()); | |
@@ -104,6 +104,7 b' impl DirstateMap {' | |||||
104 | if entry.size == SIZE_FROM_OTHER_PARENT { |
|
104 | if entry.size == SIZE_FROM_OTHER_PARENT { | |
105 | self.other_parent_set.insert(filename.to_owned()); |
|
105 | self.other_parent_set.insert(filename.to_owned()); | |
106 | } |
|
106 | } | |
|
107 | Ok(()) | |||
107 | } |
|
108 | } | |
108 |
|
109 | |||
109 | /// Mark a file as removed in the dirstate. |
|
110 | /// Mark a file as removed in the dirstate. |
@@ -101,6 +101,20 b' impl From<std::io::Error> for DirstatePa' | |||||
101 | pub enum DirstateMapError { |
|
101 | pub enum DirstateMapError { | |
102 | PathNotFound(HgPathBuf), |
|
102 | PathNotFound(HgPathBuf), | |
103 | EmptyPath, |
|
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 | pub enum DirstateError { |
|
120 | pub enum DirstateError { |
@@ -68,8 +68,19 b' py_class!(pub class Dirs |py| {' | |||||
68 | def addpath(&self, path: PyObject) -> PyResult<PyObject> { |
|
68 | def addpath(&self, path: PyObject) -> PyResult<PyObject> { | |
69 | self.inner_shared(py).borrow_mut()?.add_path( |
|
69 | self.inner_shared(py).borrow_mut()?.add_path( | |
70 | HgPath::new(path.extract::<PyBytes>(py)?.data(py)), |
|
70 | HgPath::new(path.extract::<PyBytes>(py)?.data(py)), | |
71 | ); |
|
71 | ).and(Ok(py.None())).or_else(|e| { | |
72 | Ok(py.None()) |
|
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 | def delpath(&self, path: PyObject) -> PyResult<PyObject> { |
|
86 | def delpath(&self, path: PyObject) -> PyResult<PyObject> { | |
@@ -79,15 +90,15 b' py_class!(pub class Dirs |py| {' | |||||
79 | .and(Ok(py.None())) |
|
90 | .and(Ok(py.None())) | |
80 | .or_else(|e| { |
|
91 | .or_else(|e| { | |
81 | match e { |
|
92 | match e { | |
82 |
DirstateMapError::Path |
|
93 | DirstateMapError::EmptyPath => { | |
|
94 | Ok(py.None()) | |||
|
95 | }, | |||
|
96 | e => { | |||
83 | Err(PyErr::new::<exc::ValueError, _>( |
|
97 | Err(PyErr::new::<exc::ValueError, _>( | |
84 | py, |
|
98 | py, | |
85 |
|
|
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 | use hg::{ |
|
25 | use hg::{ | |
26 | utils::hg_path::{HgPath, HgPathBuf}, |
|
26 | utils::hg_path::{HgPath, HgPathBuf}, | |
27 | DirsMultiset, DirstateEntry, DirstateMap as RustDirstateMap, |
|
27 | DirsMultiset, DirstateEntry, DirstateMap as RustDirstateMap, | |
28 |
DirstateParents, DirstateParseError, EntryState, |
|
28 | DirstateMapError, DirstateParents, DirstateParseError, EntryState, | |
29 | PARENT_SIZE, |
|
29 | StateMapIter, PARENT_SIZE, | |
30 | }; |
|
30 | }; | |
31 |
|
31 | |||
32 | // TODO |
|
32 | // TODO | |
@@ -97,8 +97,9 b' py_class!(pub class DirstateMap |py| {' | |||||
97 | size: size.extract(py)?, |
|
97 | size: size.extract(py)?, | |
98 | mtime: mtime.extract(py)?, |
|
98 | mtime: mtime.extract(py)?, | |
99 | }, |
|
99 | }, | |
100 | ); |
|
100 | ).and(Ok(py.None())).or_else(|e: DirstateMapError| { | |
101 | Ok(py.None()) |
|
101 | Err(PyErr::new::<exc::ValueError, _>(py, e.to_string())) | |
|
102 | }) | |||
102 | } |
|
103 | } | |
103 |
|
104 | |||
104 | def removefile( |
|
105 | def removefile( |
General Comments 0
You need to be logged in to leave comments.
Login now