attr: remove index from git_attr_set_direction()

Since attr checking API now take the index, there's no need to set an index in advance with this call. Most call sites are straightforward because they either pass the_index or NULL (which defaults back to the_index previously). There's only one suspicious call site in unpack-trees.c where it sets a different index. This code in unpack-trees is about to check out entries from the new/temporary index after merging is done in it. The attributes will be used by entry.c code to do crlf conversion if needed. entry.c now respects struct checkout's istate field, and this field is correctly set in unpack-trees.c, there should be no regression from this change. 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 c4500e251f89cbbc49fe90b832348ea9d4899946
5 files changed +8 -18
archive.c
+1 -1
@@ -274,7 +274,7 @@ int write_archive_entries(struct archiver_args *args,
274 init_tree_desc(&t, args->tree->buffer, args->tree->size);
275 if (unpack_trees(1, &t, &opts))
276 return -1;
277 - git_attr_set_direction(GIT_ATTR_INDEX, &the_index);
277 + git_attr_set_direction(GIT_ATTR_INDEX);
278 }
279
280 err = read_tree_recursive(args->tree, "", 0, 0, &args->pathspec,
attr.c
+3 -12
@@ -708,10 +708,8 @@ static struct attr_stack *read_attr_from_array(const char **list)
708 * another thread could potentially be calling into the attribute system.
709 */
710 static enum git_attr_direction direction;
711 -static const struct index_state *use_index;
711
713 -void git_attr_set_direction(enum git_attr_direction new_direction,
714 - const struct index_state *istate)
712 +void git_attr_set_direction(enum git_attr_direction new_direction)
713 {
714 if (is_bare_repository() && new_direction != GIT_ATTR_INDEX)
715 BUG("non-INDEX attr direction in a bare repo");
@@ -720,7 +718,6 @@ void git_attr_set_direction(enum git_attr_direction new_direction,
718 drop_all_attr_stacks();
719
720 direction = new_direction;
723 - use_index = istate;
721 }
722
723 static struct attr_stack *read_attr_from_file(const char *path, int macro_ok)
@@ -750,17 +747,11 @@ static struct attr_stack *read_attr_from_index(const struct index_state *istate,
747 struct attr_stack *res;
748 char *buf, *sp;
749 int lineno = 0;
753 - const struct index_state *to_read_from;
750
755 - /*
756 - * Temporary workaround for c24f3abace (apply: file commited
757 - * with CRLF should roundtrip diff and apply - 2017-08-19)
758 - */
759 - to_read_from = use_index ? use_index : istate;
760 - if (!to_read_from)
751 + if (!istate)
752 return NULL;
753
763 - buf = read_blob_data_from_index(to_read_from, path, NULL);
754 + buf = read_blob_data_from_index(istate, path, NULL);
755 if (!buf)
756 return NULL;
757
attr.h
+1 -2
@@ -77,8 +77,7 @@ enum git_attr_direction {
77 GIT_ATTR_CHECKOUT,
78 GIT_ATTR_INDEX
79 };
80 -void git_attr_set_direction(enum git_attr_direction new_direction,
81 - const struct index_state *istate);
80 +void git_attr_set_direction(enum git_attr_direction new_direction);
81
82 void attr_start(void);
83
builtin/check-attr.c
+1 -1
@@ -120,7 +120,7 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
120 }
121
122 if (cached_attrs)
123 - git_attr_set_direction(GIT_ATTR_INDEX, NULL);
123 + git_attr_set_direction(GIT_ATTR_INDEX);
124
125 doubledash = -1;
126 for (i = 0; doubledash < 0 && i < argc; i++) {
unpack-trees.c
+2 -2
@@ -353,7 +353,7 @@ static int check_updates(struct unpack_trees_options *o)
353 progress = get_progress(o);
354
355 if (o->update)
356 - git_attr_set_direction(GIT_ATTR_CHECKOUT, index);
356 + git_attr_set_direction(GIT_ATTR_CHECKOUT);
357
358 if (should_update_submodules() && o->update && !o->dry_run)
359 load_gitmodules_file(index, NULL);
@@ -413,7 +413,7 @@ static int check_updates(struct unpack_trees_options *o)
413 stop_progress(&progress);
414 errs |= finish_delayed_checkout(&state);
415 if (o->update)
416 - git_attr_set_direction(GIT_ATTR_CHECKIN, NULL);
416 + git_attr_set_direction(GIT_ATTR_CHECKIN);
417 return errs != 0;
418 }
419