##// END OF EJS Templates
rust: Return owned instead of borrowed DirstateEntry in DirstateMap APIs...
Simon Sapin -
r48123:4ee9f419 default
parent child Browse files
Show More
@@ -77,7 +77,7 b' pub const SIZE_FROM_OTHER_PARENT: i32 = '
77 77
78 78 pub type StateMap = FastHashMap<HgPathBuf, DirstateEntry>;
79 79 pub type StateMapIter<'a> =
80 Box<dyn Iterator<Item = (&'a HgPath, &'a DirstateEntry)> + Send + 'a>;
80 Box<dyn Iterator<Item = (&'a HgPath, DirstateEntry)> + Send + 'a>;
81 81
82 82 pub type CopyMap = FastHashMap<HgPathBuf, HgPathBuf>;
83 83 pub type CopyMapIter<'a> =
@@ -30,12 +30,12 b' impl DirsMultiset {'
30 30 /// Initializes the multiset from a dirstate.
31 31 ///
32 32 /// If `skip_state` is provided, skips dirstate entries with equal state.
33 pub fn from_dirstate<'a, I, P>(
33 pub fn from_dirstate<I, P>(
34 34 dirstate: I,
35 35 skip_state: Option<EntryState>,
36 36 ) -> Result<Self, DirstateMapError>
37 37 where
38 I: IntoIterator<Item = (P, &'a DirstateEntry)>,
38 I: IntoIterator<Item = (P, DirstateEntry)>,
39 39 P: AsRef<HgPath>,
40 40 {
41 41 let mut multiset = DirsMultiset {
@@ -338,7 +338,7 b' mod tests {'
338 338 assert_eq!(expected, new);
339 339
340 340 let new =
341 DirsMultiset::from_dirstate(&StateMap::default(), None).unwrap();
341 DirsMultiset::from_dirstate(StateMap::default(), None).unwrap();
342 342 let expected = DirsMultiset {
343 343 inner: FastHashMap::default(),
344 344 };
@@ -381,7 +381,7 b' mod tests {'
381 381 .map(|(k, v)| (HgPathBuf::from_bytes(k.as_bytes()), *v))
382 382 .collect();
383 383
384 let new = DirsMultiset::from_dirstate(&input_map, None).unwrap();
384 let new = DirsMultiset::from_dirstate(input_map, None).unwrap();
385 385 let expected = DirsMultiset {
386 386 inner: expected_inner,
387 387 };
@@ -417,7 +417,7 b' mod tests {'
417 417 .collect();
418 418
419 419 let new =
420 DirsMultiset::from_dirstate(&input_map, Some(EntryState::Normal))
420 DirsMultiset::from_dirstate(input_map, Some(EntryState::Normal))
421 421 .unwrap();
422 422 let expected = DirsMultiset {
423 423 inner: expected_inner,
@@ -249,7 +249,7 b' impl DirstateMap {'
249 249 pub fn set_all_dirs(&mut self) -> Result<(), DirstateMapError> {
250 250 if self.all_dirs.is_none() {
251 251 self.all_dirs = Some(DirsMultiset::from_dirstate(
252 self.state_map.iter(),
252 self.state_map.iter().map(|(k, v)| (k, *v)),
253 253 None,
254 254 )?);
255 255 }
@@ -259,7 +259,7 b' impl DirstateMap {'
259 259 pub fn set_dirs(&mut self) -> Result<(), DirstateMapError> {
260 260 if self.dirs.is_none() {
261 261 self.dirs = Some(DirsMultiset::from_dirstate(
262 self.state_map.iter(),
262 self.state_map.iter().map(|(k, v)| (k, *v)),
263 263 Some(EntryState::Removed),
264 264 )?);
265 265 }
@@ -627,13 +627,13 b" impl<'on_disk> super::dispatch::Dirstate"
627 627 self.get(key).is_some()
628 628 }
629 629
630 fn get(&self, key: &HgPath) -> Option<&DirstateEntry> {
631 self.get_node(key)?.entry.as_ref()
630 fn get(&self, key: &HgPath) -> Option<DirstateEntry> {
631 self.get_node(key)?.entry
632 632 }
633 633
634 634 fn iter(&self) -> StateMapIter<'_> {
635 635 Box::new(self.iter_nodes().filter_map(|(path, node)| {
636 node.entry.as_ref().map(|entry| (&**path, entry))
636 node.entry.map(|entry| (&**path, entry))
637 637 }))
638 638 }
639 639 }
@@ -117,7 +117,7 b' pub trait DirstateMapMethods {'
117 117
118 118 fn contains_key(&self, key: &HgPath) -> bool;
119 119
120 fn get(&self, key: &HgPath) -> Option<&DirstateEntry>;
120 fn get(&self, key: &HgPath) -> Option<DirstateEntry>;
121 121
122 122 fn iter(&self) -> StateMapIter<'_>;
123 123 }
@@ -290,11 +290,11 b' impl DirstateMapMethods for DirstateMap '
290 290 (&**self).contains_key(key)
291 291 }
292 292
293 fn get(&self, key: &HgPath) -> Option<&DirstateEntry> {
294 (&**self).get(key)
293 fn get(&self, key: &HgPath) -> Option<DirstateEntry> {
294 (&**self).get(key).cloned()
295 295 }
296 296
297 297 fn iter(&self) -> StateMapIter<'_> {
298 Box::new((&**self).iter().map(|(key, value)| (&**key, value)))
298 Box::new((&**self).iter().map(|(key, value)| (&**key, *value)))
299 299 }
300 300 }
@@ -45,7 +45,8 b' py_class!(pub class Dirs |py| {'
45 45 }
46 46 let inner = if let Ok(map) = map.cast_as::<PyDict>(py) {
47 47 let dirstate = extract_dirstate(py, &map)?;
48 DirsMultiset::from_dirstate(&dirstate, skip_state)
48 let dirstate = dirstate.iter().map(|(k, v)| (k, *v));
49 DirsMultiset::from_dirstate(dirstate, skip_state)
49 50 .map_err(|e: DirstateMapError| {
50 51 PyErr::new::<exc::ValueError, _>(py, e.to_string())
51 52 })?
@@ -92,7 +92,7 b' py_class!(pub class DirstateMap |py| {'
92 92 let key = key.extract::<PyBytes>(py)?;
93 93 match self.inner(py).borrow().get(HgPath::new(key.data(py))) {
94 94 Some(entry) => {
95 Ok(Some(make_dirstate_tuple(py, entry)?))
95 Ok(Some(make_dirstate_tuple(py, &entry)?))
96 96 },
97 97 None => Ok(default)
98 98 }
@@ -348,7 +348,7 b' py_class!(pub class DirstateMap |py| {'
348 348 let key = HgPath::new(key.data(py));
349 349 match self.inner(py).borrow().get(key) {
350 350 Some(entry) => {
351 Ok(make_dirstate_tuple(py, entry)?)
351 Ok(make_dirstate_tuple(py, &entry)?)
352 352 },
353 353 None => Err(PyErr::new::<exc::KeyError, _>(
354 354 py,
@@ -525,13 +525,13 b' impl DirstateMap {'
525 525 }
526 526 fn translate_key(
527 527 py: Python,
528 res: (&HgPath, &DirstateEntry),
528 res: (&HgPath, DirstateEntry),
529 529 ) -> PyResult<Option<PyBytes>> {
530 530 Ok(Some(PyBytes::new(py, res.0.as_bytes())))
531 531 }
532 532 fn translate_key_value(
533 533 py: Python,
534 res: (&HgPath, &DirstateEntry),
534 res: (&HgPath, DirstateEntry),
535 535 ) -> PyResult<Option<(PyBytes, PyObject)>> {
536 536 let (f, entry) = res;
537 537 Ok(Some((
@@ -173,7 +173,7 b' impl DirstateMapMethods for OwningDirsta'
173 173 self.get().contains_key(key)
174 174 }
175 175
176 fn get(&self, key: &HgPath) -> Option<&DirstateEntry> {
176 fn get(&self, key: &HgPath) -> Option<DirstateEntry> {
177 177 self.get().get(key)
178 178 }
179 179
General Comments 0
You need to be logged in to leave comments. Login now