Mercurial > public > mercurial-scm > hg-stable
comparison rust/hg-core/src/utils/hg_path.rs @ 47203:1249eb9cc332
dirstate-tree: Refactor DirstateMap::drop_file to be recursive
It should behave the same as before. This will enable the next changeset
to run code on the way "down" (in order to removing newly-empty nodes).
Differential Revision: https://phab.mercurial-scm.org/D10705
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Mon, 10 May 2021 21:31:05 +0200 |
parents | be579775c2d9 |
children | 6d69e83e6b6e |
comparison
equal
deleted
inserted
replaced
47202:b338d831d18c | 47203:1249eb9cc332 |
---|---|
3 // Copyright 2019 Raphaël Gomès <rgomes@octobus.net> | 3 // Copyright 2019 Raphaël Gomès <rgomes@octobus.net> |
4 // | 4 // |
5 // This software may be used and distributed according to the terms of the | 5 // This software may be used and distributed according to the terms of the |
6 // GNU General Public License version 2 or any later version. | 6 // GNU General Public License version 2 or any later version. |
7 | 7 |
8 use crate::utils::SliceExt; | |
8 use std::borrow::Borrow; | 9 use std::borrow::Borrow; |
9 use std::borrow::Cow; | 10 use std::borrow::Cow; |
10 use std::convert::TryFrom; | 11 use std::convert::TryFrom; |
11 use std::ffi::{OsStr, OsString}; | 12 use std::ffi::{OsStr, OsString}; |
12 use std::fmt; | 13 use std::fmt; |
230 | 231 |
231 pub fn components(&self) -> impl Iterator<Item = &HgPath> { | 232 pub fn components(&self) -> impl Iterator<Item = &HgPath> { |
232 self.inner.split(|&byte| byte == b'/').map(HgPath::new) | 233 self.inner.split(|&byte| byte == b'/').map(HgPath::new) |
233 } | 234 } |
234 | 235 |
236 /// Returns the first (that is "root-most") slash-separated component of | |
237 /// the path, and the rest after the first slash if there is one. | |
238 pub fn split_first_component(&self) -> (&HgPath, Option<&HgPath>) { | |
239 match self.inner.split_2(b'/') { | |
240 Some((a, b)) => (HgPath::new(a), Some(HgPath::new(b))), | |
241 None => (self, None), | |
242 } | |
243 } | |
244 | |
235 pub fn parent(&self) -> &Self { | 245 pub fn parent(&self) -> &Self { |
236 let inner = self.as_bytes(); | 246 let inner = self.as_bytes(); |
237 HgPath::new(match inner.iter().rposition(|b| *b == b'/') { | 247 HgPath::new(match inner.iter().rposition(|b| *b == b'/') { |
238 Some(pos) => &inner[..pos], | 248 Some(pos) => &inner[..pos], |
239 None => &[], | 249 None => &[], |