git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] Attr: Allow macros to override earlier attributes.

From
Henrik Grubbström (Grubba) <grubba@grubba.org>
Date
Apr 2, 2010, 13:53 UTC
Message-ID
<f02815e3761a8050aa76f46cd19288e72da14206.1270216006.git.grubba@grubba.org>
In-Reply-To
<ca1f7f974d72a036dd8369309d487bbd047a8e2d.1270216006.git.grubba@grubba.org>

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(-)
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
Previous: Henrik Grubbström (Grubba)Next: Henrik Grubbström
Message 2 of 3 in “Attr: Fixed debug output for macro expansion.”
  1. 1/2 Attr: Fixed debug output for macro expansion.Henrik Grubbström (Grubba), Apr 2, 2010
  2. 2/2 Attr: Allow macros to override earlier attributes.Henrik Grubbström (Grubba), Apr 2, 2010
  3. Henrik GrubbströmApr 2, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.