##// END OF EJS Templates
rust: run a clippy pass with the latest stable version...
Raphaël Gomès -
r52013:532e74ad default
parent child Browse files
Show More
@@ -107,7 +107,7 b' impl ConfigLayer {'
107 107 ) {
108 108 self.sections
109 109 .entry(section)
110 .or_insert_with(HashMap::new)
110 .or_default()
111 111 .insert(item, ConfigValue { bytes: value, line });
112 112 }
113 113
@@ -178,7 +178,7 b' impl ConfigLayer {'
178 178 .expect("Path::parent fail on a file we’ve read");
179 179 // `Path::join` with an absolute argument correctly ignores the
180 180 // base path
181 let filename = dir.join(&get_path_from_bytes(&filename_bytes));
181 let filename = dir.join(get_path_from_bytes(&filename_bytes));
182 182 match std::fs::read(&filename) {
183 183 Ok(data) => {
184 184 layers.push(current_layer);
@@ -758,7 +758,7 b' mod tests {'
758 758 let tmpdir = tempfile::tempdir().unwrap();
759 759 let tmpdir_path = tmpdir.path();
760 760 let mut included_file =
761 File::create(&tmpdir_path.join("included.rc")).unwrap();
761 File::create(tmpdir_path.join("included.rc")).unwrap();
762 762
763 763 included_file.write_all(b"[section]\nitem=value1").unwrap();
764 764 let base_config_path = tmpdir_path.join("base.rc");
@@ -205,8 +205,7 b' mod tests {'
205 205 graph: &impl Graph,
206 206 revs: &[BaseRevision],
207 207 ) -> Result<Vec<Revision>, GraphError> {
208 let iter_revs: Vec<_> =
209 revs.into_iter().cloned().map(Revision).collect();
208 let iter_revs: Vec<_> = revs.iter().cloned().map(Revision).collect();
210 209 let heads = heads(graph, iter_revs.iter())?;
211 210 let mut as_vec: Vec<Revision> = heads.iter().cloned().collect();
212 211 as_vec.sort_unstable();
@@ -178,7 +178,7 b" impl<'on_disk> ChildNodes<'on_disk> {"
178 178 ChildNodes::InMemory(nodes) => Ok(nodes),
179 179 ChildNodes::OnDisk(nodes) => {
180 180 *unreachable_bytes +=
181 std::mem::size_of_val::<[on_disk::Node]>(nodes) as u32;
181 std::mem::size_of_val::<[on_disk::Node]>(*nodes) as u32;
182 182 let nodes = nodes
183 183 .iter()
184 184 .map(|node| {
@@ -764,7 +764,7 b" impl<'on_disk> DirstateMap<'on_disk> {"
764 764 ) -> Result<bool, DirstateV2ParseError> {
765 765 let was_tracked = old_entry_opt.map_or(false, |e| e.tracked());
766 766 let had_entry = old_entry_opt.is_some();
767 let tracked_count_increment = if was_tracked { 0 } else { 1 };
767 let tracked_count_increment = u32::from(!was_tracked);
768 768 let mut new = false;
769 769
770 770 let node = self.get_or_insert_node(filename, |ancestor| {
@@ -249,7 +249,7 b" impl<'a> HasIgnoredAncestor<'a> {"
249 249 }
250 250 }
251 251
252 fn force<'b>(&self, ignore_fn: &IgnoreFnType<'b>) -> bool {
252 fn force(&self, ignore_fn: &IgnoreFnType<'_>) -> bool {
253 253 match self.parent {
254 254 None => false,
255 255 Some(parent) => {
@@ -332,7 +332,7 b' impl<G: Graph + Clone> PartialDiscovery<'
332 332 FastHashMap::default();
333 333 for &rev in self.undecided.as_ref().unwrap() {
334 334 for p in ParentsIterator::graph_parents(&self.graph, rev)? {
335 children.entry(p).or_insert_with(Vec::new).push(rev);
335 children.entry(p).or_default().push(rev);
336 336 }
337 337 }
338 338 self.children_cache = Some(children);
@@ -695,7 +695,7 b' mod tests {'
695 695 #[test]
696 696 fn test_bidirectional_sample() -> Result<(), GraphError> {
697 697 let mut disco = full_disco();
698 disco.undecided = Some((0..=13).into_iter().map(Revision).collect());
698 disco.undecided = Some((0..=13).map(Revision).collect());
699 699
700 700 let (sample_set, size) = disco.bidirectional_sample(7)?;
701 701 assert_eq!(size, 7);
@@ -629,8 +629,7 b' impl SubInclude {'
629 629 normalize_path_bytes(&get_bytes_from_path(source));
630 630
631 631 let source_root = get_path_from_bytes(&normalized_source);
632 let source_root =
633 source_root.parent().unwrap_or_else(|| source_root.deref());
632 let source_root = source_root.parent().unwrap_or(source_root);
634 633
635 634 let path = source_root.join(get_path_from_bytes(pattern));
636 635 let new_root = path.parent().unwrap_or_else(|| path.deref());
@@ -682,22 +681,21 b' mod tests {'
682 681 assert_eq!(escape_pattern(untouched), untouched.to_vec());
683 682 // All escape codes
684 683 assert_eq!(
685 escape_pattern(br#"()[]{}?*+-|^$\\.&~#\t\n\r\v\f"#),
686 br#"\(\)\[\]\{\}\?\*\+\-\|\^\$\\\\\.\&\~\#\\t\\n\\r\\v\\f"#
687 .to_vec()
684 escape_pattern(br"()[]{}?*+-|^$\\.&~#\t\n\r\v\f"),
685 br"\(\)\[\]\{\}\?\*\+\-\|\^\$\\\\\.\&\~\#\\t\\n\\r\\v\\f".to_vec()
688 686 );
689 687 }
690 688
691 689 #[test]
692 690 fn glob_test() {
693 assert_eq!(glob_to_re(br#"?"#), br#"."#);
694 assert_eq!(glob_to_re(br#"*"#), br#"[^/]*"#);
695 assert_eq!(glob_to_re(br#"**"#), br#".*"#);
696 assert_eq!(glob_to_re(br#"**/a"#), br#"(?:.*/)?a"#);
697 assert_eq!(glob_to_re(br#"a/**/b"#), br#"a/(?:.*/)?b"#);
698 assert_eq!(glob_to_re(br#"[a*?!^][^b][!c]"#), br#"[a*?!^][\^b][^c]"#);
699 assert_eq!(glob_to_re(br#"{a,b}"#), br#"(?:a|b)"#);
700 assert_eq!(glob_to_re(br#".\*\?"#), br#"\.\*\?"#);
691 assert_eq!(glob_to_re(br"?"), br".");
692 assert_eq!(glob_to_re(br"*"), br"[^/]*");
693 assert_eq!(glob_to_re(br"**"), br".*");
694 assert_eq!(glob_to_re(br"**/a"), br"(?:.*/)?a");
695 assert_eq!(glob_to_re(br"a/**/b"), br"a/(?:.*/)?b");
696 assert_eq!(glob_to_re(br"[a*?!^][^b][!c]"), br"[a*?!^][\^b][^c]");
697 assert_eq!(glob_to_re(br"{a,b}"), br"(?:a|b)");
698 assert_eq!(glob_to_re(br".\*\?"), br"\.\*\?");
701 699 }
702 700
703 701 #[test]
@@ -28,7 +28,6 b' use crate::dirstate::status::IgnoreFnTyp'
28 28 use crate::filepatterns::normalize_path_bytes;
29 29 use std::collections::HashSet;
30 30 use std::fmt::{Display, Error, Formatter};
31 use std::ops::Deref;
32 31 use std::path::{Path, PathBuf};
33 32 use std::{borrow::ToOwned, collections::BTreeSet};
34 33
@@ -183,7 +182,7 b' impl FileMatcher {'
183 182 pub fn new(files: Vec<HgPathBuf>) -> Result<Self, HgPathError> {
184 183 let dirs = DirsMultiset::from_manifest(&files)?;
185 184 Ok(Self {
186 files: HashSet::from_iter(files.into_iter()),
185 files: HashSet::from_iter(files),
187 186 dirs,
188 187 sorted_visitchildrenset_candidates: OnceCell::new(),
189 188 })
@@ -316,7 +315,7 b" impl<'a> PatternMatcher<'a> {"
316 315 pub fn new(ignore_patterns: Vec<IgnorePattern>) -> PatternResult<Self> {
317 316 let (files, _) = roots_and_dirs(&ignore_patterns);
318 317 let dirs = DirsMultiset::from_manifest(&files)?;
319 let files: HashSet<HgPathBuf> = HashSet::from_iter(files.into_iter());
318 let files: HashSet<HgPathBuf> = HashSet::from_iter(files);
320 319
321 320 let prefix = ignore_patterns.iter().all(|k| {
322 321 matches!(k.syntax, PatternSyntax::Path | PatternSyntax::RelPath)
@@ -773,10 +772,10 b' fn re_matcher(pattern: &[u8]) -> Pattern'
773 772
774 773 /// Returns the regex pattern and a function that matches an `HgPath` against
775 774 /// said regex formed by the given ignore patterns.
776 fn build_regex_match<'a, 'b>(
777 ignore_patterns: &'a [IgnorePattern],
775 fn build_regex_match<'a>(
776 ignore_patterns: &[IgnorePattern],
778 777 glob_suffix: &[u8],
779 ) -> PatternResult<(Vec<u8>, IgnoreFnType<'b>)> {
778 ) -> PatternResult<(Vec<u8>, IgnoreFnType<'a>)> {
780 779 let mut regexps = vec![];
781 780 let mut exact_set = HashSet::new();
782 781
@@ -958,7 +957,7 b" fn build_match<'a>("
958 957 } else {
959 958 b"."
960 959 };
961 dirs.contains(dir.deref())
960 dirs.contains(dir)
962 961 };
963 962 match_funcs.push(Box::new(match_func));
964 963
@@ -686,7 +686,7 b' impl Repo {'
686 686 }
687 687 file.write_all(&data)?;
688 688 file.flush()?;
689 file.seek(SeekFrom::Current(0))
689 file.stream_position()
690 690 })()
691 691 .when_writing_file(&data_filename)?;
692 692
@@ -248,8 +248,8 b' impl Revlog {'
248 248 ) -> Result<Self, HgError> {
249 249 let index_path = index_path.as_ref();
250 250 let index = {
251 match store_vfs.mmap_open_opt(&index_path)? {
252 None => Index::new(Box::new(vec![])),
251 match store_vfs.mmap_open_opt(index_path)? {
252 None => Index::new(Box::<Vec<_>>::default()),
253 253 Some(index_mmap) => {
254 254 let index = Index::new(Box::new(index_mmap))?;
255 255 Ok(index)
@@ -348,7 +348,7 b' mod tests {'
348 348 assert_eq!(Node::from_hex(SAMPLE_NODE_HEX).unwrap(), SAMPLE_NODE);
349 349 assert!(Node::from_hex(not_hex).is_err());
350 350 assert!(Node::from_hex(too_short).is_err());
351 assert!(Node::from_hex(&too_long).is_err());
351 assert!(Node::from_hex(too_long).is_err());
352 352 }
353 353
354 354 #[test]
@@ -656,7 +656,7 b' impl From<Vec<Block>> for NodeTree {'
656 656
657 657 impl fmt::Debug for NodeTree {
658 658 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
659 let readonly: &[Block] = &*self.readonly;
659 let readonly: &[Block] = &self.readonly;
660 660 write!(
661 661 f,
662 662 "readonly: {:?}, growable: {:?}, root: {:?}",
@@ -668,7 +668,7 b' impl fmt::Debug for NodeTree {'
668 668 impl Default for NodeTree {
669 669 /// Create a fully mutable empty NodeTree
670 670 fn default() -> Self {
671 NodeTree::new(Box::new(Vec::new()))
671 NodeTree::new(Box::<Vec<_>>::default())
672 672 }
673 673 }
674 674
@@ -775,7 +775,7 b' pub mod tests {'
775 775 /// strings for test data, and brings actual hash size independency.
776 776 #[cfg(test)]
777 777 fn pad_node(hex: &str) -> Node {
778 Node::from_hex(&hex_pad_right(hex)).unwrap()
778 Node::from_hex(hex_pad_right(hex)).unwrap()
779 779 }
780 780
781 781 /// Pad hexadecimal Node prefix with zeros on the right, then insert
@@ -824,7 +824,7 b' pub mod tests {'
824 824 nt.find_node(&idx, idx.get(&1.into()).unwrap())?,
825 825 Some(R!(1))
826 826 );
827 let unknown = Node::from_hex(&hex_pad_right("3d")).unwrap();
827 let unknown = Node::from_hex(hex_pad_right("3d")).unwrap();
828 828 assert_eq!(nt.find_node(&idx, &unknown)?, None);
829 829 Ok(())
830 830 }
@@ -900,7 +900,7 b' pub mod tests {'
900 900 hex: &str,
901 901 ) -> Result<(), NodeMapError> {
902 902 let node = pad_node(hex);
903 return self.insert_node(rev, node);
903 self.insert_node(rev, node)
904 904 }
905 905
906 906 fn find_hex(
@@ -931,6 +931,12 b' pub mod tests {'
931 931 }
932 932 }
933 933
934 impl Default for TestNtIndex {
935 fn default() -> Self {
936 Self::new()
937 }
938 }
939
934 940 #[test]
935 941 fn test_insert_full_mutable() -> Result<(), NodeMapError> {
936 942 let mut idx = TestNtIndex::new();
@@ -1003,7 +1009,7 b' pub mod tests {'
1003 1009 let mut node1_hex = hex_pad_right("444444");
1004 1010 node1_hex.pop();
1005 1011 node1_hex.push('5');
1006 let node0 = Node::from_hex(&node0_hex).unwrap();
1012 let node0 = Node::from_hex(node0_hex).unwrap();
1007 1013 let node1 = Node::from_hex(&node1_hex).unwrap();
1008 1014
1009 1015 idx.insert(0.into(), node0);
@@ -75,7 +75,7 b' impl NodeMapDocket {'
75 75 // TODO: use `vfs.read()` here when the `persistent-nodemap.mmap`
76 76 // config is false?
77 77 if let Some(mmap) =
78 store_vfs.mmap_open(&data_path).io_not_found_as_none()?
78 store_vfs.mmap_open(data_path).io_not_found_as_none()?
79 79 {
80 80 if mmap.len() >= data_length {
81 81 Ok(Some((docket, mmap)))
@@ -192,13 +192,13 b' pub fn canonical_path('
192 192 let name = name.as_ref();
193 193
194 194 let name = if !name.is_absolute() {
195 root.join(&cwd).join(&name)
195 root.join(cwd).join(name)
196 196 } else {
197 197 name.to_owned()
198 198 };
199 let auditor = PathAuditor::new(&root);
200 if name != root && name.starts_with(&root) {
201 let name = name.strip_prefix(&root).unwrap();
199 let auditor = PathAuditor::new(root);
200 if name != root && name.starts_with(root) {
201 let name = name.strip_prefix(root).unwrap();
202 202 auditor.audit_path(path_to_hg_path_buf(name)?)?;
203 203 Ok(name.to_owned())
204 204 } else if name == root {
@@ -210,7 +210,7 b' pub fn canonical_path('
210 210 let mut name = name.deref();
211 211 let original_name = name.to_owned();
212 212 loop {
213 let same = is_same_file(&name, &root).unwrap_or(false);
213 let same = is_same_file(name, root).unwrap_or(false);
214 214 if same {
215 215 if name == original_name {
216 216 // `name` was actually the same as root (maybe a symlink)
@@ -218,8 +218,8 b' pub fn canonical_path('
218 218 }
219 219 // `name` is a symlink to root, so `original_name` is under
220 220 // root
221 let rel_path = original_name.strip_prefix(&name).unwrap();
222 auditor.audit_path(path_to_hg_path_buf(&rel_path)?)?;
221 let rel_path = original_name.strip_prefix(name).unwrap();
222 auditor.audit_path(path_to_hg_path_buf(rel_path)?)?;
223 223 return Ok(rel_path.to_owned());
224 224 }
225 225 name = match name.parent() {
@@ -429,7 +429,7 b' mod tests {'
429 429 })
430 430 );
431 431 assert_eq!(
432 canonical_path(&root, Path::new(""), &under_repo_symlink),
432 canonical_path(&root, Path::new(""), under_repo_symlink),
433 433 Ok(PathBuf::from("d"))
434 434 );
435 435 }
@@ -117,7 +117,7 b' impl PathAuditor {'
117 117 if self.audited_dirs.read().unwrap().contains(prefix) {
118 118 continue;
119 119 }
120 self.check_filesystem(&prefix, &path)?;
120 self.check_filesystem(prefix, path)?;
121 121 self.audited_dirs.write().unwrap().insert(prefix.to_owned());
122 122 }
123 123
@@ -203,12 +203,12 b' mod tests {'
203 203 })
204 204 );
205 205
206 create_dir(&base_dir_path.join("realdir")).unwrap();
207 File::create(&base_dir_path.join("realdir/realfile")).unwrap();
206 create_dir(base_dir_path.join("realdir")).unwrap();
207 File::create(base_dir_path.join("realdir/realfile")).unwrap();
208 208 // TODO make portable
209 209 std::os::unix::fs::symlink(
210 &base_dir_path.join("realdir"),
211 &base_dir_path.join("symlink"),
210 base_dir_path.join("realdir"),
211 base_dir_path.join("symlink"),
212 212 )
213 213 .unwrap();
214 214 let path = HgPath::new(b"symlink/realfile");
@@ -273,7 +273,7 b' fn build_response('
273 273 py_warnings.append(
274 274 py,
275 275 (
276 PyBytes::new(py, &get_bytes_from_path(&file)),
276 PyBytes::new(py, &get_bytes_from_path(file)),
277 277 PyBytes::new(py, syn),
278 278 )
279 279 .to_py_object(py)
@@ -282,7 +282,7 b' fn build_response('
282 282 }
283 283 PatternFileWarning::NoSuchFile(file) => py_warnings.append(
284 284 py,
285 PyBytes::new(py, &get_bytes_from_path(&file)).into_object(),
285 PyBytes::new(py, &get_bytes_from_path(file)).into_object(),
286 286 ),
287 287 }
288 288 }
@@ -348,7 +348,7 b' impl MixedIndex {'
348 348 py: Python<'a>,
349 349 ) -> PyResult<&'a RefCell<Option<NodeTree>>> {
350 350 if self.nt(py).borrow().is_none() {
351 let readonly = Box::new(Vec::new());
351 let readonly = Box::<Vec<_>>::default();
352 352 let mut nt = NodeTree::load_bytes(readonly, 0);
353 353 self.fill_nodemap(py, &mut nt)?;
354 354 self.nt(py).borrow_mut().replace(nt);
@@ -382,7 +382,7 b' impl MixedIndex {'
382 382 // If there's anything readonly, we need to build the data again from
383 383 // scratch
384 384 let bytes = if readonly.len() > 0 {
385 let mut nt = NodeTree::load_bytes(Box::new(vec![]), 0);
385 let mut nt = NodeTree::load_bytes(Box::<Vec<_>>::default(), 0);
386 386 self.fill_nodemap(py, &mut nt)?;
387 387
388 388 let (readonly, bytes) = nt.into_readonly_and_added_bytes();
@@ -62,7 +62,7 b' pub fn run(invocation: &crate::CliInvoca'
62 62 return Err(CommandError::unsupported(message));
63 63 }
64 64
65 let normalized = cwd.join(&file);
65 let normalized = cwd.join(file);
66 66 // TODO: actually normalize `..` path segments etc?
67 67 let dotted = normalized.components().any(|c| c.as_os_str() == "..");
68 68 if file.as_bytes() == b"." || dotted {
@@ -23,7 +23,7 b' pub fn args() -> clap::Command {'
23 23 )
24 24 .group(
25 25 ArgGroup::new("revlog")
26 .args(&["changelog", "manifest"])
26 .args(["changelog", "manifest"])
27 27 .required(true),
28 28 )
29 29 .arg(
@@ -20,7 +20,7 b' pub fn run(invocation: &crate::CliInvoca'
20 20 .with_context(|| {
21 21 IoErrorContext::CanonicalizingPath(working_directory.to_owned())
22 22 })?;
23 let bytes = get_bytes_from_path(&working_directory);
23 let bytes = get_bytes_from_path(working_directory);
24 24 invocation
25 25 .ui
26 26 .write_stdout(&format_bytes!(b"{}\n", bytes.as_slice()))?;
@@ -404,8 +404,8 b' fn exit_code('
404 404 }
405 405 }
406 406
407 fn exit<'a>(
408 original_args: &'a [OsString],
407 fn exit(
408 original_args: &[OsString],
409 409 initial_current_dir: &Option<PathBuf>,
410 410 ui: &Ui,
411 411 mut on_unsupported: OnUnsupported,
@@ -251,7 +251,7 b' pub(crate) fn format_pattern_file_warnin'
251 251 PatternFileWarning::InvalidSyntax(path, syntax) => format_bytes!(
252 252 b"{}: ignoring invalid syntax '{}'\n",
253 253 get_bytes_from_path(path),
254 &*syntax
254 syntax
255 255 ),
256 256 PatternFileWarning::NoSuchFile(path) => {
257 257 let path = if let Ok(relative) =
@@ -259,7 +259,7 b' pub(crate) fn format_pattern_file_warnin'
259 259 {
260 260 relative
261 261 } else {
262 &*path
262 path
263 263 };
264 264 format_bytes!(
265 265 b"skipping unreadable pattern file '{}': \
General Comments 0
You need to be logged in to leave comments. Login now