convert: convert crlf_to_git to take an index

Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed Jun 12, 2017 at 15:13 UTC 49a6d31fc8c4277b1c5f5b82331e7190afa1d4ce
1 file changed +8 -6
convert.c
+8 -6
@@ -218,13 +218,13 @@ static void check_safe_crlf(const char *path, enum crlf_action crlf_action,
218 }
219 }
220
221 -static int has_cr_in_index(const char *path)
221 +static int has_cr_in_index(const struct index_state *istate, const char *path)
222 {
223 unsigned long sz;
224 void *data;
225 int has_cr;
226
227 - data = read_blob_data_from_cache(path, &sz);
227 + data = read_blob_data_from_index(istate, path, &sz);
228 if (!data)
229 return 0;
230 has_cr = memchr(data, '\r', sz) != NULL;
@@ -254,7 +254,8 @@ static int will_convert_lf_to_crlf(size_t len, struct text_stat *stats,
254
255 }
256
257 -static int crlf_to_git(const char *path, const char *src, size_t len,
257 +static int crlf_to_git(const struct index_state *istate,
258 + const char *path, const char *src, size_t len,
259 struct strbuf *buf,
260 enum crlf_action crlf_action, enum safe_crlf checksafe)
261 {
@@ -286,7 +287,8 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
287 * unless we want to renormalize in a merge or
288 * cherry-pick.
289 */
289 - if ((checksafe != SAFE_CRLF_RENORMALIZE) && has_cr_in_index(path))
290 + if ((checksafe != SAFE_CRLF_RENORMALIZE) &&
291 + has_cr_in_index(istate, path))
292 convert_crlf_into_lf = 0;
293 }
294 if ((checksafe == SAFE_CRLF_WARN ||
@@ -1098,7 +1100,7 @@ int convert_to_git(const char *path, const char *src, size_t len,
1100 src = dst->buf;
1101 len = dst->len;
1102 }
1101 - ret |= crlf_to_git(path, src, len, dst, ca.crlf_action, checksafe);
1103 + ret |= crlf_to_git(&the_index, path, src, len, dst, ca.crlf_action, checksafe);
1104 if (ret && dst) {
1105 src = dst->buf;
1106 len = dst->len;
@@ -1118,7 +1120,7 @@ void convert_to_git_filter_fd(const char *path, int fd, struct strbuf *dst,
1120 if (!apply_filter(path, NULL, 0, fd, dst, ca.drv, CAP_CLEAN))
1121 die("%s: clean filter '%s' failed", path, ca.drv->name);
1122
1121 - crlf_to_git(path, dst->buf, dst->len, dst, ca.crlf_action, checksafe);
1123 + crlf_to_git(&the_index, path, dst->buf, dst->len, dst, ca.crlf_action, checksafe);
1124 ident_to_git(path, dst->buf, dst->len, dst, ca.ident);
1125 }
1126