convert: convert convert_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 82b474e025e89cfa294e81611c81355a73dc23a2
8 files changed +18 -15
apply.c
+1 -1
@@ -2267,7 +2267,7 @@ static int read_old_data(struct stat *st, const char *path, struct strbuf *buf)
2267 case S_IFREG:
2268 if (strbuf_read_file(buf, path, st->st_size) != st->st_size)
2269 return error(_("unable to open or read %s"), path);
2270 - convert_to_git(path, buf->buf, buf->len, buf, 0);
2270 + convert_to_git(&the_index, path, buf->buf, buf->len, buf, 0);
2271 return 0;
2272 default:
2273 return -1;
blame.c
+1 -1
@@ -229,7 +229,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
229 if (strbuf_read(&buf, 0, 0) < 0)
230 die_errno("failed to read from stdin");
231 }
232 - convert_to_git(path, buf.buf, buf.len, &buf, 0);
232 + convert_to_git(&the_index, path, buf.buf, buf.len, &buf, 0);
233 origin->file.ptr = buf.buf;
234 origin->file.size = buf.len;
235 pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_oid.hash);
combine-diff.c
+1 -1
@@ -1053,7 +1053,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
1053 if (is_file) {
1054 struct strbuf buf = STRBUF_INIT;
1055
1056 - if (convert_to_git(elem->path, result, len, &buf, safe_crlf)) {
1056 + if (convert_to_git(&the_index, elem->path, result, len, &buf, safe_crlf)) {
1057 free(result);
1058 result = strbuf_detach(&buf, &len);
1059 result_size = len;
convert.c
+4 -3
@@ -1084,7 +1084,8 @@ const char *get_convert_attr_ascii(const char *path)
1084 return "";
1085 }
1086
1087 -int convert_to_git(const char *path, const char *src, size_t len,
1087 +int convert_to_git(const struct index_state *istate,
1088 + const char *path, const char *src, size_t len,
1089 struct strbuf *dst, enum safe_crlf checksafe)
1090 {
1091 int ret = 0;
@@ -1100,7 +1101,7 @@ int convert_to_git(const char *path, const char *src, size_t len,
1101 src = dst->buf;
1102 len = dst->len;
1103 }
1103 - ret |= crlf_to_git(&the_index, path, src, len, dst, ca.crlf_action, checksafe);
1104 + ret |= crlf_to_git(istate, path, src, len, dst, ca.crlf_action, checksafe);
1105 if (ret && dst) {
1106 src = dst->buf;
1107 len = dst->len;
@@ -1171,7 +1172,7 @@ int renormalize_buffer(const char *path, const char *src, size_t len, struct str
1172 src = dst->buf;
1173 len = dst->len;
1174 }
1174 - return ret | convert_to_git(path, src, len, dst, SAFE_CRLF_RENORMALIZE);
1175 + return ret | convert_to_git(&the_index, path, src, len, dst, SAFE_CRLF_RENORMALIZE);
1176 }
1177
1178 /*****************************************************************
convert.h
+5 -3
@@ -41,15 +41,17 @@ extern const char *get_wt_convert_stats_ascii(const char *path);
41 extern const char *get_convert_attr_ascii(const char *path);
42
43 /* returns 1 if *dst was used */
44 -extern int convert_to_git(const char *path, const char *src, size_t len,
44 +extern int convert_to_git(const struct index_state *istate,
45 + const char *path, const char *src, size_t len,
46 struct strbuf *dst, enum safe_crlf checksafe);
47 extern int convert_to_working_tree(const char *path, const char *src,
48 size_t len, struct strbuf *dst);
49 extern int renormalize_buffer(const char *path, const char *src, size_t len,
50 struct strbuf *dst);
50 -static inline int would_convert_to_git(const char *path)
51 +static inline int would_convert_to_git(const struct index_state *istate,
52 + const char *path)
53 {
52 - return convert_to_git(path, NULL, 0, NULL, 0);
54 + return convert_to_git(istate, path, NULL, 0, NULL, 0);
55 }
56 /* Precondition: would_convert_to_git_filter_fd(path) == true */
57 extern void convert_to_git_filter_fd(const struct index_state *istate,
diff.c
+3 -3
@@ -2755,7 +2755,7 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
2755 * Similarly, if we'd have to convert the file contents anyway, that
2756 * makes the optimization not worthwhile.
2757 */
2758 - if (!want_file && would_convert_to_git(name))
2758 + if (!want_file && would_convert_to_git(&the_index, name))
2759 return 0;
2760
2761 len = strlen(name);
@@ -2877,7 +2877,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
2877 * point if the path requires us to run the content
2878 * conversion.
2879 */
2880 - if (size_only && !would_convert_to_git(s->path))
2880 + if (size_only && !would_convert_to_git(&the_index, s->path))
2881 return 0;
2882
2883 /*
@@ -2904,7 +2904,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
2904 /*
2905 * Convert from working tree format to canonical git format
2906 */
2907 - if (convert_to_git(s->path, s->data, s->size, &buf, crlf_warn)) {
2907 + if (convert_to_git(&the_index, s->path, s->data, s->size, &buf, crlf_warn)) {
2908 size_t size = 0;
2909 munmap(s->data, s->size);
2910 s->should_munmap = 0;
dir.c
+1 -1
@@ -795,7 +795,7 @@ static int add_excludes(const char *fname, const char *base, int baselen,
795 (pos = index_name_pos(istate, fname, strlen(fname))) >= 0 &&
796 !ce_stage(istate->cache[pos]) &&
797 ce_uptodate(istate->cache[pos]) &&
798 - !would_convert_to_git(fname))
798 + !would_convert_to_git(istate, fname))
799 hashcpy(sha1_stat->sha1,
800 istate->cache[pos]->oid.hash);
801 else
sha1_file.c
+2 -2
@@ -3546,7 +3546,7 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size,
3546 */
3547 if ((type == OBJ_BLOB) && path) {
3548 struct strbuf nbuf = STRBUF_INIT;
3549 - if (convert_to_git(path, buf, size, &nbuf,
3549 + if (convert_to_git(&the_index, path, buf, size, &nbuf,
3550 write_object ? safe_crlf : SAFE_CRLF_FALSE)) {
3551 buf = strbuf_detach(&nbuf, &size);
3552 re_allocated = 1;
@@ -3668,7 +3668,7 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st,
3668 else if (!S_ISREG(st->st_mode))
3669 ret = index_pipe(sha1, fd, type, path, flags);
3670 else if (st->st_size <= big_file_threshold || type != OBJ_BLOB ||
3671 - (path && would_convert_to_git(path)))
3671 + (path && would_convert_to_git(&the_index, path)))
3672 ret = index_core(sha1, fd, xsize_t(st->st_size), type, path,
3673 flags);
3674 else