rhg: fix a bug in path_encode
authorArseniy Alekseyev <aalekseyev@janestreet.com>
Thu, 16 Feb 2023 14:56:59 +0000
changeset 50096 06659dea51b0
parent 50095 362fe34702d5
child 50099 0f0880c8a7e5
rhg: fix a bug in path_encode This makes rhg able to access long paths at the root of the tree just fine.
rust/hg-core/src/revlog/path_encode.rs
--- a/rust/hg-core/src/revlog/path_encode.rs	Thu Feb 16 14:54:34 2023 +0000
+++ b/rust/hg-core/src/revlog/path_encode.rs	Thu Feb 16 14:56:59 2023 +0000
@@ -542,11 +542,9 @@
     let mut dest = vec![0; MAXSTOREPATHLEN];
     memcopy(Some(&mut dest), &mut destlen, b"dh/");
 
-    {
+    if let Some(last_slash) = last_slash {
         let mut first = true;
-        for slice in
-            src[..last_slash.unwrap_or(src.len())].split(|b| *b == b'/')
-        {
+        for slice in src[..last_slash].split(|b| *b == b'/') {
             let slice = &slice[..std::cmp::min(slice.len(), dirprefixlen)];
             if destlen + (slice.len() + if first { 0 } else { 1 })
                 > maxshortdirslen + 3
@@ -649,9 +647,7 @@
     use super::*;
     use crate::utils::hg_path::HgPathBuf;
 
-    // expected failure
     #[test]
-    #[should_panic]
     fn test_long_filename_at_root() {
         let input = b"data/ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ.i";
         let expected = b"dh/abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij.i708243a2237a7afae259ea3545a72a2ef11c247b.i";