Mercurial > hg-stable
changeset 42850:b1b984f9c01d
rust-utils: add normalize_case util to mirror Python one
While we still don't handle filenames properly cross-platform, this at least
sticks closer to the Python behavior.
Differential Revision: https://phab.mercurial-scm.org/D6756
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Thu, 22 Aug 2019 14:31:07 +0200 |
parents | ee0f511b7a22 |
children | ce6797ef6eab |
files | rust/hg-core/src/dirstate/dirstate_map.rs rust/hg-core/src/utils/files.rs |
diffstat | 2 files changed, 17 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate/dirstate_map.rs Wed Aug 28 08:16:58 2019 -0400 +++ b/rust/hg-core/src/dirstate/dirstate_map.rs Thu Aug 22 14:31:07 2019 +0200 @@ -7,9 +7,10 @@ use crate::{ dirstate::{parsers::PARENT_SIZE, EntryState}, - pack_dirstate, parse_dirstate, CopyMap, DirsMultiset, DirstateEntry, - DirstateError, DirstateMapError, DirstateParents, DirstateParseError, - StateMap, + pack_dirstate, parse_dirstate, + utils::files::normalize_case, + CopyMap, DirsMultiset, DirstateEntry, DirstateError, DirstateMapError, + DirstateParents, DirstateParseError, StateMap, }; use core::borrow::Borrow; use std::collections::{HashMap, HashSet}; @@ -127,7 +128,7 @@ } if let Some(ref mut file_fold_map) = self.file_fold_map { - file_fold_map.remove(&filename.to_ascii_uppercase()); + file_fold_map.remove(&normalize_case(filename)); } self.state_map.insert( filename.to_owned(), @@ -162,7 +163,7 @@ } } if let Some(ref mut file_fold_map) = self.file_fold_map { - file_fold_map.remove(&filename.to_ascii_uppercase()); + file_fold_map.remove(&normalize_case(filename)); } self.non_normal_set.remove(filename); @@ -326,10 +327,8 @@ for (filename, DirstateEntry { state, .. }) in self.state_map.borrow() { if *state == EntryState::Removed { - new_file_fold_map.insert( - filename.to_ascii_uppercase().to_owned(), - filename.to_owned(), - ); + new_file_fold_map + .insert(normalize_case(filename), filename.to_owned()); } } self.file_fold_map = Some(new_file_fold_map);
--- a/rust/hg-core/src/utils/files.rs Wed Aug 28 08:16:58 2019 -0400 +++ b/rust/hg-core/src/utils/files.rs Thu Aug 22 14:31:07 2019 +0200 @@ -71,6 +71,15 @@ dirs } +/// TODO improve handling of utf8 file names. Our overall strategy for +/// filenames has to be revisited anyway, since Windows is UTF-16. +pub fn normalize_case(bytes: &[u8]) -> Vec<u8> { + #[cfg(windows)] // NTFS compares via upper() + return bytes.to_ascii_uppercase(); + #[cfg(unix)] + bytes.to_ascii_lowercase() +} + #[cfg(test)] mod tests { #[test]