path: root/builtin/check-attr.c
diff options
authorMichael Haggerty <>2011-08-04 04:47:46 (GMT)
committerJunio C Hamano <>2011-08-04 22:57:18 (GMT)
commitf5114a40c0d0276ce6ff215a3dc51eb19da5b420 (patch)
tree7ef4ab2fd35855a58a76f296aa96e3001057321a /builtin/check-attr.c
parent0216af8356ef562147251c40fef72be25b8b9b07 (diff)
git-check-attr: Normalize paths
Normalize the path arguments (relative to the working tree root, if applicable) before looking up their attributes. This requires passing the prefix down the call chain. This fixes two test cases for different reasons: * "unnormalized paths" is fixed because the .gitattribute-file-seeking code is not confused into reading the top-level file twice. * "relative paths" is fixed because the canonical pathnames are passed to get_check_attr() or get_all_attrs(), allowing them to match the pathname patterns as expected. Signed-off-by: Michael Haggerty <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/check-attr.c')
1 files changed, 12 insertions, 8 deletions
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index 6b16368..708988a 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -41,22 +41,26 @@ static void output_attr(int cnt, struct git_attr_check *check,
-static void check_attr(int cnt, struct git_attr_check *check,
- const char *file)
+static void check_attr(const char *prefix, int cnt,
+ struct git_attr_check *check, const char *file)
+ char *full_path =
+ prefix_path(prefix, prefix ? strlen(prefix) : 0, file);
if (check != NULL) {
- if (git_check_attr(file, cnt, check))
+ if (git_check_attr(full_path, cnt, check))
die("git_check_attr died");
output_attr(cnt, check, file);
} else {
- if (git_all_attrs(file, &cnt, &check))
+ if (git_all_attrs(full_path, &cnt, &check))
die("git_all_attrs died");
output_attr(cnt, check, file);
+ free(full_path);
-static void check_attr_stdin_paths(int cnt, struct git_attr_check *check)
+static void check_attr_stdin_paths(const char *prefix, int cnt,
+ struct git_attr_check *check)
struct strbuf buf, nbuf;
int line_termination = null_term_line ? 0 : '\n';
@@ -70,7 +74,7 @@ static void check_attr_stdin_paths(int cnt, struct git_attr_check *check)
die("line is badly quoted");
strbuf_swap(&buf, &nbuf);
- check_attr(cnt, check, buf.buf);
+ check_attr(prefix, cnt, check, buf.buf);
maybe_flush_or_die(stdout, "attribute to stdout");
@@ -154,10 +158,10 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
if (stdin_paths)
- check_attr_stdin_paths(cnt, check);
+ check_attr_stdin_paths(prefix, cnt, check);
else {
for (i = filei; i < argc; i++)
- check_attr(cnt, check, argv[i]);
+ check_attr(prefix, cnt, check, argv[i]);
maybe_flush_or_die(stdout, "attribute to stdout");
return 0;