# HG changeset patch # User Simon Sapin # Date 1614860813 -3600 # Node ID e8cd519a0a34a1fa08a7a035fedee77b06684d16 # Parent fb23685982811dc8c1cd92f4612cea526a8e2d8f rhg: Ignore trailing newlines in .hg/sharedpath Differential Revision: https://phab.mercurial-scm.org/D10132 diff -r fb2368598281 -r e8cd519a0a34 rust/hg-core/src/repo.rs --- a/rust/hg-core/src/repo.rs Tue Mar 02 21:31:12 2021 +0100 +++ b/rust/hg-core/src/repo.rs Thu Mar 04 13:26:53 2021 +0100 @@ -1,8 +1,8 @@ use crate::config::{Config, ConfigError, ConfigParseError}; use crate::errors::{HgError, IoErrorContext, IoResultExt}; use crate::requirements; -use crate::utils::current_dir; use crate::utils::files::get_path_from_bytes; +use crate::utils::{current_dir, SliceExt}; use memmap::{Mmap, MmapOptions}; use std::collections::HashSet; use std::path::{Path, PathBuf}; @@ -118,7 +118,8 @@ store_path = dot_hg.join("store"); } else { let bytes = hg_vfs.read("sharedpath")?; - let mut shared_path = get_path_from_bytes(&bytes).to_owned(); + let mut shared_path = + get_path_from_bytes(bytes.trim_end_newlines()).to_owned(); if relative { shared_path = dot_hg.join(shared_path) } diff -r fb2368598281 -r e8cd519a0a34 rust/hg-core/src/utils.rs --- a/rust/hg-core/src/utils.rs Tue Mar 02 21:31:12 2021 +0100 +++ b/rust/hg-core/src/utils.rs Thu Mar 04 13:26:53 2021 +0100 @@ -67,6 +67,7 @@ } pub trait SliceExt { + fn trim_end_newlines(&self) -> &Self; fn trim_end(&self) -> &Self; fn trim_start(&self) -> &Self; fn trim(&self) -> &Self; @@ -80,6 +81,13 @@ } impl SliceExt for [u8] { + fn trim_end_newlines(&self) -> &[u8] { + if let Some(last) = self.iter().rposition(|&byte| byte != b'\n') { + &self[..=last] + } else { + &[] + } + } fn trim_end(&self) -> &[u8] { if let Some(last) = self.iter().rposition(is_not_whitespace) { &self[..=last]