rhg: fix a bug in path encoding, demonstrated in the parent commit stable
authorArseniy Alekseyev <aalekseyev@janestreet.com>
Fri, 24 Mar 2023 19:02:46 +0000
branchstable
changeset 50331 0b84474ebd0a
parent 50330 eb07591825fa
child 50332 3f5137543773
rhg: fix a bug in path encoding, demonstrated in the parent commit
rust/hg-core/src/revlog/path_encode.rs
--- a/rust/hg-core/src/revlog/path_encode.rs	Fri Mar 24 19:01:03 2023 +0000
+++ b/rust/hg-core/src/revlog/path_encode.rs	Fri Mar 24 19:02:46 2023 +0000
@@ -546,7 +546,13 @@
             if dest.len() + slice.len() > maxshortdirslen + 3 {
                 break;
             } else {
-                dest.write_bytes(slice);
+                let last_char = slice[slice.len() - 1];
+                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'/');
         }
@@ -612,8 +618,7 @@
     #[test]
     fn test_dirname_ends_with_underscore() {
         let input = b"data/dir1234.foo/ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ.i";
-        // TODO: BUG: trailing dot should become an underscore
-        let expected = b"dh/dir1234./abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij.if2e9ce59e095eff5f8f334dc809e65606a0aa50b.i";
+        let expected = b"dh/dir1234_/abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij.if2e9ce59e095eff5f8f334dc809e65606a0aa50b.i";
         let res = path_encode(input);
         assert_eq!(
             HgPathBuf::from_bytes(&res),