Skip to content

Commit c4500e2

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent 74cfc0e commit c4500e2

File tree

5 files changed

+8
-18
lines changed

5 files changed

+8
-18
lines changed

archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ int write_archive_entries(struct archiver_args *args,
274274
init_tree_desc(&t, args->tree->buffer, args->tree->size);
275275
if (unpack_trees(1, &t, &opts))
276276
return -1;
277-
git_attr_set_direction(GIT_ATTR_INDEX, &the_index);
277+
git_attr_set_direction(GIT_ATTR_INDEX);
278278
}
279279

280280
err = read_tree_recursive(args->tree, "", 0, 0, &args->pathspec,

attr.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -708,10 +708,8 @@ static struct attr_stack *read_attr_from_array(const char **list)
708708
* another thread could potentially be calling into the attribute system.
709709
*/
710710
static enum git_attr_direction direction;
711-
static const struct index_state *use_index;
712711

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)
715713
{
716714
if (is_bare_repository() && new_direction != GIT_ATTR_INDEX)
717715
BUG("non-INDEX attr direction in a bare repo");
@@ -720,7 +718,6 @@ void git_attr_set_direction(enum git_attr_direction new_direction,
720718
drop_all_attr_stacks();
721719

722720
direction = new_direction;
723-
use_index = istate;
724721
}
725722

726723
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,
750747
struct attr_stack *res;
751748
char *buf, *sp;
752749
int lineno = 0;
753-
const struct index_state *to_read_from;
754750

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)
761752
return NULL;
762753

763-
buf = read_blob_data_from_index(to_read_from, path, NULL);
754+
buf = read_blob_data_from_index(istate, path, NULL);
764755
if (!buf)
765756
return NULL;
766757

attr.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ enum git_attr_direction {
7777
GIT_ATTR_CHECKOUT,
7878
GIT_ATTR_INDEX
7979
};
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);
8281

8382
void attr_start(void);
8483

builtin/check-attr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
120120
}
121121

122122
if (cached_attrs)
123-
git_attr_set_direction(GIT_ATTR_INDEX, NULL);
123+
git_attr_set_direction(GIT_ATTR_INDEX);
124124

125125
doubledash = -1;
126126
for (i = 0; doubledash < 0 && i < argc; i++) {

unpack-trees.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ static int check_updates(struct unpack_trees_options *o)
353353
progress = get_progress(o);
354354

355355
if (o->update)
356-
git_attr_set_direction(GIT_ATTR_CHECKOUT, index);
356+
git_attr_set_direction(GIT_ATTR_CHECKOUT);
357357

358358
if (should_update_submodules() && o->update && !o->dry_run)
359359
load_gitmodules_file(index, NULL);
@@ -413,7 +413,7 @@ static int check_updates(struct unpack_trees_options *o)
413413
stop_progress(&progress);
414414
errs |= finish_delayed_checkout(&state);
415415
if (o->update)
416-
git_attr_set_direction(GIT_ATTR_CHECKIN, NULL);
416+
git_attr_set_direction(GIT_ATTR_CHECKIN);
417417
return errs != 0;
418418
}
419419

0 commit comments

Comments
 (0)