@@ -17,14 +17,17 @@ impl Git {
17
17
// custom open options
18
18
let mut git_open_opts_map = git:: sec:: trust:: Mapping :: < git:: open:: Options > :: default ( ) ;
19
19
20
- // don't use the global git configs (not needed)
20
+ // On windows various configuration options are bundled as part of the installations
21
+ // This path depends on the install location of git and therefore requires some overhead to lookup
22
+ // This is basically only used on windows and has some overhead hence it's disabled on other platforms.
23
+ // `gitoxide` doesn't use this as default
21
24
let config = git:: permissions:: Config {
22
- system : false ,
23
- git : false ,
24
- user : false ,
25
+ system : true ,
26
+ git : true ,
27
+ user : true ,
25
28
env : true ,
26
29
includes : true ,
27
- git_binary : false ,
30
+ git_binary : cfg ! ( windows ) ,
28
31
} ;
29
32
// change options for config permissions without touching anything else
30
33
git_open_opts_map. reduced = git_open_opts_map. reduced . permissions ( git:: Permissions {
@@ -61,7 +64,29 @@ impl DiffProvider for Git {
61
64
let file_oid = find_file_in_commit ( & repo, & head, file) ?;
62
65
63
66
let file_object = repo. find_object ( file_oid) . ok ( ) ?;
64
- Some ( file_object. detach ( ) . data )
67
+ let mut data = file_object. detach ( ) . data ;
68
+ // convert LF to CRLF if configured to avoid showing every line as changed
69
+ if repo
70
+ . config_snapshot ( )
71
+ . boolean ( "core.autocrlf" )
72
+ . unwrap_or ( false )
73
+ {
74
+ let mut normalized_file = Vec :: with_capacity ( data. len ( ) ) ;
75
+ let mut at_cr = false ;
76
+ for & byte in & data {
77
+ if byte == b'\n' {
78
+ // if this is a LF instead of a CRLF (last byte was not a CR)
79
+ // insert a new CR to generate a CRLF
80
+ if !at_cr {
81
+ normalized_file. push ( b'\r' ) ;
82
+ }
83
+ }
84
+ at_cr = byte == b'\r' ;
85
+ normalized_file. push ( byte)
86
+ }
87
+ data = normalized_file
88
+ }
89
+ Some ( data)
65
90
}
66
91
}
67
92
0 commit comments