Esempio n. 1
0
File: ws.c Progetto: astubbs/git
unsigned whitespace_rule(const char *pathname)
{
	struct git_attr_check attr_whitespace_rule;

	setup_whitespace_attr_check(&attr_whitespace_rule);
	if (!git_checkattr(pathname, 1, &attr_whitespace_rule)) {
		const char *value;

		value = attr_whitespace_rule.value;
		if (ATTR_TRUE(value)) {
			/* true (whitespace) */
			unsigned all_rule = 0;
			int i;
			for (i = 0; i < ARRAY_SIZE(whitespace_rule_names); i++)
				if (!whitespace_rule_names[i].loosens_error)
					all_rule |= whitespace_rule_names[i].rule_bits;
			return all_rule;
		} else if (ATTR_FALSE(value)) {
			/* false (-whitespace) */
			return 0;
		} else if (ATTR_UNSET(value)) {
			/* reset to default (!whitespace) */
			return whitespace_rule_cfg;
		} else {
			/* string */
			return parse_whitespace_rule(value);
		}
	} else {
		return whitespace_rule_cfg;
	}
}
Esempio n. 2
0
File: ll-merge.c Progetto: qmx/git
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_checkattr(path, 2, check);
}
Esempio n. 3
0
static const char *git_path_check_merge(const char *path)
{
	static struct git_attr_check attr_merge_check;

	if (!attr_merge_check.attr)
		attr_merge_check.attr = git_attr("merge", 5);

	if (git_checkattr(path, 1, &attr_merge_check))
		return NULL;
	return attr_merge_check.value;
}
Esempio n. 4
0
File: archive.c Progetto: Jinyan/git
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 convert = 0;
	int err;
	enum object_type type;
	unsigned long size;
	void *buffer;

	strbuf_reset(&path);
	strbuf_grow(&path, PATH_MAX);
	strbuf_add(&path, args->base, args->baselen);
	strbuf_add(&path, base, baselen);
	strbuf_addstr(&path, filename);
	path_without_prefix = path.buf + args->baselen;

	setup_archive_check(check);
	if (!git_checkattr(path_without_prefix, ARRAY_SIZE(check), check)) {
		if (ATTR_TRUE(check[0].value))
			return 0;
		convert = ATTR_TRUE(check[1].value);
	}

	if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
		strbuf_addch(&path, '/');
		if (args->verbose)
			fprintf(stderr, "%.*s\n", (int)path.len, path.buf);
		err = write_entry(args, sha1, path.buf, path.len, mode, NULL, 0);
		if (err)
			return err;
		return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
	}

	buffer = sha1_file_to_archive(path_without_prefix, sha1, mode,
			&type, &size, convert ? args->commit : NULL);
	if (!buffer)
		return error("cannot read %s", sha1_to_hex(sha1));
	if (args->verbose)
		fprintf(stderr, "%.*s\n", (int)path.len, path.buf);
	err = write_entry(args, sha1, path.buf, path.len, mode, buffer, size);
	free(buffer);
	return err;
}
Esempio n. 5
0
File: ll-merge.c Progetto: qmx/git
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_checkattr(path, 1, &check) && check.value) {
        marker_size = atoi(check.value);
        if (marker_size <= 0)
            marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
    }
    return marker_size;
}
Esempio n. 6
0
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_checkattr(filename, 1, &check) &&
				ATTR_FALSE(check.value);
	}
	return 0;
}
Esempio n. 7
0
static void check_attr(int cnt, struct git_attr_check *check,
	const char** name, const char *file)
{
	int j;
	if (git_checkattr(file, cnt, check))
		die("git_checkattr died");
	for (j = 0; j < cnt; j++) {
		const char *value = check[j].value;

		if (ATTR_TRUE(value))
			value = "set";
		else if (ATTR_FALSE(value))
			value = "unset";
		else if (ATTR_UNSET(value))
			value = "unspecified";

		quote_c_style(file, NULL, stdout, 0);
		printf(": %s: %s\n", name[j], value);
	}
}
Esempio n. 8
0
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_checkattr(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);
}
Esempio n. 9
0
static int convert_to_archive(const char *path,
                              const void *src, size_t len,
                              struct strbuf *buf,
                              const struct commit *commit)
{
	static struct git_attr *attr_export_subst;
	struct git_attr_check check[1];

	if (!commit)
		return 0;

	if (!attr_export_subst)
		attr_export_subst = git_attr("export-subst", 12);

	check[0].attr = attr_export_subst;
	if (git_checkattr(path, ARRAY_SIZE(check), check))
		return 0;
	if (!ATTR_TRUE(check[0].value))
		return 0;

	format_subst(commit, src, len, buf);
	return 1;
}