changeset 50148:06659dea51b0

rhg: fix a bug in path_encode This makes rhg able to access long paths at the root of the tree just fine.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Thu, 16 Feb 2023 14:56:59 +0000
parents 362fe34702d5
children 0f0880c8a7e5
files rust/hg-core/src/revlog/path_encode.rs
diffstat 1 files changed, 2 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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";