Mercurial > public > mercurial-scm > hg-stable
comparison rust/hg-core/src/utils/hg_path.rs @ 52074:de317a87ea6a
rust-pathauditor: match more of Python's behavior and display messages
We will make use of the path auditor when running our update fast-path,
and we want to output of it to be close enough.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Wed, 02 Oct 2024 20:29:48 +0200 |
parents | d27b6fc7c1bf |
children | 94e2547e6f3d |
comparison
equal
deleted
inserted
replaced
52073:a8cf6a852f11 | 52074:de317a87ea6a |
---|---|
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::errors::HgError; | |
8 use crate::utils::SliceExt; | 9 use crate::utils::SliceExt; |
9 use std::borrow::Borrow; | 10 use std::borrow::Borrow; |
10 use std::borrow::Cow; | 11 use std::borrow::Cow; |
11 use std::ffi::{OsStr, OsString}; | 12 use std::ffi::{OsStr, OsString}; |
12 use std::fmt; | 13 use std::fmt; |
46 path: PathBuf, | 47 path: PathBuf, |
47 root: PathBuf, | 48 root: PathBuf, |
48 }, | 49 }, |
49 } | 50 } |
50 | 51 |
52 impl From<HgPathError> for HgError { | |
53 fn from(value: HgPathError) -> Self { | |
54 HgError::Path(value) | |
55 } | |
56 } | |
57 | |
51 impl fmt::Display for HgPathError { | 58 impl fmt::Display for HgPathError { |
52 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | 59 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
53 match self { | 60 match self { |
54 HgPathError::LeadingSlash(bytes) => { | 61 HgPathError::LeadingSlash(bytes) => { |
55 write!(f, "Invalid HgPath '{:?}': has a leading slash.", bytes) | 62 write!(f, "Invalid HgPath '{:?}': has a leading slash.", bytes) |
74 f, | 81 f, |
75 "Invalid HgPath '{:?}': could not be decoded.", | 82 "Invalid HgPath '{:?}': could not be decoded.", |
76 bytes | 83 bytes |
77 ), | 84 ), |
78 HgPathError::EndsWithSlash(path) => { | 85 HgPathError::EndsWithSlash(path) => { |
79 write!(f, "Audit failed for '{}': ends with a slash.", path) | 86 write!(f, "path '{}': ends with a slash", path) |
80 } | 87 } |
81 HgPathError::ContainsIllegalComponent(path) => write!( | 88 HgPathError::ContainsIllegalComponent(path) => { |
82 f, | 89 write!(f, "path contains illegal component: {}", path) |
83 "Audit failed for '{}': contains an illegal component.", | 90 } |
84 path | 91 HgPathError::InsideDotHg(path) => { |
85 ), | 92 write!(f, "path '{}' is inside the '.hg' folder", path) |
86 HgPathError::InsideDotHg(path) => write!( | 93 } |
87 f, | |
88 "Audit failed for '{}': is inside the '.hg' folder.", | |
89 path | |
90 ), | |
91 HgPathError::IsInsideNestedRepo { | 94 HgPathError::IsInsideNestedRepo { |
92 path, | 95 path, |
93 nested_repo: nested, | 96 nested_repo: nested, |
94 } => { | 97 } => { |
95 write!(f, | 98 write!(f, "path '{}' is inside nested repo '{}'", path, nested) |
96 "Audit failed for '{}': is inside a nested repository '{}'.", | |
97 path, nested | |
98 ) | |
99 } | 99 } |
100 HgPathError::TraversesSymbolicLink { path, symlink } => write!( | 100 HgPathError::TraversesSymbolicLink { path, symlink } => write!( |
101 f, | 101 f, |
102 "Audit failed for '{}': traverses symbolic link '{}'.", | 102 "path '{}' traverses symbolic link '{}'", |
103 path, symlink | 103 path, symlink |
104 ), | 104 ), |
105 HgPathError::NotFsCompliant(path) => write!( | 105 HgPathError::NotFsCompliant(path) => write!( |
106 f, | 106 f, |
107 "Audit failed for '{}': cannot be turned into a \ | 107 "path '{}' cannot be turned into a \ |
108 filesystem path.", | 108 filesystem path", |
109 path | 109 path |
110 ), | 110 ), |
111 HgPathError::NotUnderRoot { path, root } => write!( | 111 HgPathError::NotUnderRoot { path, root } => write!( |
112 f, | 112 f, |
113 "Audit failed for '{}': not under root {}.", | 113 "path '{}' not under root {}", |
114 path.display(), | 114 path.display(), |
115 root.display() | 115 root.display() |
116 ), | 116 ), |
117 } | 117 } |
118 } | 118 } |