|
1 | | -use bstr::ByteSlice; |
2 | | -use gix_fs::stack::ToNormalPathComponents; |
3 | | - |
4 | 1 | use crate::{ |
5 | 2 | bstr::{BStr, BString}, |
6 | 3 | tree, Tree, TreeRef, |
@@ -326,131 +323,14 @@ impl Ord for EntryRef<'_> { |
326 | 323 | } |
327 | 324 | } |
328 | 325 |
|
329 | | -/// A wrapper for `BString`. It is used to enforce the following constraints: |
330 | | -/// |
331 | | -/// - The path separator always is `/`, independent of the platform. |
332 | | -/// - Only normal components are allowed. |
333 | | -/// - It is always represented as a bunch of bytes. |
334 | | -#[derive(Clone, Debug, Eq, PartialEq, Hash)] |
335 | | -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
336 | | -pub struct RepositoryPathPuf { |
337 | | - inner: BString, |
338 | | -} |
339 | | - |
340 | | -impl RepositoryPathPuf { |
341 | | - fn len(&self) -> usize { |
342 | | - self.inner.len() |
343 | | - } |
344 | | - |
345 | | - fn get(&self, index: usize) -> std::option::Option<&u8> { |
346 | | - self.inner.get(index) |
347 | | - } |
348 | | - |
349 | | - fn find_byte(&self, byte: u8) -> std::option::Option<usize> { |
350 | | - self.inner.find_byte(byte) |
351 | | - } |
352 | | - |
353 | | - /// Do not use this method. |
354 | | - /// |
355 | | - /// This method is intended to be used during the transition from `BString` to |
356 | | - /// `RepositoryPathBuf` as long as there are APIs that expect the former instead of the latter. |
357 | | - pub fn into_bstring_do_not_use(self) -> BString { |
358 | | - self.inner |
359 | | - } |
360 | | -} |
361 | | - |
362 | | -impl std::fmt::Display for RepositoryPathPuf { |
363 | | - #[inline] |
364 | | - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
365 | | - self.inner.fmt(f) |
366 | | - } |
367 | | -} |
368 | | - |
369 | | -impl std::ops::Index<std::ops::RangeTo<usize>> for RepositoryPathPuf { |
370 | | - type Output = BStr; |
371 | | - |
372 | | - #[inline] |
373 | | - fn index(&self, r: std::ops::RangeTo<usize>) -> &BStr { |
374 | | - use bstr::ByteSlice; |
375 | | - |
376 | | - BStr::new(&self.inner.as_bytes()[..r.end]) |
377 | | - } |
378 | | -} |
379 | | - |
380 | | -/// |
381 | | -pub mod repository_path_buf { |
382 | | - use gix_fs::stack::to_normal_path_components; |
383 | | - |
384 | | - /// The error used in [`RepositoryPathPuf`](super::RepositoryPathPuf). |
385 | | - #[derive(Debug, thiserror::Error)] |
386 | | - #[allow(missing_docs)] |
387 | | - pub enum Error { |
388 | | - #[error(transparent)] |
389 | | - ContainsNonNormalComponents(#[from] to_normal_path_components::Error), |
390 | | - #[error(transparent)] |
391 | | - IllegalUtf8(#[from] gix_path::Utf8Error), |
392 | | - } |
393 | | -} |
394 | | - |
395 | | -impl TryFrom<&str> for RepositoryPathPuf { |
396 | | - type Error = repository_path_buf::Error; |
397 | | - |
398 | | - fn try_from(value: &str) -> Result<Self, Self::Error> { |
399 | | - let path = std::path::Path::new(value); |
400 | | - |
401 | | - for component in path.to_normal_path_components() { |
402 | | - component?; |
403 | | - } |
404 | | - |
405 | | - Ok(Self { inner: value.into() }) |
406 | | - } |
407 | | -} |
408 | | - |
409 | | -impl TryFrom<&BStr> for RepositoryPathPuf { |
410 | | - type Error = repository_path_buf::Error; |
411 | | - |
412 | | - fn try_from(value: &BStr) -> Result<Self, Self::Error> { |
413 | | - let path: &std::path::Path = &gix_path::try_from_bstr(value)?; |
414 | | - |
415 | | - for component in path.to_normal_path_components() { |
416 | | - component?; |
417 | | - } |
418 | | - |
419 | | - Ok(Self { inner: value.into() }) |
420 | | - } |
421 | | -} |
422 | | - |
423 | | -impl TryFrom<BString> for RepositoryPathPuf { |
424 | | - type Error = repository_path_buf::Error; |
425 | | - |
426 | | - fn try_from(value: BString) -> Result<Self, Self::Error> { |
427 | | - let path: &std::path::Path = &gix_path::try_from_bstr(&value)?; |
428 | | - |
429 | | - for component in path.to_normal_path_components() { |
430 | | - component?; |
431 | | - } |
432 | | - |
433 | | - Ok(Self { inner: value }) |
434 | | - } |
435 | | -} |
436 | | - |
437 | | -impl std::ops::Deref for RepositoryPathPuf { |
438 | | - type Target = [u8]; |
439 | | - |
440 | | - #[inline] |
441 | | - fn deref(&self) -> &[u8] { |
442 | | - &self.inner |
443 | | - } |
444 | | -} |
445 | | - |
446 | 326 | /// An entry in a [`Tree`], similar to an entry in a directory. |
447 | 327 | #[derive(PartialEq, Eq, Debug, Hash, Clone)] |
448 | 328 | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
449 | 329 | pub struct Entry { |
450 | 330 | /// The kind of object to which `oid` is pointing to. |
451 | 331 | pub mode: EntryMode, |
452 | 332 | /// The name of the file in the parent tree. |
453 | | - pub filename: RepositoryPathPuf, |
| 333 | + pub filename: BString, |
454 | 334 | /// The id of the object representing the entry. |
455 | 335 | pub oid: gix_hash::ObjectId, |
456 | 336 | } |
|
0 commit comments