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 @@ -391,8 +391,7 @@ } = ignore_pattern; match syntax { PatternSyntax::RootGlob | PatternSyntax::Glob => { - let mut root = vec![]; - + let mut root = HgPathBuf::new(); for p in pattern.split(|c| *c == b'/') { if p.iter().any(|c| match *c { b'[' | b'{' | b'*' | b'?' => true, @@ -400,11 +399,9 @@ }) { break; } - root.push(HgPathBuf::from_bytes(p)); + root.push(HgPathBuf::from_bytes(p).as_ref()); } - let buf = - root.iter().fold(HgPathBuf::new(), |acc, r| acc.join(r)); - roots.push(buf); + roots.push(root); } PatternSyntax::Path | PatternSyntax::RelPath => { let pat = HgPath::new(if pattern == b"." { 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 {