708
* another thread could potentially be calling into the attribute system.
709
*/
710
static enum git_attr_direction direction;
711
-static struct index_state *use_index;
711
+static const struct index_state *use_index;
712
713
void git_attr_set_direction(enum git_attr_direction new_direction,
714
- struct index_state *istate)
714
+ const struct index_state *istate)
715
{
716
if (is_bare_repository() && new_direction != GIT_ATTR_INDEX)
717
BUG("non-INDEX attr direction in a bare repo");
743
return res;
744
}
745
746
-static struct attr_stack *read_attr_from_index(const char *path, int macro_ok)
746
+static struct attr_stack *read_attr_from_index(const struct index_state *istate,
747
+ const char *path,
748
+ int macro_ok)
749
{
750
struct attr_stack *res;
751
char *buf, *sp;
752
int lineno = 0;
753
+ const struct index_state *to_read_from;
754
752
- buf = read_blob_data_from_index(use_index ? use_index : &the_index, path, NULL);
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)
761
+ return NULL;
762
+
763
+ buf = read_blob_data_from_index(to_read_from, path, NULL);
764
if (!buf)
765
return NULL;
766
779
return res;
780
}
781
771
-static struct attr_stack *read_attr(const char *path, int macro_ok)
782
+static struct attr_stack *read_attr(const struct index_state *istate,
783
+ const char *path, int macro_ok)
784
{
785
struct attr_stack *res = NULL;
786
787
if (direction == GIT_ATTR_INDEX) {
776
- res = read_attr_from_index(path, macro_ok);
788
+ res = read_attr_from_index(istate, path, macro_ok);
789
} else if (!is_bare_repository()) {
790
if (direction == GIT_ATTR_CHECKOUT) {
779
- res = read_attr_from_index(path, macro_ok);
791
+ res = read_attr_from_index(istate, path, macro_ok);
792
if (!res)
793
res = read_attr_from_file(path, macro_ok);
794
} else if (direction == GIT_ATTR_CHECKIN) {
800
* We allow operation in a sparsely checked out
801
* work tree, so read from it.
802
*/
791
- res = read_attr_from_index(path, macro_ok);
803
+ res = read_attr_from_index(istate, path, macro_ok);
804
}
805
}
806
871
}
872
}
873
862
-static void bootstrap_attr_stack(struct attr_stack **stack)
874
+static void bootstrap_attr_stack(const struct index_state *istate,
875
+ struct attr_stack **stack)
876
{
877
struct attr_stack *e;
878
896
}
897
898
/* root directory */
886
- e = read_attr(GITATTRIBUTES_FILE, 1);
899
+ e = read_attr(istate, GITATTRIBUTES_FILE, 1);
900
push_stack(stack, e, xstrdup(""), 0);
901
902
/* info frame */
909
push_stack(stack, e, NULL, 0);
910
}
911
899
-static void prepare_attr_stack(const char *path, int dirlen,
912
+static void prepare_attr_stack(const struct index_state *istate,
913
+ const char *path, int dirlen,
914
struct attr_stack **stack)
915
{
916
struct attr_stack *info;
931
* .gitattributes in deeper directories to shallower ones,
932
* and finally use the built-in set as the default.
933
*/
920
- bootstrap_attr_stack(stack);
934
+ bootstrap_attr_stack(istate, stack);
935
936
/*
937
* Pop the "info" one that is always at the top of the stack.
987
strbuf_add(&pathbuf, path + pathbuf.len, (len - pathbuf.len));
988
strbuf_addf(&pathbuf, "/%s", GITATTRIBUTES_FILE);
989
976
- next = read_attr(pathbuf.buf, 0);
990
+ next = read_attr(istate, pathbuf.buf, 0);
991
992
/* reset the pathbuf to not include "/.gitattributes" */
993
strbuf_setlen(&pathbuf, len);
1109
* If check->check_nr is non-zero, only attributes in check[] are collected.
1110
* Otherwise all attributes are collected.
1111
*/
1098
-static void collect_some_attrs(const char *path, struct attr_check *check)
1112
+static void collect_some_attrs(const struct index_state *istate,
1113
+ const char *path,
1114
+ struct attr_check *check)
1115
{
1116
int i, pathlen, rem, dirlen;
1117
const char *cp, *last_slash = NULL;
1130
dirlen = 0;
1131
}
1132
1117
- prepare_attr_stack(path, dirlen, &check->stack);
1133
+ prepare_attr_stack(istate, path, dirlen, &check->stack);
1134
all_attrs_init(&g_attr_hashmap, check);
1135
determine_macros(check->all_attrs, check->stack);
1136
1152
fill(path, pathlen, basename_offset, check->stack, check->all_attrs, rem);
1153
}
1154
1139
-int git_check_attr(const char *path, struct attr_check *check)
1155
+int git_check_attr(const struct index_state *istate,
1156
+ const char *path,
1157
+ struct attr_check *check)
1158
{
1159
int i;
1160
1143
- collect_some_attrs(path, check);
1161
+ collect_some_attrs(istate, path, check);
1162
1163
for (i = 0; i < check->nr; i++) {
1164
size_t n = check->items[i].attr->attr_nr;
1171
return 0;
1172
}
1173
1156
-void git_all_attrs(const char *path, struct attr_check *check)
1174
+void git_all_attrs(const struct index_state *istate,
1175
+ const char *path, struct attr_check *check)
1176
{
1177
int i;
1178
1179
attr_check_reset(check);
1161
- collect_some_attrs(path, check);
1180
+ collect_some_attrs(istate, path, check);
1181
1182
for (i = 0; i < check->all_attrs_nr; i++) {
1183
const char *name = check->all_attrs[i].attr->name;