Skip to content

Commit 43dd233

Browse files
eyvindgitster
authored andcommitted
Don't expand CRLFs when normalizing text during merge
Disable CRLF expansion when convert_to_working_tree() is called from normalize_buffer(). This improves performance when merging branches with conflicting line endings when core.eol=crlf or core.autocrlf=true by making the normalization act as if core.eol=lf. Signed-off-by: Eyvind Bernhardsen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 331a183 commit 43dd233

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

convert.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,9 @@ int convert_to_git(const char *path, const char *src, size_t len,
741741
return ret | ident_to_git(path, src, len, dst, ident);
742742
}
743743

744-
int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst)
744+
static int convert_to_working_tree_internal(const char *path, const char *src,
745+
size_t len, struct strbuf *dst,
746+
int normalizing)
745747
{
746748
struct git_attr_check check[5];
747749
enum action action = CRLF_GUESS;
@@ -767,18 +769,29 @@ int convert_to_working_tree(const char *path, const char *src, size_t len, struc
767769
src = dst->buf;
768770
len = dst->len;
769771
}
770-
action = determine_action(action, eol_attr);
771-
ret |= crlf_to_worktree(path, src, len, dst, action);
772-
if (ret) {
773-
src = dst->buf;
774-
len = dst->len;
772+
/*
773+
* CRLF conversion can be skipped if normalizing, unless there
774+
* is a smudge filter. The filter might expect CRLFs.
775+
*/
776+
if (filter || !normalizing) {
777+
action = determine_action(action, eol_attr);
778+
ret |= crlf_to_worktree(path, src, len, dst, action);
779+
if (ret) {
780+
src = dst->buf;
781+
len = dst->len;
782+
}
775783
}
776784
return ret | apply_filter(path, src, len, dst, filter);
777785
}
778786

787+
int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst)
788+
{
789+
return convert_to_working_tree_internal(path, src, len, dst, 0);
790+
}
791+
779792
int renormalize_buffer(const char *path, const char *src, size_t len, struct strbuf *dst)
780793
{
781-
int ret = convert_to_working_tree(path, src, len, dst);
794+
int ret = convert_to_working_tree_internal(path, src, len, dst, 1);
782795
if (ret) {
783796
src = dst->buf;
784797
len = dst->len;

0 commit comments

Comments
 (0)