changeset 50331:0b84474ebd0a stable

rhg: fix a bug in path encoding, demonstrated in the parent commit
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Fri, 24 Mar 2023 19:02:46 +0000
parents eb07591825fa
children 3f5137543773
files rust/hg-core/src/revlog/path_encode.rs
diffstat 1 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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),