rhg: don't crash on empty directory names in path_encode, just in case
I don't expect that to be possible, but there's nothing in path_encode.rs
that prevents it, and the old code didn't crash in this case, so it's
better to be defensive.
--- a/rust/hg-core/src/revlog/path_encode.rs Fri Mar 24 19:02:46 2023 +0000
+++ b/rust/hg-core/src/revlog/path_encode.rs Fri Mar 24 19:19:37 2023 +0000
@@ -545,15 +545,15 @@
let slice = &slice[..std::cmp::min(slice.len(), dirprefixlen)];
if dest.len() + slice.len() > maxshortdirslen + 3 {
break;
- } else {
- let last_char = slice[slice.len() - 1];
- if last_char == b'.' || last_char == b' ' {
+ }
+ if let Some(last_char) = slice.last() {
+ if *last_char == b'.' || *last_char == b' ' {
dest.write_bytes(&slice[0..slice.len() - 1]);
dest.write_byte(b'_');
} else {
dest.write_bytes(slice);
}
- }
+ };
dest.write_byte(b'/');
}
}