Skip to content

Commit 4191e80

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent ad94657 commit 4191e80

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

attr.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ static struct attr_stack *read_attr(const char *path, int macro_ok)
405405
if (!res)
406406
res = read_attr_from_file(path, macro_ok);
407407
}
408-
else {
408+
else if (direction == GIT_ATTR_CHECKIN) {
409409
res = read_attr_from_file(path, macro_ok);
410410
if (!res)
411411
/*
@@ -415,6 +415,8 @@ static struct attr_stack *read_attr(const char *path, int macro_ok)
415415
*/
416416
res = read_attr_from_index(path, macro_ok);
417417
}
418+
else
419+
res = read_attr_from_index(path, macro_ok);
418420
if (!res)
419421
res = xcalloc(1, sizeof(*res));
420422
return res;
@@ -466,7 +468,7 @@ static void bootstrap_attr_stack(void)
466468
elem->prev = attr_stack;
467469
attr_stack = elem;
468470

469-
if (!is_bare_repository()) {
471+
if (!is_bare_repository() || direction == GIT_ATTR_INDEX) {
470472
elem = read_attr(GITATTRIBUTES_FILE, 1);
471473
elem->origin = strdup("");
472474
elem->prev = attr_stack;
@@ -533,7 +535,7 @@ static void prepare_attr_stack(const char *path, int dirlen)
533535
/*
534536
* Read from parent directories and push them down
535537
*/
536-
if (!is_bare_repository()) {
538+
if (!is_bare_repository() || direction == GIT_ATTR_INDEX) {
537539
while (1) {
538540
char *cp;
539541

@@ -674,6 +676,10 @@ int git_checkattr(const char *path, int num, struct git_attr_check *check)
674676
void git_attr_set_direction(enum git_attr_direction new, struct index_state *istate)
675677
{
676678
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+
677683
direction = new;
678684
if (new != old)
679685
drop_attr_stack();

attr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ int git_checkattr(const char *path, int, struct git_attr_check *);
3333

3434
enum git_attr_direction {
3535
GIT_ATTR_CHECKIN,
36-
GIT_ATTR_CHECKOUT
36+
GIT_ATTR_CHECKOUT,
37+
GIT_ATTR_INDEX,
3738
};
3839
void git_attr_set_direction(enum git_attr_direction, struct index_state *);
3940

0 commit comments

Comments
 (0)