Merge branch 'bw/attr'
The gitattributes machinery is being taught to work better in a multi-threaded environment. * bw/attr: (27 commits) attr: reformat git_attr_set_direction() function attr: push the bare repo check into read_attr() attr: store attribute stack in attr_check structure attr: tighten const correctness with git_attr and match_attr attr: remove maybe-real, maybe-macro from git_attr attr: eliminate global check_all_attr array attr: use hashmap for attribute dictionary attr: change validity check for attribute names to use positive logic attr: pass struct attr_check to collect_some_attrs attr: retire git_check_attrs() API attr: convert git_check_attrs() callers to use the new API attr: convert git_all_attrs() to use "struct attr_check" attr: (re)introduce git_check_attr() and struct attr_check attr: rename function and struct related to checking attributes attr.c: outline the future plans by heavily commenting Documentation: fix a typo attr.c: add push_stack() helper attr: support quoting pathname patterns in C style attr.c: plug small leak in parse_attr_line() attr.c: tighten constness around "git_attr" structure ...
This commit is contained in:
@ -24,12 +24,13 @@ static const struct option check_attr_options[] = {
|
||||
OPT_END()
|
||||
};
|
||||
|
||||
static void output_attr(int cnt, struct git_attr_check *check,
|
||||
const char *file)
|
||||
static void output_attr(struct attr_check *check, const char *file)
|
||||
{
|
||||
int j;
|
||||
int cnt = check->nr;
|
||||
|
||||
for (j = 0; j < cnt; j++) {
|
||||
const char *value = check[j].value;
|
||||
const char *value = check->items[j].value;
|
||||
|
||||
if (ATTR_TRUE(value))
|
||||
value = "set";
|
||||
@ -42,35 +43,38 @@ static void output_attr(int cnt, struct git_attr_check *check,
|
||||
printf("%s%c" /* path */
|
||||
"%s%c" /* attrname */
|
||||
"%s%c" /* attrvalue */,
|
||||
file, 0, git_attr_name(check[j].attr), 0, value, 0);
|
||||
file, 0,
|
||||
git_attr_name(check->items[j].attr), 0, value, 0);
|
||||
} else {
|
||||
quote_c_style(file, NULL, stdout, 0);
|
||||
printf(": %s: %s\n", git_attr_name(check[j].attr), value);
|
||||
printf(": %s: %s\n",
|
||||
git_attr_name(check->items[j].attr), value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static void check_attr(const char *prefix, int cnt,
|
||||
struct git_attr_check *check, const char *file)
|
||||
static void check_attr(const char *prefix,
|
||||
struct attr_check *check,
|
||||
int collect_all,
|
||||
const char *file)
|
||||
{
|
||||
char *full_path =
|
||||
prefix_path(prefix, prefix ? strlen(prefix) : 0, file);
|
||||
if (check != NULL) {
|
||||
if (git_check_attr(full_path, cnt, check))
|
||||
die("git_check_attr died");
|
||||
output_attr(cnt, check, file);
|
||||
|
||||
if (collect_all) {
|
||||
git_all_attrs(full_path, check);
|
||||
} else {
|
||||
if (git_all_attrs(full_path, &cnt, &check))
|
||||
die("git_all_attrs died");
|
||||
output_attr(cnt, check, file);
|
||||
free(check);
|
||||
if (git_check_attr(full_path, check))
|
||||
die("git_check_attr died");
|
||||
}
|
||||
output_attr(check, file);
|
||||
|
||||
free(full_path);
|
||||
}
|
||||
|
||||
static void check_attr_stdin_paths(const char *prefix, int cnt,
|
||||
struct git_attr_check *check)
|
||||
static void check_attr_stdin_paths(const char *prefix,
|
||||
struct attr_check *check,
|
||||
int collect_all)
|
||||
{
|
||||
struct strbuf buf = STRBUF_INIT;
|
||||
struct strbuf unquoted = STRBUF_INIT;
|
||||
@ -84,7 +88,7 @@ static void check_attr_stdin_paths(const char *prefix, int cnt,
|
||||
die("line is badly quoted");
|
||||
strbuf_swap(&buf, &unquoted);
|
||||
}
|
||||
check_attr(prefix, cnt, check, buf.buf);
|
||||
check_attr(prefix, check, collect_all, buf.buf);
|
||||
maybe_flush_or_die(stdout, "attribute to stdout");
|
||||
}
|
||||
strbuf_release(&buf);
|
||||
@ -99,7 +103,7 @@ static NORETURN void error_with_usage(const char *msg)
|
||||
|
||||
int cmd_check_attr(int argc, const char **argv, const char *prefix)
|
||||
{
|
||||
struct git_attr_check *check;
|
||||
struct attr_check *check;
|
||||
int cnt, i, doubledash, filei;
|
||||
|
||||
if (!is_bare_repository())
|
||||
@ -159,28 +163,26 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
|
||||
error_with_usage("No file specified");
|
||||
}
|
||||
|
||||
if (all_attrs) {
|
||||
check = NULL;
|
||||
} else {
|
||||
check = xcalloc(cnt, sizeof(*check));
|
||||
check = attr_check_alloc();
|
||||
if (!all_attrs) {
|
||||
for (i = 0; i < cnt; i++) {
|
||||
const char *name;
|
||||
struct git_attr *a;
|
||||
name = argv[i];
|
||||
a = git_attr(name);
|
||||
const struct git_attr *a = git_attr(argv[i]);
|
||||
|
||||
if (!a)
|
||||
return error("%s: not a valid attribute name",
|
||||
name);
|
||||
check[i].attr = a;
|
||||
argv[i]);
|
||||
attr_check_append(check, a);
|
||||
}
|
||||
}
|
||||
|
||||
if (stdin_paths)
|
||||
check_attr_stdin_paths(prefix, cnt, check);
|
||||
check_attr_stdin_paths(prefix, check, all_attrs);
|
||||
else {
|
||||
for (i = filei; i < argc; i++)
|
||||
check_attr(prefix, cnt, check, argv[i]);
|
||||
check_attr(prefix, check, all_attrs, argv[i]);
|
||||
maybe_flush_or_die(stdout, "attribute to stdout");
|
||||
}
|
||||
|
||||
attr_check_free(check);
|
||||
return 0;
|
||||
}
|
||||
|
@ -894,24 +894,15 @@ static void write_pack_file(void)
|
||||
written, nr_result);
|
||||
}
|
||||
|
||||
static void setup_delta_attr_check(struct git_attr_check *check)
|
||||
{
|
||||
static struct git_attr *attr_delta;
|
||||
|
||||
if (!attr_delta)
|
||||
attr_delta = git_attr("delta");
|
||||
|
||||
check[0].attr = attr_delta;
|
||||
}
|
||||
|
||||
static int no_try_delta(const char *path)
|
||||
{
|
||||
struct git_attr_check check[1];
|
||||
static struct attr_check *check;
|
||||
|
||||
setup_delta_attr_check(check);
|
||||
if (git_check_attr(path, ARRAY_SIZE(check), check))
|
||||
if (!check)
|
||||
check = attr_check_initl("delta", NULL);
|
||||
if (git_check_attr(path, check))
|
||||
return 0;
|
||||
if (ATTR_FALSE(check->value))
|
||||
if (ATTR_FALSE(check->items[0].value))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user