@matheusbsbs / matheus-bagliano / commits / 4191e80a3e
Fork 0

attr: add GIT_ATTR_INDEX "direction"

This instructs attr mechanism, not to look into working .gitattributes at all. Needed by tools that does not handle working directory, such as "git archive". 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 Apr 18, 2009 at 00:17 UTC 4191e80a3e8ee0fa0b8f97f9fba81c3549813fd5
2 files changed +11 -4
attr.c
+9 -3
@@ -405,7 +405,7 @@ static struct attr_stack *read_attr(const char *path, int macro_ok)
405 if (!res)
406 res = read_attr_from_file(path, macro_ok);
407 }
408 - else {
408 + else if (direction == GIT_ATTR_CHECKIN) {
409 res = read_attr_from_file(path, macro_ok);
410 if (!res)
411 /*
@@ -415,6 +415,8 @@ static struct attr_stack *read_attr(const char *path, int macro_ok)
415 */
416 res = read_attr_from_index(path, macro_ok);
417 }
418 + else
419 + res = read_attr_from_index(path, macro_ok);
420 if (!res)
421 res = xcalloc(1, sizeof(*res));
422 return res;
@@ -466,7 +468,7 @@ static void bootstrap_attr_stack(void)
468 elem->prev = attr_stack;
469 attr_stack = elem;
470
469 - if (!is_bare_repository()) {
471 + if (!is_bare_repository() || direction == GIT_ATTR_INDEX) {
472 elem = read_attr(GITATTRIBUTES_FILE, 1);
473 elem->origin = strdup("");
474 elem->prev = attr_stack;
@@ -533,7 +535,7 @@ static void prepare_attr_stack(const char *path, int dirlen)
535 /*
536 * Read from parent directories and push them down
537 */
536 - if (!is_bare_repository()) {
538 + if (!is_bare_repository() || direction == GIT_ATTR_INDEX) {
539 while (1) {
540 char *cp;
541
@@ -674,6 +676,10 @@ int git_checkattr(const char *path, int num, struct git_attr_check *check)
676 void git_attr_set_direction(enum git_attr_direction new, struct index_state *istate)
677 {
678 enum git_attr_direction old = direction;
679 +
680 + if (is_bare_repository() && new != GIT_ATTR_INDEX)
681 + die("BUG: non-INDEX attr direction in a bare repo");
682 +
683 direction = new;
684 if (new != old)
685 drop_attr_stack();
attr.h
+2 -1
@@ -33,7 +33,8 @@ int git_checkattr(const char *path, int, struct git_attr_check *);
33
34 enum git_attr_direction {
35 GIT_ATTR_CHECKIN,
36 - GIT_ATTR_CHECKOUT
36 + GIT_ATTR_CHECKOUT,
37 + GIT_ATTR_INDEX,
38 };
39 void git_attr_set_direction(enum git_attr_direction, struct index_state *);
40