From 7a400a2c0270f2085b70690e4ddbfd8d141e69ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Mon, 13 Aug 2018 18:14:20 +0200 Subject: attr: remove an implicit dependency on the_index MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make the attr API take an index_state instead of assuming the_index in attr code. All 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. There is one ugly temporary workaround added in attr.c that needs some more explanation. Commit c24f3abace (apply: file commited with CRLF should roundtrip diff and apply - 2017-08-19) forces one convert_to_git() call to NOT read the index at all. But what do you know, we read it anyway by falling back to the_index. When "istate" from convert_to_git is now propagated down to read_attr_from_array() we will hit segfault somewhere inside read_blob_data_from_index. The right way of dealing with this is to kill "use_index" variable and only follow "istate" but at this stage we are not ready for that: while most git_attr_set_direction() calls just passes the_index to be assigned to use_index, unpack-trees passes a different one which is used by entry.c code, which has no way to know what index to use if we delete use_index. So this has to be done later. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- convert.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'convert.c') diff --git a/convert.c b/convert.c index 7907efd16f..1935bde929 100644 --- a/convert.c +++ b/convert.c @@ -1303,7 +1303,7 @@ static void convert_attrs(struct conv_attrs *ca, const char *path) git_config(read_convert_config, NULL); } - if (!git_check_attr(path, check)) { + if (!git_check_attr(&the_index, path, check)) { struct attr_check_item *ccheck = check->items; ca->crlf_action = git_path_check_crlf(ccheck + 4); if (ca->crlf_action == CRLF_UNDEFINED) -- cgit v1.2.1 From 7f944e264ebe2fcf9a2c228a9fc9463ab3274d39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Mon, 13 Aug 2018 18:14:21 +0200 Subject: convert.c: remove an implicit dependency on the_index MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- convert.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'convert.c') diff --git a/convert.c b/convert.c index 1935bde929..8acfe8ae45 100644 --- a/convert.c +++ b/convert.c @@ -1291,7 +1291,8 @@ struct conv_attrs { const char *working_tree_encoding; /* Supported encoding or default encoding if NULL */ }; -static void convert_attrs(struct conv_attrs *ca, const char *path) +static void convert_attrs(const struct index_state *istate, + struct conv_attrs *ca, const char *path) { static struct attr_check *check; @@ -1303,7 +1304,7 @@ static void convert_attrs(struct conv_attrs *ca, const char *path) git_config(read_convert_config, NULL); } - if (!git_check_attr(&the_index, path, check)) { + if (!git_check_attr(istate, path, check)) { struct attr_check_item *ccheck = check->items; ca->crlf_action = git_path_check_crlf(ccheck + 4); if (ca->crlf_action == CRLF_UNDEFINED) @@ -1340,11 +1341,11 @@ static void convert_attrs(struct conv_attrs *ca, const char *path) ca->crlf_action = CRLF_AUTO_INPUT; } -int would_convert_to_git_filter_fd(const char *path) +int would_convert_to_git_filter_fd(const struct index_state *istate, const char *path) { struct conv_attrs ca; - convert_attrs(&ca, path); + convert_attrs(istate, &ca, path); if (!ca.drv) return 0; @@ -1359,11 +1360,11 @@ int would_convert_to_git_filter_fd(const char *path) return apply_filter(path, NULL, 0, -1, NULL, ca.drv, CAP_CLEAN, NULL); } -const char *get_convert_attr_ascii(const char *path) +const char *get_convert_attr_ascii(const struct index_state *istate, const char *path) { struct conv_attrs ca; - convert_attrs(&ca, path); + convert_attrs(istate, &ca, path); switch (ca.attr_action) { case CRLF_UNDEFINED: return ""; @@ -1392,7 +1393,7 @@ int convert_to_git(const struct index_state *istate, int ret = 0; struct conv_attrs ca; - convert_attrs(&ca, path); + convert_attrs(istate, &ca, path); ret |= apply_filter(path, src, len, -1, dst, ca.drv, CAP_CLEAN, NULL); if (!ret && ca.drv && ca.drv->required) @@ -1424,7 +1425,7 @@ void convert_to_git_filter_fd(const struct index_state *istate, int conv_flags) { struct conv_attrs ca; - convert_attrs(&ca, path); + convert_attrs(istate, &ca, path); assert(ca.drv); assert(ca.drv->clean || ca.drv->process); @@ -1437,14 +1438,15 @@ void convert_to_git_filter_fd(const struct index_state *istate, ident_to_git(path, dst->buf, dst->len, dst, ca.ident); } -static int convert_to_working_tree_internal(const char *path, const char *src, +static int convert_to_working_tree_internal(const struct index_state *istate, + const char *path, const char *src, size_t len, struct strbuf *dst, int normalizing, struct delayed_checkout *dco) { int ret = 0, ret_filter = 0; struct conv_attrs ca; - convert_attrs(&ca, path); + convert_attrs(istate, &ca, path); ret |= ident_to_worktree(path, src, len, dst, ca.ident); if (ret) { @@ -1478,22 +1480,25 @@ static int convert_to_working_tree_internal(const char *path, const char *src, return ret | ret_filter; } -int async_convert_to_working_tree(const char *path, const char *src, +int async_convert_to_working_tree(const struct index_state *istate, + const char *path, const char *src, size_t len, struct strbuf *dst, void *dco) { - return convert_to_working_tree_internal(path, src, len, dst, 0, dco); + return convert_to_working_tree_internal(istate, path, src, len, dst, 0, dco); } -int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst) +int convert_to_working_tree(const struct index_state *istate, + const char *path, const char *src, + size_t len, struct strbuf *dst) { - return convert_to_working_tree_internal(path, src, len, dst, 0, NULL); + return convert_to_working_tree_internal(istate, path, src, len, dst, 0, NULL); } int renormalize_buffer(const struct index_state *istate, const char *path, const char *src, size_t len, struct strbuf *dst) { - int ret = convert_to_working_tree_internal(path, src, len, dst, 1, NULL); + int ret = convert_to_working_tree_internal(istate, path, src, len, dst, 1, NULL); if (ret) { src = dst->buf; len = dst->len; @@ -1927,12 +1932,14 @@ static struct stream_filter *ident_filter(const struct object_id *oid) * Note that you would be crazy to set CRLF, smuge/clean or ident to a * large binary blob you would want us not to slurp into the memory! */ -struct stream_filter *get_stream_filter(const char *path, const struct object_id *oid) +struct stream_filter *get_stream_filter(const struct index_state *istate, + const char *path, + const struct object_id *oid) { struct conv_attrs ca; struct stream_filter *filter = NULL; - convert_attrs(&ca, path); + convert_attrs(istate, &ca, path); if (ca.drv && (ca.drv->process || ca.drv->smudge || ca.drv->clean)) return NULL; -- cgit v1.2.1