[PATCH 2/2] Attr: Allow macros to override earlier attributes.
Macros need to be able to override earlier attribute values. Consider a .gitattributes file with the following content:
[attr]mybinary binary -ident * ident foo.bin mybinary
Without this patch foo.bin will still have the ident attribute set.
Signed-off-by: Henrik Grubbström <grubba@grubba.org>
---
attr.c | 8 ++++----
t/t0003-attributes.sh | 6 ++++++
2 files changed, 10 insertions(+), 4 deletions(-)
Show changes to 2 files +10 −4
attr.c, t/t0003-attributes.sh
diff --git a/attr.c b/attr.c
index 5c6464e..4d7ff02 100644
--- a/attr.c
+++ b/attr.c
@@ -594,7 +594,7 @@ static int path_matches(const char *pathname, int pathlen,
return fnmatch(pattern, pathname + baselen, FNM_PATHNAME) == 0;
}
-static int fill_one(const char *what, struct match_attr *a, int rem)
+static int fill_one(const char *what, struct match_attr *a, int rem, int force)
{
struct git_attr_check *check = check_all_attr;
int i;
@@ -604,7 +604,7 @@ static int fill_one(const char *what, struct match_attr *a, int rem)
const char **n = &(check[attr->attr_nr].value);
const char *v = a->state[i].setto;
- if (*n == ATTR__UNKNOWN) {
+ if (force || *n == ATTR__UNKNOWN) {
debug_set(what,
a->is_macro?a->u.attr->name:a->u.pattern,
attr, v);
@@ -626,7 +626,7 @@ static int fill(const char *path, int pathlen, struct attr_stack *stk, int rem)
continue;
if (path_matches(path, pathlen,
a->u.pattern, base, strlen(base)))
- rem = fill_one("fill", a, rem);
+ rem = fill_one("fill", a, rem, 0);
}
return rem;
}
@@ -642,7 +642,7 @@ static int macroexpand(struct attr_stack *stk, int rem)
continue;
if (check[a->u.attr->attr_nr].value != ATTR__TRUE)
continue;
- rem = fill_one("expand", a, rem);
+ rem = fill_one("expand", a, rem, 1);
}
return rem;
}
diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh
index 1c77192..f8bc43b 100755
--- a/t/t0003-attributes.sh
+++ b/t/t0003-attributes.sh
@@ -20,8 +20,10 @@ test_expect_success 'setup' '
mkdir -p a/b/d a/c &&
(
+ echo "[attr]notest !test"
echo "f test=f"
echo "a/i test=a/i"
+ echo "no notest"
) >.gitattributes &&
(
echo "g test=a/g" &&
@@ -44,6 +46,8 @@ test_expect_success 'attribute test' '
attr_check b/g unspecified &&
attr_check a/b/h a/b/h &&
attr_check a/b/d/g "a/b/d/*"
+ attr_check no unspecified
+ attr_check a/b/d/no unspecified
'
@@ -58,6 +62,8 @@ a/b/g: test: a/b/g
b/g: test: unspecified
a/b/h: test: a/b/h
a/b/d/g: test: a/b/d/*
+no: test: unspecified
+a/b/d/no: test: unspecified
EOF
sed -e "s/:.*//" < expect | git check-attr --stdin test > actual &&
--
1.7.0.3.316.g33b5e