unsigned whitespace_rule(const char *pathname) { static struct attr_check *attr_whitespace_rule; const char *value; if (!attr_whitespace_rule) attr_whitespace_rule = attr_check_initl("whitespace", NULL); git_check_attr(&the_index, pathname, attr_whitespace_rule); value = attr_whitespace_rule->items[0].value; if (ATTR_TRUE(value)) { /* true (whitespace) */ unsigned all_rule = ws_tab_width(whitespace_rule_cfg); int i; for (i = 0; i < ARRAY_SIZE(whitespace_rule_names); i++) if (!whitespace_rule_names[i].loosens_error && !whitespace_rule_names[i].exclude_default) all_rule |= whitespace_rule_names[i].rule_bits; return all_rule; } else if (ATTR_FALSE(value)) { /* false (-whitespace) */ return ws_tab_width(whitespace_rule_cfg); } else if (ATTR_UNSET(value)) { /* reset to default (!whitespace) */ return whitespace_rule_cfg; } else { /* string */ return parse_whitespace_rule(value); } }
static int git_path_check_merge(const char *path, struct git_attr_check check[2]) { if (!check[0].attr) { check[0].attr = git_attr("merge"); check[1].attr = git_attr("conflict-marker-size"); } return git_check_attr(path, 2, check); }
static const struct attr_check *get_archive_attrs(struct index_state *istate, const char *path) { static struct attr_check *check; if (!check) check = attr_check_initl("export-ignore", "export-subst", NULL); git_check_attr(istate, path, check); return check; }
int ll_merge_marker_size(const char *path) { static struct git_attr_check check; int marker_size = DEFAULT_CONFLICT_MARKER_SIZE; if (!check.attr) check.attr = git_attr("conflict-marker-size"); if (!git_check_attr(path, 1, &check) && check.value) { marker_size = atoi(check.value); if (marker_size <= 0) marker_size = DEFAULT_CONFLICT_MARKER_SIZE; } return marker_size; }
int ll_merge_marker_size(const char *path) { static struct attr_check *check; int marker_size = DEFAULT_CONFLICT_MARKER_SIZE; if (!check) check = attr_check_initl("conflict-marker-size", NULL); if (!git_check_attr(&the_index, path, check) && check->items[0].value) { marker_size = atoi(check->items[0].value); if (marker_size <= 0) marker_size = DEFAULT_CONFLICT_MARKER_SIZE; } return marker_size; }
static int skip_binary(struct grep_opt *opt, const char *filename) { if ((opt->binary & GREP_BINARY_NOMATCH)) { static struct git_attr *attr_text; struct git_attr_check check; if (!attr_text) attr_text = git_attr("text"); memset(&check, 0, sizeof(check)); check.attr = attr_text; return !git_check_attr(filename, 1, &check) && ATTR_FALSE(check.value); } return 0; }
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(full_path, cnt, check)) die("git_check_attr died"); output_attr(cnt, check, file); } else { 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(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 (collect_all) { git_all_attrs(full_path, check); } else { if (git_check_attr(full_path, check)) die("git_check_attr died"); } output_attr(check, file); free(full_path); }
int ll_merge(mmbuffer_t *result_buf, const char *path, mmfile_t *ancestor, const char *ancestor_label, mmfile_t *ours, const char *our_label, mmfile_t *theirs, const char *their_label, const struct ll_merge_options *opts) { static struct attr_check *check; static const struct ll_merge_options default_opts; const char *ll_driver_name = NULL; int marker_size = DEFAULT_CONFLICT_MARKER_SIZE; const struct ll_merge_driver *driver; if (!opts) opts = &default_opts; if (opts->renormalize) { normalize_file(ancestor, path); normalize_file(ours, path); normalize_file(theirs, path); } if (!check) check = attr_check_initl("merge", "conflict-marker-size", NULL); if (!git_check_attr(&the_index, path, check)) { ll_driver_name = check->items[0].value; if (check->items[1].value) { marker_size = atoi(check->items[1].value); if (marker_size <= 0) marker_size = DEFAULT_CONFLICT_MARKER_SIZE; } } driver = find_ll_merge_driver(ll_driver_name); if (opts->virtual_ancestor) { if (driver->recursive) driver = find_ll_merge_driver(driver->recursive); marker_size += 2; } return driver->fn(driver, result_buf, path, ancestor, ancestor_label, ours, our_label, theirs, their_label, opts, marker_size); }
struct userdiff_driver *userdiff_find_by_path(struct index_state *istate, const char *path) { static struct attr_check *check; if (!check) check = attr_check_initl("diff", NULL); if (!path) return NULL; git_check_attr(istate, path, check); if (ATTR_TRUE(check->items[0].value)) return &driver_true; if (ATTR_FALSE(check->items[0].value)) return &driver_false; if (ATTR_UNSET(check->items[0].value)) return NULL; return userdiff_find_by_name(check->items[0].value); }
static int write_archive_entry(const unsigned char *sha1, const char *base, int baselen, const char *filename, unsigned mode, int stage, void *context) { static struct strbuf path = STRBUF_INIT; struct archiver_context *c = context; struct archiver_args *args = c->args; write_archive_entry_fn_t write_entry = c->write_entry; struct git_attr_check check[2]; const char *path_without_prefix; int err; args->convert = 0; strbuf_reset(&path); strbuf_grow(&path, PATH_MAX); strbuf_add(&path, args->base, args->baselen); strbuf_add(&path, base, baselen); strbuf_addstr(&path, filename); if (S_ISDIR(mode) || S_ISGITLINK(mode)) strbuf_addch(&path, '/'); path_without_prefix = path.buf + args->baselen; setup_archive_check(check); if (!git_check_attr(path_without_prefix, ARRAY_SIZE(check), check)) { if (ATTR_TRUE(check[0].value)) return 0; args->convert = ATTR_TRUE(check[1].value); } if (S_ISDIR(mode) || S_ISGITLINK(mode)) { if (args->verbose) fprintf(stderr, "%.*s\n", (int)path.len, path.buf); err = write_entry(args, sha1, path.buf, path.len, mode); if (err) return err; return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0); } if (args->verbose) fprintf(stderr, "%.*s\n", (int)path.len, path.buf); return write_entry(args, sha1, path.buf, path.len, mode); }
struct userdiff_driver *userdiff_find_by_path(const char *path) { static struct git_attr *attr; struct git_attr_check check; if (!attr) attr = git_attr("diff"); check.attr = attr; if (!path) return NULL; if (git_check_attr(path, 1, &check)) return NULL; if (ATTR_TRUE(check.value)) return &driver_true; if (ATTR_FALSE(check.value)) return &driver_false; if (ATTR_UNSET(check.value)) return NULL; return userdiff_find_by_name(check.value); }