diff --git a/rust/hg-core/src/filepatterns.rs b/rust/hg-core/src/filepatterns.rs --- a/rust/hg-core/src/filepatterns.rs +++ b/rust/hg-core/src/filepatterns.rs @@ -536,7 +536,7 @@ Ok(Self { prefix: path_to_hg_path_buf(prefix).and_then(|mut p| { if !p.is_empty() { - p.push(b'/'); + p.push_byte(b'/'); } Ok(p) })?, diff --git a/rust/hg-core/src/matchers.rs b/rust/hg-core/src/matchers.rs --- a/rust/hg-core/src/matchers.rs +++ b/rust/hg-core/src/matchers.rs @@ -402,8 +402,8 @@ } root.push(HgPathBuf::from_bytes(p)); } - let buf = - root.iter().fold(HgPathBuf::new(), |acc, r| acc.join(r)); + let mut buf = HgPathBuf::new(); + root.iter().fold((), |(), r| buf.push(r)); roots.push(buf); } PatternSyntax::Path | PatternSyntax::RelPath => { diff --git a/rust/hg-core/src/utils/hg_path.rs b/rust/hg-core/src/utils/hg_path.rs --- a/rust/hg-core/src/utils/hg_path.rs +++ b/rust/hg-core/src/utils/hg_path.rs @@ -220,13 +220,11 @@ ), } } - pub fn join>(&self, other: &T) -> HgPathBuf { - let mut inner = self.inner.to_owned(); - if !inner.is_empty() && inner.last() != Some(&b'/') { - inner.push(b'/'); - } - inner.extend(other.as_ref().bytes()); - HgPathBuf::from_bytes(&inner) + + pub fn join(&self, path: &HgPath) -> HgPathBuf { + let mut buf = self.to_owned(); + buf.push(path); + buf } pub fn components(&self) -> impl Iterator { @@ -405,7 +403,15 @@ pub fn new() -> Self { Default::default() } - pub fn push(&mut self, byte: u8) { + + pub fn push>(&mut self, other: &T) -> () { + if !self.inner.is_empty() && self.inner.last() != Some(&b'/') { + self.inner.push(b'/'); + } + self.inner.extend(other.as_ref().bytes()) + } + + pub fn push_byte(&mut self, byte: u8) { self.inner.push(byte); } pub fn from_bytes(s: &[u8]) -> HgPathBuf {