}
}
-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_checkattr(file, cnt, check))
- die("git_checkattr died");
+ 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(check);
}
+ 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';
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");
}
strbuf_release(&buf);
} else if (doubledash == 0) {
error_with_usage("No attribute specified");
} else if (doubledash < 0) {
- /*
- * There is no double dash; treat the first
- * argument as an attribute.
- */
if (!argc)
error_with_usage("No attribute specified");
- cnt = 1;
- filei = 1;
+ if (stdin_paths) {
+ /* Treat all arguments as attribute names. */
+ cnt = argc;
+ filei = argc;
+ } else {
+ /* Treat exactly one argument as an attribute name. */
+ cnt = 1;
+ filei = 1;
+ }
} else {
cnt = doubledash;
filei = doubledash + 1;
}
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;