1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! Lossless raw-bytes → `OsString`/`PathBuf` bridge for filesystem paths taken
//! from `git`/`jj` machine output.
//!
//! A filesystem path is *bytes*, not text: on Unix a filename can be any byte
//! sequence except `/` and NUL, so it need not be valid UTF-8. Decoding such a
//! path through [`String::from_utf8_lossy`] substitutes `U+FFFD` for the offending
//! bytes, and the resulting `String` no longer names the same file — feeding it
//! back to `add`/`commit_paths` then addresses a *different* path (or none at
//! all). These helpers preserve the exact bytes so a path read from
//! status/diff/conflict output round-trips into a mutating call unchanged.
use OsString;
use PathBuf;
/// Build an [`OsString`] from raw filesystem-path `bytes`, losslessly on Unix.
///
/// - **Unix:** the bytes *are* the OS path encoding, wrapped verbatim via
/// [`OsStringExt::from_vec`](std::os::unix::ffi::OsStringExt::from_vec), so a
/// filename whose bytes are not valid UTF-8 survives byte-for-byte.
/// - **Other platforms (Windows/WASI):** `git` and `jj` emit their `-z` / machine
/// path output as UTF-8 there, so the bytes are decoded as UTF-8. A genuinely
/// invalid sequence — which these tools do not produce on this path — falls back
/// to the lossy replacement, preserving the pre-existing Windows
/// `String`/`OsString` behaviour (Unicode names like `𝓁abc` still round-trip).
/// [`os_from_bytes`] as a [`PathBuf`] — the path type the facade DTOs carry.