convert: add SAFE_CRLF_KEEP_CRLF

When convert_to_git() is called, the caller may want to keep CRLF to be kept as CRLF (and not converted into LF). This will be used in the next commit, when apply works with files that have CRLF and patches are applied onto these files. Add the new value "SAFE_CRLF_KEEP_CRLF" to safe_crlf. Prepare convert_to_git() to be able to run the clean filter, skip the CRLF conversion and run the ident filter. Signed-off-by: Torsten Bögershausen <tboegi@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Torsten Bögershausen committed Aug 13, 2017 at 10:51 UTC 2fea9de61857986431982ae89c01c89a2fc10038
2 files changed +8 -5
convert.c
+6 -4
@@ -1104,10 +1104,12 @@ int convert_to_git(const struct index_state *istate,
1104 src = dst->buf;
1105 len = dst->len;
1106 }
1107 - ret |= crlf_to_git(istate, path, src, len, dst, ca.crlf_action, checksafe);
1108 - if (ret && dst) {
1109 - src = dst->buf;
1110 - len = dst->len;
1107 + if (checksafe != SAFE_CRLF_KEEP_CRLF) {
1108 + ret |= crlf_to_git(istate, path, src, len, dst, ca.crlf_action, checksafe);
1109 + if (ret && dst) {
1110 + src = dst->buf;
1111 + len = dst->len;
1112 + }
1113 }
1114 return ret | ident_to_git(path, src, len, dst, ca.ident);
1115 }
convert.h
+2 -1
@@ -10,7 +10,8 @@ enum safe_crlf {
10 SAFE_CRLF_FALSE = 0,
11 SAFE_CRLF_FAIL = 1,
12 SAFE_CRLF_WARN = 2,
13 - SAFE_CRLF_RENORMALIZE = 3
13 + SAFE_CRLF_RENORMALIZE = 3,
14 + SAFE_CRLF_KEEP_CRLF = 4
15 };
16
17 extern enum safe_crlf safe_crlf;