@@ -8,11 +8,17 @@ use std::path::PathBuf;
8
8
#[ cfg_attr( feature = "serde" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
9
9
#[ derive( PartialEq , Eq , Debug , Hash , Ord , PartialOrd , Clone , Copy ) ]
10
10
pub struct Capabilities {
11
- /// If true, the filesystem will store paths as decomposed unicode, i.e. `ä` becomes `"a\u{308}"`, which means that
12
- /// we have to turn these forms back from decomposed to precomposed unicode before storing it in the index or generally
13
- /// using it. This also applies to input received from the command-line, so callers may have to be aware of this and
14
- /// perform conversions accordingly.
15
- /// If false, no conversions will be performed.
11
+ /// If `true`, the filesystem will consider the precomposed umlaut `ä` similiar to its decomposed form `"a\u{308}"` and consider them the same.
12
+ /// If `false`, the filesystem will only see bytes which means that the above example could live side-by-side.
13
+ ///
14
+ /// Even though a filesystem that treats both forms the same will still reproduce the exact same byte sequence during traversal for instance,
15
+ /// this might also mean that we see paths in their decomposed form (this happens when creating directory `ä` in MacOS Finder for example).
16
+ ///
17
+ /// If Git would store such decomposed paths in the repository, which only sees bytes, on linux this might mean the path will look strange
18
+ /// at best, which is why it prefers to store precomposed unicode on systems where it matters, like MacOS and Windows.
19
+ ///
20
+ /// For best compatibility, and with this value being `true`, we will turn decomposed paths and input like command-line arguments into their
21
+ /// precomposed forms, so no decomposed byte sequences should end up in storage.
16
22
pub precompose_unicode : bool ,
17
23
/// If true, the filesystem ignores the case of input, which makes `A` the same file as `a`.
18
24
/// This is also called case-folding.
@@ -35,6 +41,22 @@ pub mod symlink;
35
41
///
36
42
pub mod dir;
37
43
44
+ /// Like [`std::env::current_dir()`], but it will `precompose_unicode` if that value is true, if the current directory
45
+ /// is valid unicode and if there are decomposed unicode codepoints.
46
+ ///
47
+ /// Thus, it will turn `"a\u{308}"` into `ä` if `true`.
48
+ /// Keeping it `false` will not alter the output.
49
+ ///
50
+ /// Note that `precompose_unicode` most be set using the `core.precomposeUnicode` git configuration.
51
+ pub fn current_dir ( precompose_unicode : bool ) -> std:: io:: Result < PathBuf > {
52
+ let cwd = std:: env:: current_dir ( ) ?;
53
+ Ok ( if precompose_unicode {
54
+ gix_utils:: str:: precompose_path ( cwd. into ( ) ) . into_owned ( )
55
+ } else {
56
+ cwd
57
+ } )
58
+ }
59
+
38
60
/// A stack of path components with the delegation of side-effects as the currently set path changes, component by component.
39
61
#[ derive( Clone ) ]
40
62
pub struct Stack {
0 commit comments