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 <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Aug 4, 2011 at 06:47 UTC
f5114a40c0d0276ce6ff215a3dc51eb19da5b420
2 files changed
+14
-10
builtin/check-attr.c
+12
-8
@@ -41,22 +41,26 @@ static void output_attr(int cnt, struct git_attr_check *check,
41
}
42
}
43
44
-static void check_attr(int cnt, struct git_attr_check *check,
45
- const char *file)
44
+static void check_attr(const char *prefix, int cnt,
45
+ struct git_attr_check *check, const char *file)
46
{
47
+ char *full_path =
48
+ prefix_path(prefix, prefix ? strlen(prefix) : 0, file);
49
if (check != NULL) {
48
- if (git_check_attr(file, cnt, check))
50
+ if (git_check_attr(full_path, cnt, check))
51
die("git_check_attr died");
52
output_attr(cnt, check, file);
53
} else {
52
- if (git_all_attrs(file, &cnt, &check))
54
+ if (git_all_attrs(full_path, &cnt, &check))
55
die("git_all_attrs died");
56
output_attr(cnt, check, file);
57
free(check);
58
}
59
+ free(full_path);
60
}
61
59
-static void check_attr_stdin_paths(int cnt, struct git_attr_check *check)
62
+static void check_attr_stdin_paths(const char *prefix, int cnt,
63
+ struct git_attr_check *check)
64
{
65
struct strbuf buf, nbuf;
66
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)
74
die("line is badly quoted");
75
strbuf_swap(&buf, &nbuf);
76
}
73
- check_attr(cnt, check, buf.buf);
77
+ check_attr(prefix, cnt, check, buf.buf);
78
maybe_flush_or_die(stdout, "attribute to stdout");
79
}
80
strbuf_release(&buf);
@@ -154,10 +158,10 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
158
}
159
160
if (stdin_paths)
157
- check_attr_stdin_paths(cnt, check);
161
+ check_attr_stdin_paths(prefix, cnt, check);
162
else {
163
for (i = filei; i < argc; i++)
160
- check_attr(cnt, check, argv[i]);
164
+ check_attr(prefix, cnt, check, argv[i]);
165
maybe_flush_or_die(stdout, "attribute to stdout");
166
}
167
return 0;
t/t0003-attributes.sh
+2
-2
@@ -93,7 +93,7 @@ test_expect_success 'attribute test' '
93
94
'
95
96
-test_expect_failure 'unnormalized paths' '
96
+test_expect_success 'unnormalized paths' '
97
98
attr_check ./f f &&
99
attr_check ./a/g a/g &&
@@ -102,7 +102,7 @@ test_expect_failure 'unnormalized paths' '
102
103
'
104
105
-test_expect_failure 'relative paths' '
105
+test_expect_success 'relative paths' '
106
107
(cd a && attr_check ../f f) &&
108
(cd a && attr_check f f) &&