threads / patch / 23302

patch, 2 partsAttr: Fixed debug output for macro expansion.

Subject: [PATCH 1/2] Attr: Fixed debug output for macro expansion.

## tl;dr

3 messages between Apr 2, 2010 and Apr 2, 2010. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Henrik Grubbström (Grubba)· Apr 2, 2010, 13:53 UTC · lore

When debug_set() was called during macro expansion, it received a pointer to a struct git_attr rather than a string.

Signed-off-by: Henrik Grubbström <grubba@grubba.org>
---
 attr.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
Show changes to attr.c +3 −1
diff --git a/attr.c b/attr.c
index f5346ed..5c6464e 100644
--- a/attr.c
+++ b/attr.c
@@ -605,7 +605,9 @@ static int fill_one(const char *what, struct match_attr *a, int rem)
 		const char *v = a->state[i].setto;
 
 		if (*n == ATTR__UNKNOWN) {
-			debug_set(what, a->u.pattern, attr, v);
+			debug_set(what,
+				  a->is_macro?a->u.attr->name:a->u.pattern,
+				  attr, v);
 			*n = v;
 			rem--;
 		}
-- 
1.7.0.3.316.g33b5e
Henrik Grubbström (Grubba)· Apr 2, 2010, 13:53 UTC · re: Henrik Grubbström (Grubba) · lore

[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
Henrik Grubbström· Apr 2, 2010, 19:23 UTC · re: Henrik Grubbström (Grubba) · lore

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

On Fri, 2 Apr 2010, Henrik Grubbström (Grubba) wrote:
Show 8 quoted lines
> 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.

On closer thought, the approach taken by this patch wasn't a good idea, since it doesn't handle the case:

bar.bin		mybinary ident

-- Henrik Grubbström grubba@roxen.com Roxen Internet Software AB

← back to recent threads