Mercurial > hg
comparison rust/hg-cpython/src/dirstate/dirstate_map.rs @ 44973:26114bd6ec60
rust: do a clippy pass
This is the result of running `cargo clippy` on hg-core/hg-cpython and fixing
the lints that do not require too much code churn (and would warrant a separate
commit/complete refactor) and only come from our code (a lot of warnings in
hg-cpython come from `rust-cpython`).
Most of those were good lints, two of them was the linter not being smart
enough (or compiler to get up to `clippy`'s level depending on how you see it).
Maybe in the future we could have `clippy` be part of the CI.
Differential Revision: https://phab.mercurial-scm.org/D8635
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Mon, 15 Jun 2020 18:26:40 +0200 |
parents | 8cdd0b9629e3 |
children | 496537c9c1b4 |
comparison
equal
deleted
inserted
replaced
44962:ef8dcee272ac | 44973:26114bd6ec60 |
---|---|
177 locals.set_item( | 177 locals.set_item( |
178 py, | 178 py, |
179 "other_parent", | 179 "other_parent", |
180 other_parent | 180 other_parent |
181 .iter() | 181 .iter() |
182 .map(|v| PyBytes::new(py, v.as_ref())) | 182 .map(|v| PyBytes::new(py, v.as_bytes())) |
183 .collect::<Vec<PyBytes>>() | 183 .collect::<Vec<PyBytes>>() |
184 .to_py_object(py), | 184 .to_py_object(py), |
185 )?; | 185 )?; |
186 | 186 |
187 py.eval("set(other_parent)", None, Some(&locals)) | 187 py.eval("set(other_parent)", None, Some(&locals)) |
346 def filefoldmapasdict(&self) -> PyResult<PyDict> { | 346 def filefoldmapasdict(&self) -> PyResult<PyDict> { |
347 let dict = PyDict::new(py); | 347 let dict = PyDict::new(py); |
348 for (key, value) in | 348 for (key, value) in |
349 self.inner(py).borrow_mut().build_file_fold_map().iter() | 349 self.inner(py).borrow_mut().build_file_fold_map().iter() |
350 { | 350 { |
351 dict.set_item(py, key.as_ref().to_vec(), value.as_ref().to_vec())?; | 351 dict.set_item( |
352 py, | |
353 key.as_bytes().to_vec(), | |
354 value.as_bytes().to_vec(), | |
355 )?; | |
352 } | 356 } |
353 Ok(dict) | 357 Ok(dict) |
354 } | 358 } |
355 | 359 |
356 def __len__(&self) -> PyResult<usize> { | 360 def __len__(&self) -> PyResult<usize> { |
438 def copymapcopy(&self) -> PyResult<PyDict> { | 442 def copymapcopy(&self) -> PyResult<PyDict> { |
439 let dict = PyDict::new(py); | 443 let dict = PyDict::new(py); |
440 for (key, value) in self.inner(py).borrow().copy_map.iter() { | 444 for (key, value) in self.inner(py).borrow().copy_map.iter() { |
441 dict.set_item( | 445 dict.set_item( |
442 py, | 446 py, |
443 PyBytes::new(py, key.as_ref()), | 447 PyBytes::new(py, key.as_bytes()), |
444 PyBytes::new(py, value.as_ref()), | 448 PyBytes::new(py, value.as_bytes()), |
445 )?; | 449 )?; |
446 } | 450 } |
447 Ok(dict) | 451 Ok(dict) |
448 } | 452 } |
449 | 453 |
450 def copymapgetitem(&self, key: PyObject) -> PyResult<PyBytes> { | 454 def copymapgetitem(&self, key: PyObject) -> PyResult<PyBytes> { |
451 let key = key.extract::<PyBytes>(py)?; | 455 let key = key.extract::<PyBytes>(py)?; |
452 match self.inner(py).borrow().copy_map.get(HgPath::new(key.data(py))) { | 456 match self.inner(py).borrow().copy_map.get(HgPath::new(key.data(py))) { |
453 Some(copy) => Ok(PyBytes::new(py, copy.as_ref())), | 457 Some(copy) => Ok(PyBytes::new(py, copy.as_bytes())), |
454 None => Err(PyErr::new::<exc::KeyError, _>( | 458 None => Err(PyErr::new::<exc::KeyError, _>( |
455 py, | 459 py, |
456 String::from_utf8_lossy(key.data(py)), | 460 String::from_utf8_lossy(key.data(py)), |
457 )), | 461 )), |
458 } | 462 } |
483 .borrow() | 487 .borrow() |
484 .copy_map | 488 .copy_map |
485 .get(HgPath::new(key.data(py))) | 489 .get(HgPath::new(key.data(py))) |
486 { | 490 { |
487 Some(copy) => Ok(Some( | 491 Some(copy) => Ok(Some( |
488 PyBytes::new(py, copy.as_ref()).into_object(), | 492 PyBytes::new(py, copy.as_bytes()).into_object(), |
489 )), | 493 )), |
490 None => Ok(default), | 494 None => Ok(default), |
491 } | 495 } |
492 } | 496 } |
493 def copymapsetitem( | 497 def copymapsetitem( |
547 } | 551 } |
548 fn translate_key( | 552 fn translate_key( |
549 py: Python, | 553 py: Python, |
550 res: (&HgPathBuf, &DirstateEntry), | 554 res: (&HgPathBuf, &DirstateEntry), |
551 ) -> PyResult<Option<PyBytes>> { | 555 ) -> PyResult<Option<PyBytes>> { |
552 Ok(Some(PyBytes::new(py, res.0.as_ref()))) | 556 Ok(Some(PyBytes::new(py, res.0.as_bytes()))) |
553 } | 557 } |
554 fn translate_key_value( | 558 fn translate_key_value( |
555 py: Python, | 559 py: Python, |
556 res: (&HgPathBuf, &DirstateEntry), | 560 res: (&HgPathBuf, &DirstateEntry), |
557 ) -> PyResult<Option<(PyBytes, PyObject)>> { | 561 ) -> PyResult<Option<(PyBytes, PyObject)>> { |
558 let (f, entry) = res; | 562 let (f, entry) = res; |
559 Ok(Some(( | 563 Ok(Some(( |
560 PyBytes::new(py, f.as_ref()), | 564 PyBytes::new(py, f.as_bytes()), |
561 make_dirstate_tuple(py, entry)?, | 565 make_dirstate_tuple(py, entry)?, |
562 ))) | 566 ))) |
563 } | 567 } |
564 } | 568 } |
565 | 569 |