[Updated] D10132: rhg: Ignore trailing newlines in .hg/sharedpath

SimonSapin phabricator at mercurial-scm.org
Wed Mar 10 19:23:38 UTC 2021


Closed by commit rHGe8cd519a0a34: rhg: Ignore trailing newlines in .hg/sharedpath (authored by SimonSapin).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D10132?vs=26191&id=26232

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D10132/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D10132

AFFECTED FILES
  rust/hg-core/src/repo.rs
  rust/hg-core/src/utils.rs

CHANGE DETAILS

diff --git a/rust/hg-core/src/utils.rs b/rust/hg-core/src/utils.rs
--- a/rust/hg-core/src/utils.rs
+++ b/rust/hg-core/src/utils.rs
@@ -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]
diff --git a/rust/hg-core/src/repo.rs b/rust/hg-core/src/repo.rs
--- a/rust/hg-core/src/repo.rs
+++ b/rust/hg-core/src/repo.rs
@@ -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)
             }



To: SimonSapin, #hg-reviewers, marmoute, Alphare
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20210310/56bcf3a0/attachment-0002.html>


More information about the Mercurial-patches mailing list