convert.c: remove an implicit dependency on the_index

Make the convert API take an index_state instead of assuming the_index in convert.c. All external call sites are converted blindly to keep the patch simple and retain current behavior. Individual call sites may receive further updates to use the right index instead of the_index. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Aug 13, 2018 at 18:14 UTC 7f944e264ebe2fcf9a2c228a9fc9463ab3274d39
10 files changed +45 -33
apply.c
+1 -1
@@ -4335,7 +4335,7 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,
4335 if (fd < 0)
4336 return 1;
4337
4338 - if (convert_to_working_tree(path, buf, size, &nbuf)) {
4338 + if (convert_to_working_tree(&the_index, path, buf, size, &nbuf)) {
4339 size = nbuf.len;
4340 buf = nbuf.buf;
4341 }
archive.c
+1 -1
@@ -79,7 +79,7 @@ void *object_file_to_archive(const struct archiver_args *args,
79 size_t size = 0;
80
81 strbuf_attach(&buf, buffer, *sizep, *sizep + 1);
82 - convert_to_working_tree(path, buf.buf, buf.len, &buf);
82 + convert_to_working_tree(&the_index, path, buf.buf, buf.len, &buf);
83 if (commit)
84 format_subst(commit, buf.buf, buf.len, &buf);
85 buffer = strbuf_detach(&buf, &size);
builtin/cat-file.c
+1 -1
@@ -39,7 +39,7 @@ static int filter_object(const char *path, unsigned mode,
39 oid_to_hex(oid), path);
40 if ((type == OBJ_BLOB) && S_ISREG(mode)) {
41 struct strbuf strbuf = STRBUF_INIT;
42 - if (convert_to_working_tree(path, *buf, *size, &strbuf)) {
42 + if (convert_to_working_tree(&the_index, path, *buf, *size, &strbuf)) {
43 free(*buf);
44 *size = strbuf.len;
45 *buf = strbuf_detach(&strbuf, NULL);
builtin/ls-files.c
+1 -1
@@ -63,7 +63,7 @@ static void write_eolinfo(const struct index_state *istate,
63 struct stat st;
64 const char *i_txt = "";
65 const char *w_txt = "";
66 - const char *a_txt = get_convert_attr_ascii(path);
66 + const char *a_txt = get_convert_attr_ascii(&the_index, path);
67 if (ce && S_ISREG(ce->ce_mode))
68 i_txt = get_cached_convert_stats_ascii(istate,
69 ce->name);
convert.c
+24 -17
@@ -1291,7 +1291,8 @@ struct conv_attrs {
1291 const char *working_tree_encoding; /* Supported encoding or default encoding if NULL */
1292 };
1293
1294 -static void convert_attrs(struct conv_attrs *ca, const char *path)
1294 +static void convert_attrs(const struct index_state *istate,
1295 + struct conv_attrs *ca, const char *path)
1296 {
1297 static struct attr_check *check;
1298
@@ -1303,7 +1304,7 @@ static void convert_attrs(struct conv_attrs *ca, const char *path)
1304 git_config(read_convert_config, NULL);
1305 }
1306
1306 - if (!git_check_attr(&the_index, path, check)) {
1307 + if (!git_check_attr(istate, path, check)) {
1308 struct attr_check_item *ccheck = check->items;
1309 ca->crlf_action = git_path_check_crlf(ccheck + 4);
1310 if (ca->crlf_action == CRLF_UNDEFINED)
@@ -1340,11 +1341,11 @@ static void convert_attrs(struct conv_attrs *ca, const char *path)
1341 ca->crlf_action = CRLF_AUTO_INPUT;
1342 }
1343
1343 -int would_convert_to_git_filter_fd(const char *path)
1344 +int would_convert_to_git_filter_fd(const struct index_state *istate, const char *path)
1345 {
1346 struct conv_attrs ca;
1347
1347 - convert_attrs(&ca, path);
1348 + convert_attrs(istate, &ca, path);
1349 if (!ca.drv)
1350 return 0;
1351
@@ -1359,11 +1360,11 @@ int would_convert_to_git_filter_fd(const char *path)
1360 return apply_filter(path, NULL, 0, -1, NULL, ca.drv, CAP_CLEAN, NULL);
1361 }
1362
1362 -const char *get_convert_attr_ascii(const char *path)
1363 +const char *get_convert_attr_ascii(const struct index_state *istate, const char *path)
1364 {
1365 struct conv_attrs ca;
1366
1366 - convert_attrs(&ca, path);
1367 + convert_attrs(istate, &ca, path);
1368 switch (ca.attr_action) {
1369 case CRLF_UNDEFINED:
1370 return "";
@@ -1392,7 +1393,7 @@ int convert_to_git(const struct index_state *istate,
1393 int ret = 0;
1394 struct conv_attrs ca;
1395
1395 - convert_attrs(&ca, path);
1396 + convert_attrs(istate, &ca, path);
1397
1398 ret |= apply_filter(path, src, len, -1, dst, ca.drv, CAP_CLEAN, NULL);
1399 if (!ret && ca.drv && ca.drv->required)
@@ -1424,7 +1425,7 @@ void convert_to_git_filter_fd(const struct index_state *istate,
1425 int conv_flags)
1426 {
1427 struct conv_attrs ca;
1427 - convert_attrs(&ca, path);
1428 + convert_attrs(istate, &ca, path);
1429
1430 assert(ca.drv);
1431 assert(ca.drv->clean || ca.drv->process);
@@ -1437,14 +1438,15 @@ void convert_to_git_filter_fd(const struct index_state *istate,
1438 ident_to_git(path, dst->buf, dst->len, dst, ca.ident);
1439 }
1440
1440 -static int convert_to_working_tree_internal(const char *path, const char *src,
1441 +static int convert_to_working_tree_internal(const struct index_state *istate,
1442 + const char *path, const char *src,
1443 size_t len, struct strbuf *dst,
1444 int normalizing, struct delayed_checkout *dco)
1445 {
1446 int ret = 0, ret_filter = 0;
1447 struct conv_attrs ca;
1448
1447 - convert_attrs(&ca, path);
1449 + convert_attrs(istate, &ca, path);
1450
1451 ret |= ident_to_worktree(path, src, len, dst, ca.ident);
1452 if (ret) {
@@ -1478,22 +1480,25 @@ static int convert_to_working_tree_internal(const char *path, const char *src,
1480 return ret | ret_filter;
1481 }
1482
1481 -int async_convert_to_working_tree(const char *path, const char *src,
1483 +int async_convert_to_working_tree(const struct index_state *istate,
1484 + const char *path, const char *src,
1485 size_t len, struct strbuf *dst,
1486 void *dco)
1487 {
1485 - return convert_to_working_tree_internal(path, src, len, dst, 0, dco);
1488 + return convert_to_working_tree_internal(istate, path, src, len, dst, 0, dco);
1489 }
1490
1488 -int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst)
1491 +int convert_to_working_tree(const struct index_state *istate,
1492 + const char *path, const char *src,
1493 + size_t len, struct strbuf *dst)
1494 {
1490 - return convert_to_working_tree_internal(path, src, len, dst, 0, NULL);
1495 + return convert_to_working_tree_internal(istate, path, src, len, dst, 0, NULL);
1496 }
1497
1498 int renormalize_buffer(const struct index_state *istate, const char *path,
1499 const char *src, size_t len, struct strbuf *dst)
1500 {
1496 - int ret = convert_to_working_tree_internal(path, src, len, dst, 1, NULL);
1501 + int ret = convert_to_working_tree_internal(istate, path, src, len, dst, 1, NULL);
1502 if (ret) {
1503 src = dst->buf;
1504 len = dst->len;
@@ -1927,12 +1932,14 @@ static struct stream_filter *ident_filter(const struct object_id *oid)
1932 * Note that you would be crazy to set CRLF, smuge/clean or ident to a
1933 * large binary blob you would want us not to slurp into the memory!
1934 */
1930 -struct stream_filter *get_stream_filter(const char *path, const struct object_id *oid)
1935 +struct stream_filter *get_stream_filter(const struct index_state *istate,
1936 + const char *path,
1937 + const struct object_id *oid)
1938 {
1939 struct conv_attrs ca;
1940 struct stream_filter *filter = NULL;
1941
1935 - convert_attrs(&ca, path);
1942 + convert_attrs(istate, &ca, path);
1943 if (ca.drv && (ca.drv->process || ca.drv->smudge || ca.drv->clean))
1944 return NULL;
1945
convert.h
+10 -5
@@ -60,15 +60,18 @@ extern char *check_roundtrip_encoding;
60 const char *get_cached_convert_stats_ascii(const struct index_state *istate,
61 const char *path);
62 const char *get_wt_convert_stats_ascii(const char *path);
63 -const char *get_convert_attr_ascii(const char *path);
63 +const char *get_convert_attr_ascii(const struct index_state *istate,
64 + const char *path);
65
66 /* returns 1 if *dst was used */
67 int convert_to_git(const struct index_state *istate,
68 const char *path, const char *src, size_t len,
69 struct strbuf *dst, int conv_flags);
69 -int convert_to_working_tree(const char *path, const char *src,
70 +int convert_to_working_tree(const struct index_state *istate,
71 + const char *path, const char *src,
72 size_t len, struct strbuf *dst);
71 -int async_convert_to_working_tree(const char *path, const char *src,
73 +int async_convert_to_working_tree(const struct index_state *istate,
74 + const char *path, const char *src,
75 size_t len, struct strbuf *dst,
76 void *dco);
77 int async_query_available_blobs(const char *cmd,
@@ -86,7 +89,8 @@ void convert_to_git_filter_fd(const struct index_state *istate,
89 const char *path, int fd,
90 struct strbuf *dst,
91 int conv_flags);
89 -int would_convert_to_git_filter_fd(const char *path);
92 +int would_convert_to_git_filter_fd(const struct index_state *istate,
93 + const char *path);
94
95 /*****************************************************************
96 *
@@ -96,7 +100,8 @@ int would_convert_to_git_filter_fd(const char *path);
100
101 struct stream_filter; /* opaque */
102
99 -struct stream_filter *get_stream_filter(const char *path,
103 +struct stream_filter *get_stream_filter(const struct index_state *istate,
104 + const char *path,
105 const struct object_id *);
106 void free_stream_filter(struct stream_filter *);
107 int is_null_stream_filter(struct stream_filter *);
diff.c
+1 -1
@@ -3893,7 +3893,7 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,
3893 temp->tempfile = mks_tempfile_ts(tempfile.buf, strlen(base) + 1);
3894 if (!temp->tempfile)
3895 die_errno("unable to create temp-file");
3896 - if (convert_to_working_tree(path,
3896 + if (convert_to_working_tree(&the_index, path,
3897 (const char *)blob, (size_t)size, &buf)) {
3898 blob = buf.buf;
3899 size = buf.len;
entry.c
+3 -3
@@ -266,7 +266,7 @@ static int write_entry(struct cache_entry *ce,
266 const struct submodule *sub;
267
268 if (ce_mode_s_ifmt == S_IFREG) {
269 - struct stream_filter *filter = get_stream_filter(ce->name,
269 + struct stream_filter *filter = get_stream_filter(&the_index, ce->name,
270 &ce->oid);
271 if (filter &&
272 !streaming_write_entry(ce, path, filter,
@@ -314,14 +314,14 @@ static int write_entry(struct cache_entry *ce,
314 * Convert from git internal format to working tree format
315 */
316 if (dco && dco->state != CE_NO_DELAY) {
317 - ret = async_convert_to_working_tree(ce->name, new_blob,
317 + ret = async_convert_to_working_tree(&the_index, ce->name, new_blob,
318 size, &buf, dco);
319 if (ret && string_list_has_string(&dco->paths, ce->name)) {
320 free(new_blob);
321 goto delayed;
322 }
323 } else
324 - ret = convert_to_working_tree(ce->name, new_blob, size, &buf);
324 + ret = convert_to_working_tree(&the_index, ce->name, new_blob, size, &buf);
325
326 if (ret) {
327 free(new_blob);
merge-recursive.c
+1 -1
@@ -966,7 +966,7 @@ static int update_file_flags(struct merge_options *o,
966 }
967 if (S_ISREG(mode)) {
968 struct strbuf strbuf = STRBUF_INIT;
969 - if (convert_to_working_tree(path, buf, size, &strbuf)) {
969 + if (convert_to_working_tree(&the_index, path, buf, size, &strbuf)) {
970 free(buf);
971 size = strbuf.len;
972 buf = strbuf_detach(&strbuf, NULL);
sha1-file.c
+2 -2
@@ -1860,7 +1860,7 @@ static int index_stream_convert_blob(struct object_id *oid, int fd,
1860 struct strbuf sbuf = STRBUF_INIT;
1861
1862 assert(path);
1863 - assert(would_convert_to_git_filter_fd(path));
1863 + assert(would_convert_to_git_filter_fd(&the_index, path));
1864
1865 convert_to_git_filter_fd(&the_index, path, fd, &sbuf,
1866 get_conv_flags(flags));
@@ -1950,7 +1950,7 @@ int index_fd(struct object_id *oid, int fd, struct stat *st,
1950 * Call xsize_t() only when needed to avoid potentially unnecessary
1951 * die() for large files.
1952 */
1953 - if (type == OBJ_BLOB && path && would_convert_to_git_filter_fd(path))
1953 + if (type == OBJ_BLOB && path && would_convert_to_git_filter_fd(&the_index, path))
1954 ret = index_stream_convert_blob(oid, fd, path, flags);
1955 else if (!S_ISREG(st->st_mode))
1956 ret = index_pipe(oid, fd, type, path, flags);