##// END OF EJS Templates
rust-utils: add normalize_case util to mirror Python one...
Raphaël Gomès -
r43108:b1b984f9 default
parent child Browse files
Show More
@@ -7,9 +7,10 b''
7
7
8 use crate::{
8 use crate::{
9 dirstate::{parsers::PARENT_SIZE, EntryState},
9 dirstate::{parsers::PARENT_SIZE, EntryState},
10 pack_dirstate, parse_dirstate, CopyMap, DirsMultiset, DirstateEntry,
10 pack_dirstate, parse_dirstate,
11 DirstateError, DirstateMapError, DirstateParents, DirstateParseError,
11 utils::files::normalize_case,
12 StateMap,
12 CopyMap, DirsMultiset, DirstateEntry, DirstateError, DirstateMapError,
13 DirstateParents, DirstateParseError, StateMap,
13 };
14 };
14 use core::borrow::Borrow;
15 use core::borrow::Borrow;
15 use std::collections::{HashMap, HashSet};
16 use std::collections::{HashMap, HashSet};
@@ -127,7 +128,7 b' impl DirstateMap {'
127 }
128 }
128
129
129 if let Some(ref mut file_fold_map) = self.file_fold_map {
130 if let Some(ref mut file_fold_map) = self.file_fold_map {
130 file_fold_map.remove(&filename.to_ascii_uppercase());
131 file_fold_map.remove(&normalize_case(filename));
131 }
132 }
132 self.state_map.insert(
133 self.state_map.insert(
133 filename.to_owned(),
134 filename.to_owned(),
@@ -162,7 +163,7 b' impl DirstateMap {'
162 }
163 }
163 }
164 }
164 if let Some(ref mut file_fold_map) = self.file_fold_map {
165 if let Some(ref mut file_fold_map) = self.file_fold_map {
165 file_fold_map.remove(&filename.to_ascii_uppercase());
166 file_fold_map.remove(&normalize_case(filename));
166 }
167 }
167 self.non_normal_set.remove(filename);
168 self.non_normal_set.remove(filename);
168
169
@@ -326,10 +327,8 b' impl DirstateMap {'
326 for (filename, DirstateEntry { state, .. }) in self.state_map.borrow()
327 for (filename, DirstateEntry { state, .. }) in self.state_map.borrow()
327 {
328 {
328 if *state == EntryState::Removed {
329 if *state == EntryState::Removed {
329 new_file_fold_map.insert(
330 new_file_fold_map
330 filename.to_ascii_uppercase().to_owned(),
331 .insert(normalize_case(filename), filename.to_owned());
331 filename.to_owned(),
332 );
333 }
332 }
334 }
333 }
335 self.file_fold_map = Some(new_file_fold_map);
334 self.file_fold_map = Some(new_file_fold_map);
@@ -71,6 +71,15 b" pub fn find_dirs<'a>(path: &'a [u8]) -> "
71 dirs
71 dirs
72 }
72 }
73
73
74 /// TODO improve handling of utf8 file names. Our overall strategy for
75 /// filenames has to be revisited anyway, since Windows is UTF-16.
76 pub fn normalize_case(bytes: &[u8]) -> Vec<u8> {
77 #[cfg(windows)] // NTFS compares via upper()
78 return bytes.to_ascii_uppercase();
79 #[cfg(unix)]
80 bytes.to_ascii_lowercase()
81 }
82
74 #[cfg(test)]
83 #[cfg(test)]
75 mod tests {
84 mod tests {
76 #[test]
85 #[test]
General Comments 0
You need to be logged in to leave comments. Login now