Mercurial > public > mercurial-scm > hg
comparison rust/hg-core/src/dirstate_tree/status.rs @ 49567:6b32d39e9a67
rust-status: make `DirEntry` attributes clearer
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Wed, 19 Oct 2022 14:46:19 +0200 |
parents | eb02decdf0ab |
children | da48f170d203 |
comparison
equal
deleted
inserted
replaced
49541:976648e20856 | 49567:6b32d39e9a67 |
---|---|
412 // `merge_join_by` requires both its input iterators to be sorted: | 412 // `merge_join_by` requires both its input iterators to be sorted: |
413 | 413 |
414 let dirstate_nodes = dirstate_nodes.sorted(); | 414 let dirstate_nodes = dirstate_nodes.sorted(); |
415 // `sort_unstable_by_key` doesn’t allow keys borrowing from the value: | 415 // `sort_unstable_by_key` doesn’t allow keys borrowing from the value: |
416 // https://github.com/rust-lang/rust/issues/34162 | 416 // https://github.com/rust-lang/rust/issues/34162 |
417 fs_entries.sort_unstable_by(|e1, e2| e1.base_name.cmp(&e2.base_name)); | 417 fs_entries.sort_unstable_by(|e1, e2| e1.hg_path.cmp(&e2.hg_path)); |
418 | 418 |
419 // Propagate here any error that would happen inside the comparison | 419 // Propagate here any error that would happen inside the comparison |
420 // callback below | 420 // callback below |
421 for dirstate_node in &dirstate_nodes { | 421 for dirstate_node in &dirstate_nodes { |
422 dirstate_node.base_name(self.dmap.on_disk)?; | 422 dirstate_node.base_name(self.dmap.on_disk)?; |
428 // This `unwrap` never panics because we already propagated | 428 // This `unwrap` never panics because we already propagated |
429 // those errors above | 429 // those errors above |
430 dirstate_node | 430 dirstate_node |
431 .base_name(self.dmap.on_disk) | 431 .base_name(self.dmap.on_disk) |
432 .unwrap() | 432 .unwrap() |
433 .cmp(&fs_entry.base_name) | 433 .cmp(&fs_entry.hg_path) |
434 }, | 434 }, |
435 ) | 435 ) |
436 .par_bridge() | 436 .par_bridge() |
437 .map(|pair| { | 437 .map(|pair| { |
438 use itertools::EitherOrBoth::*; | 438 use itertools::EitherOrBoth::*; |
439 let has_dirstate_node_or_is_ignored; | 439 let has_dirstate_node_or_is_ignored; |
440 match pair { | 440 match pair { |
441 Both(dirstate_node, fs_entry) => { | 441 Both(dirstate_node, fs_entry) => { |
442 self.traverse_fs_and_dirstate( | 442 self.traverse_fs_and_dirstate( |
443 &fs_entry.full_path, | 443 &fs_entry.fs_path, |
444 &fs_entry.metadata, | 444 &fs_entry.metadata, |
445 dirstate_node, | 445 dirstate_node, |
446 has_ignored_ancestor, | 446 has_ignored_ancestor, |
447 )?; | 447 )?; |
448 has_dirstate_node_or_is_ignored = true | 448 has_dirstate_node_or_is_ignored = true |
735 &self, | 735 &self, |
736 has_ignored_ancestor: bool, | 736 has_ignored_ancestor: bool, |
737 directory_hg_path: &HgPath, | 737 directory_hg_path: &HgPath, |
738 fs_entry: &DirEntry, | 738 fs_entry: &DirEntry, |
739 ) -> bool { | 739 ) -> bool { |
740 let hg_path = directory_hg_path.join(&fs_entry.base_name); | 740 let hg_path = directory_hg_path.join(&fs_entry.hg_path); |
741 let file_type = fs_entry.metadata.file_type(); | 741 let file_type = fs_entry.metadata.file_type(); |
742 let file_or_symlink = file_type.is_file() || file_type.is_symlink(); | 742 let file_or_symlink = file_type.is_file() || file_type.is_symlink(); |
743 if file_type.is_dir() { | 743 if file_type.is_dir() { |
744 let is_ignored = | 744 let is_ignored = |
745 has_ignored_ancestor || (self.ignore_fn)(&hg_path); | 745 has_ignored_ancestor || (self.ignore_fn)(&hg_path); |
753 }; | 753 }; |
754 if traverse_children { | 754 if traverse_children { |
755 let is_at_repo_root = false; | 755 let is_at_repo_root = false; |
756 if let Ok(children_fs_entries) = self.read_dir( | 756 if let Ok(children_fs_entries) = self.read_dir( |
757 &hg_path, | 757 &hg_path, |
758 &fs_entry.full_path, | 758 &fs_entry.fs_path, |
759 is_at_repo_root, | 759 is_at_repo_root, |
760 ) { | 760 ) { |
761 children_fs_entries.par_iter().for_each(|child_fs_entry| { | 761 children_fs_entries.par_iter().for_each(|child_fs_entry| { |
762 self.traverse_fs_only( | 762 self.traverse_fs_only( |
763 is_ignored, | 763 is_ignored, |
819 is_ignored | 819 is_ignored |
820 } | 820 } |
821 } | 821 } |
822 | 822 |
823 struct DirEntry { | 823 struct DirEntry { |
824 base_name: HgPathBuf, | 824 /// Path as stored in the dirstate |
825 full_path: PathBuf, | 825 hg_path: HgPathBuf, |
826 /// Filesystem path | |
827 fs_path: PathBuf, | |
826 metadata: std::fs::Metadata, | 828 metadata: std::fs::Metadata, |
827 } | 829 } |
828 | 830 |
829 impl DirEntry { | 831 impl DirEntry { |
830 /// Returns **unsorted** entries in the given directory, with name and | 832 /// Returns **unsorted** entries in the given directory, with name and |
870 } else { | 872 } else { |
871 entry.path() | 873 entry.path() |
872 }; | 874 }; |
873 let base_name = get_bytes_from_os_string(file_name).into(); | 875 let base_name = get_bytes_from_os_string(file_name).into(); |
874 results.push(DirEntry { | 876 results.push(DirEntry { |
875 base_name, | 877 hg_path: base_name, |
876 full_path, | 878 fs_path: full_path, |
877 metadata, | 879 metadata, |
878 }) | 880 }) |
879 } | 881 } |
880 Ok(results) | 882 Ok(results) |
881 } | 883 } |