Mercurial > public > mercurial-scm > hg
comparison rust/hg-core/src/dirstate_tree/status.rs @ 49930:e98fd81bb151
rust-clippy: fix most warnings in `hg-core`
All of these are simple changes that for the most part are clear improvements
and the rest are at most equivalent.
The remaining warnings have to be fixed either with a bigger refactor like for
the nested "revlog" module, or in the dependency `bytes-cast`, which we own.
This will be done sometime in the future.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Mon, 09 Jan 2023 19:18:43 +0100 |
parents | c15b415d1bff |
children | bae51b50a5cf |
comparison
equal
deleted
inserted
replaced
49929:5f1cd6839c69 | 49930:e98fd81bb151 |
---|---|
152 &has_ignored_ancestor, | 152 &has_ignored_ancestor, |
153 dmap.root.as_ref(), | 153 dmap.root.as_ref(), |
154 hg_path, | 154 hg_path, |
155 &DirEntry { | 155 &DirEntry { |
156 hg_path: Cow::Borrowed(HgPath::new(b"")), | 156 hg_path: Cow::Borrowed(HgPath::new(b"")), |
157 fs_path: Cow::Borrowed(&root_dir), | 157 fs_path: Cow::Borrowed(root_dir), |
158 symlink_metadata: None, | 158 symlink_metadata: None, |
159 file_type: FakeFileType::Directory, | 159 file_type: FakeFileType::Directory, |
160 }, | 160 }, |
161 root_cached_mtime, | 161 root_cached_mtime, |
162 is_at_repo_root, | 162 is_at_repo_root, |
243 fn force<'b>(&self, ignore_fn: &IgnoreFnType<'b>) -> bool { | 243 fn force<'b>(&self, ignore_fn: &IgnoreFnType<'b>) -> bool { |
244 match self.parent { | 244 match self.parent { |
245 None => false, | 245 None => false, |
246 Some(parent) => { | 246 Some(parent) => { |
247 *(parent.cache.get_or_init(|| { | 247 *(parent.cache.get_or_init(|| { |
248 parent.force(ignore_fn) || ignore_fn(&self.path) | 248 parent.force(ignore_fn) || ignore_fn(self.path) |
249 })) | 249 })) |
250 } | 250 } |
251 } | 251 } |
252 } | 252 } |
253 } | 253 } |
400 Err(_) => return Ok(()), | 400 Err(_) => return Ok(()), |
401 }; | 401 }; |
402 let entry = DirEntry { | 402 let entry = DirEntry { |
403 hg_path: Cow::Borrowed( | 403 hg_path: Cow::Borrowed( |
404 dirstate_node | 404 dirstate_node |
405 .full_path(&self.dmap.on_disk)?, | 405 .full_path(self.dmap.on_disk)?, |
406 ), | 406 ), |
407 fs_path: Cow::Borrowed(&fs_path), | 407 fs_path: Cow::Borrowed(&fs_path), |
408 symlink_metadata: Some(fs_metadata), | 408 symlink_metadata: Some(fs_metadata), |
409 file_type, | 409 file_type, |
410 }; | 410 }; |
418 self.traverse_dirstate_only(dirstate_node) | 418 self.traverse_dirstate_only(dirstate_node) |
419 } | 419 } |
420 Err(error) => { | 420 Err(error) => { |
421 let hg_path = | 421 let hg_path = |
422 dirstate_node.full_path(self.dmap.on_disk)?; | 422 dirstate_node.full_path(self.dmap.on_disk)?; |
423 Ok(self.io_error(error, hg_path)) | 423 self.io_error(error, hg_path); |
424 Ok(()) | |
424 } | 425 } |
425 } | 426 } |
426 }) | 427 }) |
427 .collect::<Result<_, _>>()?; | 428 .collect::<Result<_, _>>()?; |
428 | 429 |
470 }, | 471 }, |
471 ) | 472 ) |
472 .par_bridge() | 473 .par_bridge() |
473 .map(|pair| { | 474 .map(|pair| { |
474 use itertools::EitherOrBoth::*; | 475 use itertools::EitherOrBoth::*; |
475 let has_dirstate_node_or_is_ignored; | 476 let has_dirstate_node_or_is_ignored = match pair { |
476 match pair { | |
477 Both(dirstate_node, fs_entry) => { | 477 Both(dirstate_node, fs_entry) => { |
478 self.traverse_fs_and_dirstate( | 478 self.traverse_fs_and_dirstate( |
479 &fs_entry, | 479 fs_entry, |
480 dirstate_node, | 480 dirstate_node, |
481 has_ignored_ancestor, | 481 has_ignored_ancestor, |
482 )?; | 482 )?; |
483 has_dirstate_node_or_is_ignored = true | 483 true |
484 } | 484 } |
485 Left(dirstate_node) => { | 485 Left(dirstate_node) => { |
486 self.traverse_dirstate_only(dirstate_node)?; | 486 self.traverse_dirstate_only(dirstate_node)?; |
487 has_dirstate_node_or_is_ignored = true; | 487 true |
488 } | 488 } |
489 Right(fs_entry) => { | 489 Right(fs_entry) => self.traverse_fs_only( |
490 has_dirstate_node_or_is_ignored = self.traverse_fs_only( | 490 has_ignored_ancestor.force(&self.ignore_fn), |
491 has_ignored_ancestor.force(&self.ignore_fn), | 491 directory_hg_path, |
492 directory_hg_path, | 492 fs_entry, |
493 fs_entry, | 493 ), |
494 ) | 494 }; |
495 } | |
496 } | |
497 Ok(has_dirstate_node_or_is_ignored) | 495 Ok(has_dirstate_node_or_is_ignored) |
498 }) | 496 }) |
499 .try_reduce(|| true, |a, b| Ok(a && b)) | 497 .try_reduce(|| true, |a, b| Ok(a && b)) |
500 } | 498 } |
501 | 499 |
522 .unwrap() | 520 .unwrap() |
523 .traversed | 521 .traversed |
524 .push(hg_path.detach_from_tree()) | 522 .push(hg_path.detach_from_tree()) |
525 } | 523 } |
526 let is_ignored = HasIgnoredAncestor::create( | 524 let is_ignored = HasIgnoredAncestor::create( |
527 Some(&has_ignored_ancestor), | 525 Some(has_ignored_ancestor), |
528 hg_path, | 526 hg_path, |
529 ); | 527 ); |
530 let is_at_repo_root = false; | 528 let is_at_repo_root = false; |
531 let children_all_have_dirstate_node_or_are_ignored = self | 529 let children_all_have_dirstate_node_or_are_ignored = self |
532 .traverse_fs_directory_and_dirstate( | 530 .traverse_fs_directory_and_dirstate( |
542 fs_entry, | 540 fs_entry, |
543 dirstate_node, | 541 dirstate_node, |
544 outdated_dircache, | 542 outdated_dircache, |
545 )? | 543 )? |
546 } else { | 544 } else { |
547 if file_or_symlink && self.matcher.matches(&hg_path) { | 545 if file_or_symlink && self.matcher.matches(hg_path) { |
548 if let Some(entry) = dirstate_node.entry()? { | 546 if let Some(entry) = dirstate_node.entry()? { |
549 if !entry.any_tracked() { | 547 if !entry.any_tracked() { |
550 // Forward-compat if we start tracking unknown/ignored | 548 // Forward-compat if we start tracking unknown/ignored |
551 // files for caching reasons | 549 // files for caching reasons |
552 self.mark_unknown_or_ignored( | 550 self.mark_unknown_or_ignored( |
553 has_ignored_ancestor.force(&self.ignore_fn), | 551 has_ignored_ancestor.force(&self.ignore_fn), |
554 &hg_path, | 552 hg_path, |
555 ); | 553 ); |
556 } | 554 } |
557 if entry.added() { | 555 if entry.added() { |
558 self.push_outcome(Outcome::Added, &dirstate_node)?; | 556 self.push_outcome(Outcome::Added, &dirstate_node)?; |
559 } else if entry.removed() { | 557 } else if entry.removed() { |
618 // https://stackoverflow.com/a/14393315/1162888), etc. | 616 // https://stackoverflow.com/a/14393315/1162888), etc. |
619 let metadata = match directory_entry.symlink_metadata() { | 617 let metadata = match directory_entry.symlink_metadata() { |
620 Ok(meta) => meta, | 618 Ok(meta) => meta, |
621 Err(_) => return Ok(()), | 619 Err(_) => return Ok(()), |
622 }; | 620 }; |
623 let directory_mtime = if let Ok(option) = | 621 |
624 TruncatedTimestamp::for_reliable_mtime_of(&metadata, status_start) | 622 let directory_mtime = match TruncatedTimestamp::for_reliable_mtime_of( |
625 { | 623 &metadata, |
626 if let Some(directory_mtime) = option { | 624 status_start, |
627 directory_mtime | 625 ) { |
628 } else { | 626 Ok(Some(directory_mtime)) => directory_mtime, |
627 Ok(None) => { | |
629 // The directory was modified too recently, | 628 // The directory was modified too recently, |
630 // don’t cache its `read_dir` results. | 629 // don’t cache its `read_dir` results. |
631 // | 630 // |
632 // 1. A change to this directory (direct child was | 631 // 1. A change to this directory (direct child was |
633 // added or removed) cause its mtime to be set | 632 // added or removed) cause its mtime to be set |
641 // On a system where the time resolution poor, this | 640 // On a system where the time resolution poor, this |
642 // scenario is not unlikely if all three steps are caused | 641 // scenario is not unlikely if all three steps are caused |
643 // by the same script. | 642 // by the same script. |
644 return Ok(()); | 643 return Ok(()); |
645 } | 644 } |
646 } else { | 645 Err(_) => { |
647 // OS/libc does not support mtime? | 646 // OS/libc does not support mtime? |
648 return Ok(()); | 647 return Ok(()); |
648 } | |
649 }; | 649 }; |
650 // We’ve observed (through `status_start`) that time has | 650 // We’ve observed (through `status_start`) that time has |
651 // “progressed” since `directory_mtime`, so any further | 651 // “progressed” since `directory_mtime`, so any further |
652 // change to this directory is extremely likely to cause a | 652 // change to this directory is extremely likely to cause a |
653 // different mtime. | 653 // different mtime. |
711 || entry.is_from_other_parent() | 711 || entry.is_from_other_parent() |
712 || (size >= 0 && (size_changed || mode_changed())) | 712 || (size >= 0 && (size_changed || mode_changed())) |
713 { | 713 { |
714 self.push_outcome(Outcome::Modified, dirstate_node)? | 714 self.push_outcome(Outcome::Modified, dirstate_node)? |
715 } else { | 715 } else { |
716 let mtime_looks_clean; | 716 let mtime_looks_clean = if let Some(dirstate_mtime) = |
717 if let Some(dirstate_mtime) = entry.truncated_mtime() { | 717 entry.truncated_mtime() |
718 { | |
718 let fs_mtime = TruncatedTimestamp::for_mtime_of(&fs_metadata) | 719 let fs_mtime = TruncatedTimestamp::for_mtime_of(&fs_metadata) |
719 .expect("OS/libc does not support mtime?"); | 720 .expect("OS/libc does not support mtime?"); |
720 // There might be a change in the future if for example the | 721 // There might be a change in the future if for example the |
721 // internal clock become off while process run, but this is a | 722 // internal clock become off while process run, but this is a |
722 // case where the issues the user would face | 723 // case where the issues the user would face |
723 // would be a lot worse and there is nothing we | 724 // would be a lot worse and there is nothing we |
724 // can really do. | 725 // can really do. |
725 mtime_looks_clean = fs_mtime.likely_equal(dirstate_mtime) | 726 fs_mtime.likely_equal(dirstate_mtime) |
726 } else { | 727 } else { |
727 // No mtime in the dirstate entry | 728 // No mtime in the dirstate entry |
728 mtime_looks_clean = false | 729 false |
729 }; | 730 }; |
730 if !mtime_looks_clean { | 731 if !mtime_looks_clean { |
731 self.push_outcome(Outcome::Unsure, dirstate_node)? | 732 self.push_outcome(Outcome::Unsure, dirstate_node)? |
732 } else if self.options.list_clean { | 733 } else if self.options.list_clean { |
733 self.push_outcome(Outcome::Clean, dirstate_node)? | 734 self.push_outcome(Outcome::Clean, dirstate_node)? |
767 let path = dirstate_node.full_path(self.dmap.on_disk)?; | 768 let path = dirstate_node.full_path(self.dmap.on_disk)?; |
768 if self.matcher.matches(path) { | 769 if self.matcher.matches(path) { |
769 if entry.removed() { | 770 if entry.removed() { |
770 self.push_outcome(Outcome::Removed, dirstate_node)? | 771 self.push_outcome(Outcome::Removed, dirstate_node)? |
771 } else { | 772 } else { |
772 self.push_outcome(Outcome::Deleted, &dirstate_node)? | 773 self.push_outcome(Outcome::Deleted, dirstate_node)? |
773 } | 774 } |
774 } | 775 } |
775 } | 776 } |
776 Ok(()) | 777 Ok(()) |
777 } | 778 } |
814 if self.options.collect_traversed_dirs { | 815 if self.options.collect_traversed_dirs { |
815 self.outcome.lock().unwrap().traversed.push(hg_path.into()) | 816 self.outcome.lock().unwrap().traversed.push(hg_path.into()) |
816 } | 817 } |
817 } | 818 } |
818 is_ignored | 819 is_ignored |
820 } else if file_or_symlink { | |
821 if self.matcher.matches(&hg_path) { | |
822 self.mark_unknown_or_ignored( | |
823 has_ignored_ancestor, | |
824 &BorrowedPath::InMemory(&hg_path), | |
825 ) | |
826 } else { | |
827 // We haven’t computed whether this path is ignored. It | |
828 // might not be, and a future run of status might have a | |
829 // different matcher that matches it. So treat it as not | |
830 // ignored. That is, inhibit readdir caching of the parent | |
831 // directory. | |
832 false | |
833 } | |
819 } else { | 834 } else { |
820 if file_or_symlink { | 835 // This is neither a directory, a plain file, or a symlink. |
821 if self.matcher.matches(&hg_path) { | 836 // Treat it like an ignored file. |
822 self.mark_unknown_or_ignored( | 837 true |
823 has_ignored_ancestor, | |
824 &BorrowedPath::InMemory(&hg_path), | |
825 ) | |
826 } else { | |
827 // We haven’t computed whether this path is ignored. It | |
828 // might not be, and a future run of status might have a | |
829 // different matcher that matches it. So treat it as not | |
830 // ignored. That is, inhibit readdir caching of the parent | |
831 // directory. | |
832 false | |
833 } | |
834 } else { | |
835 // This is neither a directory, a plain file, or a symlink. | |
836 // Treat it like an ignored file. | |
837 true | |
838 } | |
839 } | 838 } |
840 } | 839 } |
841 | 840 |
842 /// Returns whether that path is ignored | 841 /// Returns whether that path is ignored |
843 fn mark_unknown_or_ignored( | 842 fn mark_unknown_or_ignored( |
844 &self, | 843 &self, |
845 has_ignored_ancestor: bool, | 844 has_ignored_ancestor: bool, |
846 hg_path: &BorrowedPath<'_, 'on_disk>, | 845 hg_path: &BorrowedPath<'_, 'on_disk>, |
847 ) -> bool { | 846 ) -> bool { |
848 let is_ignored = has_ignored_ancestor || (self.ignore_fn)(&hg_path); | 847 let is_ignored = has_ignored_ancestor || (self.ignore_fn)(hg_path); |
849 if is_ignored { | 848 if is_ignored { |
850 if self.options.list_ignored { | 849 if self.options.list_ignored { |
851 self.push_outcome_without_copy_source( | 850 self.push_outcome_without_copy_source( |
852 Outcome::Ignored, | 851 Outcome::Ignored, |
853 hg_path, | 852 hg_path, |
854 ) | 853 ) |
855 } | 854 } |
856 } else { | 855 } else if self.options.list_unknown { |
857 if self.options.list_unknown { | 856 self.push_outcome_without_copy_source(Outcome::Unknown, hg_path) |
858 self.push_outcome_without_copy_source( | |
859 Outcome::Unknown, | |
860 hg_path, | |
861 ) | |
862 } | |
863 } | 857 } |
864 is_ignored | 858 is_ignored |
865 } | 859 } |
866 } | 860 } |
867 | 861 |