Merge branch 'jc/attr-source-tree'

"git --attr-source=<tree> cmd $args" is a new way to have any
command to read attributes not from the working tree but from the
given tree object.

* jc/attr-source-tree:
  attr: teach "--attr-source=<tree>" global option to "git"
This commit is contained in:
Junio C Hamano
2023-05-17 10:11:41 -07:00
16 changed files with 140 additions and 29 deletions

View File

@ -64,7 +64,7 @@ static void output_attr(struct attr_check *check, const char *file)
}
static void check_attr(const char *prefix, struct attr_check *check,
const struct object_id *tree_oid, int collect_all,
int collect_all,
const char *file)
{
@ -72,9 +72,9 @@ static void check_attr(const char *prefix, struct attr_check *check,
prefix_path(prefix, prefix ? strlen(prefix) : 0, file);
if (collect_all) {
git_all_attrs(&the_index, tree_oid, full_path, check);
git_all_attrs(&the_index, full_path, check);
} else {
git_check_attr(&the_index, tree_oid, full_path, check);
git_check_attr(&the_index, full_path, check);
}
output_attr(check, file);
@ -82,7 +82,7 @@ static void check_attr(const char *prefix, struct attr_check *check,
}
static void check_attr_stdin_paths(const char *prefix, struct attr_check *check,
const struct object_id *tree_oid, int collect_all)
int collect_all)
{
struct strbuf buf = STRBUF_INIT;
struct strbuf unquoted = STRBUF_INIT;
@ -96,7 +96,7 @@ static void check_attr_stdin_paths(const char *prefix, struct attr_check *check,
die("line is badly quoted");
strbuf_swap(&buf, &unquoted);
}
check_attr(prefix, check, tree_oid, collect_all, buf.buf);
check_attr(prefix, check, collect_all, buf.buf);
maybe_flush_or_die(stdout, "attribute to stdout");
}
strbuf_release(&buf);
@ -112,7 +112,6 @@ static NORETURN void error_with_usage(const char *msg)
int cmd_check_attr(int argc, const char **argv, const char *prefix)
{
struct attr_check *check;
struct object_id *tree_oid = NULL;
struct object_id initialized_oid;
int cnt, i, doubledash, filei;
@ -188,14 +187,14 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
if (source) {
if (repo_get_oid_tree(the_repository, source, &initialized_oid))
die("%s: not a valid tree-ish source", source);
tree_oid = &initialized_oid;
set_git_attr_source(source);
}
if (stdin_paths)
check_attr_stdin_paths(prefix, check, tree_oid, all_attrs);
check_attr_stdin_paths(prefix, check, all_attrs);
else {
for (i = filei; i < argc; i++)
check_attr(prefix, check, tree_oid, all_attrs, argv[i]);
check_attr(prefix, check, all_attrs, argv[i]);
maybe_flush_or_die(stdout, "attribute to stdout");
}