mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 09:26:19 +04:00
fix git diff when core.autocrlf is enabled (#4995)
This commit is contained in:
parent
1e31bc3f77
commit
b0f20f13e3
@ -17,14 +17,17 @@ fn open_repo(path: &Path, ceiling_dir: Option<&Path>) -> Option<ThreadSafeReposi
|
|||||||
// custom open options
|
// custom open options
|
||||||
let mut git_open_opts_map = git::sec::trust::Mapping::<git::open::Options>::default();
|
let mut git_open_opts_map = git::sec::trust::Mapping::<git::open::Options>::default();
|
||||||
|
|
||||||
// don't use the global git configs (not needed)
|
// On windows various configuration options are bundled as part of the installations
|
||||||
|
// This path depends on the install location of git and therefore requires some overhead to lookup
|
||||||
|
// This is basically only used on windows and has some overhead hence it's disabled on other platforms.
|
||||||
|
// `gitoxide` doesn't use this as default
|
||||||
let config = git::permissions::Config {
|
let config = git::permissions::Config {
|
||||||
system: false,
|
system: true,
|
||||||
git: false,
|
git: true,
|
||||||
user: false,
|
user: true,
|
||||||
env: true,
|
env: true,
|
||||||
includes: true,
|
includes: true,
|
||||||
git_binary: false,
|
git_binary: cfg!(windows),
|
||||||
};
|
};
|
||||||
// change options for config permissions without touching anything else
|
// change options for config permissions without touching anything else
|
||||||
git_open_opts_map.reduced = git_open_opts_map.reduced.permissions(git::Permissions {
|
git_open_opts_map.reduced = git_open_opts_map.reduced.permissions(git::Permissions {
|
||||||
@ -61,7 +64,29 @@ fn get_diff_base(&self, file: &Path) -> Option<Vec<u8>> {
|
|||||||
let file_oid = find_file_in_commit(&repo, &head, file)?;
|
let file_oid = find_file_in_commit(&repo, &head, file)?;
|
||||||
|
|
||||||
let file_object = repo.find_object(file_oid).ok()?;
|
let file_object = repo.find_object(file_oid).ok()?;
|
||||||
Some(file_object.detach().data)
|
let mut data = file_object.detach().data;
|
||||||
|
// convert LF to CRLF if configured to avoid showing every line as changed
|
||||||
|
if repo
|
||||||
|
.config_snapshot()
|
||||||
|
.boolean("core.autocrlf")
|
||||||
|
.unwrap_or(false)
|
||||||
|
{
|
||||||
|
let mut normalized_file = Vec::with_capacity(data.len());
|
||||||
|
let mut at_cr = false;
|
||||||
|
for &byte in &data {
|
||||||
|
if byte == b'\n' {
|
||||||
|
// if this is a LF instead of a CRLF (last byte was not a CR)
|
||||||
|
// insert a new CR to generate a CRLF
|
||||||
|
if !at_cr {
|
||||||
|
normalized_file.push(b'\r');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
at_cr = byte == b'\r';
|
||||||
|
normalized_file.push(byte)
|
||||||
|
}
|
||||||
|
data = normalized_file
|
||||||
|
}
|
||||||
|
Some(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user