示例#1
0
文件: repo.c 项目: ralpheav/PM_GIT
void test_attr_repo__get_many(void)
{
	const char *names[4] = { "repoattr", "rootattr", "missingattr", "subattr" };
	const char *values[4];

	cl_git_pass(git_attr_get_many(values, g_repo, 0, "root_test1", 4, names));

	cl_assert(GIT_ATTR_TRUE(values[0]));
	cl_assert(GIT_ATTR_TRUE(values[1]));
	cl_assert(GIT_ATTR_UNSPECIFIED(values[2]));
	cl_assert(GIT_ATTR_UNSPECIFIED(values[3]));

	cl_git_pass(git_attr_get_many(values, g_repo, 0, "root_test2", 4, names));

	cl_assert(GIT_ATTR_TRUE(values[0]));
	cl_assert(GIT_ATTR_FALSE(values[1]));
	cl_assert(GIT_ATTR_UNSPECIFIED(values[2]));
	cl_assert(GIT_ATTR_UNSPECIFIED(values[3]));

	cl_git_pass(git_attr_get_many(values, g_repo, 0, "sub/subdir_test1", 4, names));

	cl_assert(GIT_ATTR_TRUE(values[0]));
	cl_assert(GIT_ATTR_TRUE(values[1]));
	cl_assert(GIT_ATTR_UNSPECIFIED(values[2]));
	cl_assert_equal_s("yes", values[3]);
}
示例#2
0
文件: repo.c 项目: ralpheav/PM_GIT
void test_attr_repo__macros(void)
{
	const char *names[5] = { "rootattr", "binary", "diff", "crlf", "frotz" };
	const char *names2[5] = { "mymacro", "positive", "negative", "rootattr", "another" };
	const char *names3[3] = { "macro2", "multi2", "multi3" };
	const char *values[5];

	cl_git_pass(git_attr_get_many(values, g_repo, 0, "binfile", 5, names));

	cl_assert(GIT_ATTR_TRUE(values[0]));
	cl_assert(GIT_ATTR_TRUE(values[1]));
	cl_assert(GIT_ATTR_FALSE(values[2]));
	cl_assert(GIT_ATTR_FALSE(values[3]));
	cl_assert(GIT_ATTR_UNSPECIFIED(values[4]));

	cl_git_pass(git_attr_get_many(values, g_repo, 0, "macro_test", 5, names2));

	cl_assert(GIT_ATTR_TRUE(values[0]));
	cl_assert(GIT_ATTR_TRUE(values[1]));
	cl_assert(GIT_ATTR_FALSE(values[2]));
	cl_assert(GIT_ATTR_UNSPECIFIED(values[3]));
	cl_assert_equal_s("77", values[4]);

	cl_git_pass(git_attr_get_many(values, g_repo, 0, "macro_test", 3, names3));

	cl_assert(GIT_ATTR_TRUE(values[0]));
	cl_assert(GIT_ATTR_FALSE(values[1]));
	cl_assert_equal_s("answer", values[2]);
}
示例#3
0
文件: repo.c 项目: brodie/libgit2
void test_attr_repo__get_many_in_place(void)
{
    const char *vals[4] = { "repoattr", "rootattr", "missingattr", "subattr" };

    /* it should be legal to look up values into the same array that has
     * the attribute names, overwriting each name as the value is found.
     */

    cl_git_pass(git_attr_get_many(vals, g_repo, 0, "sub/subdir_test1", 4, vals));

    cl_assert(GIT_ATTR_TRUE(vals[0]));
    cl_assert(GIT_ATTR_TRUE(vals[1]));
    cl_assert(GIT_ATTR_UNSPECIFIED(vals[2]));
    cl_assert_equal_s("yes", vals[3]);
}
示例#4
0
static int filter_check(
	git_filter				*self,
	void					**payload, /* points to NULL ptr on entry, may be set */
	const git_filter_source	*src,
	const char				**attr_values)
{
	GIT_UNUSED(self);
	GIT_UNUSED(src);

	if (GIT_ATTR_UNSPECIFIED(attr_values[0]))
		return GIT_PASSTHROUGH;

	if (GIT_ATTR_FALSE(attr_values[0]))
		return GIT_PASSTHROUGH;

	if (GIT_ATTR_TRUE(attr_values[0]))
		return GIT_PASSTHROUGH;
	
	*payload = git__strdup(attr_values[0]);
	if (!*payload)
	{
		giterr_set_oom();
		return -1;
	}

	return 0;
}
示例#5
0
int git_diff_driver_lookup(
	git_diff_driver **out, git_repository *repo, const char *path)
{
	int error = 0;
	const char *value;

	assert(out);
	*out = NULL;

	if (!repo || !path || !strlen(path))
		/* just use the auto value */;
	else if ((error = git_attr_get(&value, repo, 0, path, "diff")) < 0)
		/* return error below */;
	else if (GIT_ATTR_UNSPECIFIED(value))
		/* just use the auto value */;
	else if (GIT_ATTR_FALSE(value))
		*out = &global_drivers[DIFF_DRIVER_BINARY];
	else if (GIT_ATTR_TRUE(value))
		*out = &global_drivers[DIFF_DRIVER_TEXT];

	/* otherwise look for driver information in config and build driver */
	else if ((error = git_diff_driver_load(out, repo, value)) < 0) {
		if (error == GIT_ENOTFOUND) {
			error = 0;
			giterr_clear();
		}
	}

	if (!*out)
		*out = &global_drivers[DIFF_DRIVER_AUTO];

	return error;
}
示例#6
0
文件: file.c 项目: Asquera/libgit2
void test_attr_file__simple_read(void)
{
	git_attr_file *file;
	git_attr_assignment *assign;
	git_attr_rule *rule;

	cl_git_pass(git_attr_file__new_and_load(&file, cl_fixture("attr/attr0")));

	cl_assert_equal_s(cl_fixture("attr/attr0"), file->key + 2);
	cl_assert(file->rules.length == 1);

	rule = get_rule(0);
	cl_assert(rule != NULL);
	cl_assert_equal_s("*", rule->match.pattern);
	cl_assert(rule->match.length == 1);
	cl_assert((rule->match.flags & GIT_ATTR_FNMATCH_HASWILD) != 0);

	cl_assert(rule->assigns.length == 1);
	assign = get_assign(rule, 0);
	cl_assert(assign != NULL);
	cl_assert_equal_s("binary", assign->name);
	cl_assert(GIT_ATTR_TRUE(assign->value));

	git_attr_file__free(file);
}
示例#7
0
文件: repo.c 项目: brodie/libgit2
void test_attr_repo__bad_macros(void)
{
    const char *names[6] = { "rootattr", "positive", "negative",
                             "firstmacro", "secondmacro", "thirdmacro"
                           };
    const char *values[6];

    cl_git_pass(git_attr_get_many(values, g_repo, 0, "macro_bad", 6, names));

    /* these three just confirm that the "mymacro" rule ran */
    cl_assert(GIT_ATTR_UNSPECIFIED(values[0]));
    cl_assert(GIT_ATTR_TRUE(values[1]));
    cl_assert(GIT_ATTR_FALSE(values[2]));

    /* file contains:
     *     # let's try some malicious macro defs
     *     [attr]firstmacro -thirdmacro -secondmacro
     *     [attr]secondmacro firstmacro -firstmacro
     *     [attr]thirdmacro secondmacro=hahaha -firstmacro
     *     macro_bad firstmacro secondmacro thirdmacro
     *
     * firstmacro assignment list ends up with:
     *     -thirdmacro -secondmacro
     * secondmacro assignment list expands "firstmacro" and ends up with:
     *     -thirdmacro -secondmacro -firstmacro
     * thirdmacro assignment don't expand so list ends up with:
     *     secondmacro="hahaha"
     *
     * macro_bad assignment list ends up with:
     *     -thirdmacro -secondmacro firstmacro &&
     *     -thirdmacro -secondmacro -firstmacro secondmacro &&
     *     secondmacro="hahaha" thirdmacro
     *
     * so summary results should be:
     *     -firstmacro secondmacro="hahaha" thirdmacro
     */
    cl_assert(GIT_ATTR_FALSE(values[3]));
    cl_assert_equal_s("hahaha", values[4]);
    cl_assert(GIT_ATTR_TRUE(values[5]));
}
示例#8
0
文件: crlf.c 项目: Study-C/libgit2
static int check_crlf(const char *value)
{
	if (GIT_ATTR_TRUE(value))
		return GIT_CRLF_TEXT;

	if (GIT_ATTR_FALSE(value))
		return GIT_CRLF_BINARY;

	if (GIT_ATTR_UNSPECIFIED(value))
		return GIT_CRLF_GUESS;

	if (strcmp(value, "input") == 0)
		return GIT_CRLF_INPUT;

	if (strcmp(value, "auto") == 0)
		return GIT_CRLF_AUTO;

	return GIT_CRLF_GUESS;
}
示例#9
0
文件: repo.c 项目: ralpheav/PM_GIT
void test_attr_repo__manpage_example(void)
{
	const char *value;

	cl_git_pass(git_attr_get(&value, g_repo, 0, "sub/abc", "foo"));
	cl_assert(GIT_ATTR_TRUE(value));

	cl_git_pass(git_attr_get(&value, g_repo, 0, "sub/abc", "bar"));
	cl_assert(GIT_ATTR_UNSPECIFIED(value));

	cl_git_pass(git_attr_get(&value, g_repo, 0, "sub/abc", "baz"));
	cl_assert(GIT_ATTR_FALSE(value));

	cl_git_pass(git_attr_get(&value, g_repo, 0, "sub/abc", "merge"));
	cl_assert_equal_s("filfre", value);

	cl_git_pass(git_attr_get(&value, g_repo, 0, "sub/abc", "frotz"));
	cl_assert(GIT_ATTR_UNSPECIFIED(value));
}
示例#10
0
文件: file.c 项目: Asquera/libgit2
void test_attr_file__check_attr_examples(void)
{
	git_attr_file *file;
	git_attr_rule *rule;
	git_attr_assignment *assign;

	cl_git_pass(git_attr_file__new_and_load(&file, cl_fixture("attr/attr3")));
	cl_assert_equal_s(cl_fixture("attr/attr3"), file->key + 2);
	cl_assert(file->rules.length == 3);

	rule = get_rule(0);
	cl_assert_equal_s("*.java", rule->match.pattern);
	cl_assert(rule->assigns.length == 3);
	assign = git_attr_rule__lookup_assignment(rule, "diff");
	cl_assert_equal_s("diff", assign->name);
	cl_assert_equal_s("java", assign->value);
	assign = git_attr_rule__lookup_assignment(rule, "crlf");
	cl_assert_equal_s("crlf", assign->name);
	cl_assert(GIT_ATTR_FALSE(assign->value));
	assign = git_attr_rule__lookup_assignment(rule, "myAttr");
	cl_assert_equal_s("myAttr", assign->name);
	cl_assert(GIT_ATTR_TRUE(assign->value));
	assign = git_attr_rule__lookup_assignment(rule, "missing");
	cl_assert(assign == NULL);

	rule = get_rule(1);
	cl_assert_equal_s("NoMyAttr.java", rule->match.pattern);
	cl_assert(rule->assigns.length == 1);
	assign = get_assign(rule, 0);
	cl_assert_equal_s("myAttr", assign->name);
	cl_assert(GIT_ATTR_UNSPECIFIED(assign->value));

	rule = get_rule(2);
	cl_assert_equal_s("README", rule->match.pattern);
	cl_assert(rule->assigns.length == 1);
	assign = get_assign(rule, 0);
	cl_assert_equal_s("caveat", assign->name);
	cl_assert_equal_s("unspecified", assign->value);

	git_attr_file__free(file);
}
示例#11
0
文件: file.c 项目: Asquera/libgit2
void test_attr_file__match_variants(void)
{
	git_attr_file *file;
	git_attr_rule *rule;
	git_attr_assignment *assign;

	cl_git_pass(git_attr_file__new_and_load(&file, cl_fixture("attr/attr1")));

	cl_assert_equal_s(cl_fixture("attr/attr1"), file->key + 2);
	cl_assert(file->rules.length == 10);

	/* let's do a thorough check of this rule, then just verify
	 * the things that are unique for the later rules
	 */
	rule = get_rule(0);
	cl_assert(rule);
	cl_assert_equal_s("pat0", rule->match.pattern);
	cl_assert(rule->match.length == strlen("pat0"));
	cl_assert(rule->match.flags == 0);
	cl_assert(rule->assigns.length == 1);
	assign = get_assign(rule,0);
	cl_assert_equal_s("attr0", assign->name);
	cl_assert(assign->name_hash == git_attr_file__name_hash(assign->name));
	cl_assert(GIT_ATTR_TRUE(assign->value));

	rule = get_rule(1);
	cl_assert_equal_s("pat1", rule->match.pattern);
	cl_assert(rule->match.length == strlen("pat1"));
	cl_assert(rule->match.flags == GIT_ATTR_FNMATCH_NEGATIVE);

	rule = get_rule(2);
	cl_assert_equal_s("pat2", rule->match.pattern);
	cl_assert(rule->match.length == strlen("pat2"));
	cl_assert(rule->match.flags == GIT_ATTR_FNMATCH_DIRECTORY);

	rule = get_rule(3);
	cl_assert_equal_s("pat3dir/pat3file", rule->match.pattern);
	cl_assert(rule->match.flags == GIT_ATTR_FNMATCH_FULLPATH);

	rule = get_rule(4);
	cl_assert_equal_s("pat4.*", rule->match.pattern);
	cl_assert((rule->match.flags & GIT_ATTR_FNMATCH_HASWILD) != 0);

	rule = get_rule(5);
	cl_assert_equal_s("*.pat5", rule->match.pattern);
	cl_assert((rule->match.flags & GIT_ATTR_FNMATCH_HASWILD) != 0);

	rule = get_rule(7);
	cl_assert_equal_s("pat7[a-e]??[xyz]", rule->match.pattern);
	cl_assert(rule->assigns.length == 1);
	cl_assert((rule->match.flags & GIT_ATTR_FNMATCH_HASWILD) != 0);
	assign = get_assign(rule,0);
	cl_assert_equal_s("attr7", assign->name);
	cl_assert(GIT_ATTR_TRUE(assign->value));

	rule = get_rule(8);
	cl_assert_equal_s("pat8 with spaces", rule->match.pattern);
	cl_assert(rule->match.length == strlen("pat8 with spaces"));
	cl_assert(rule->match.flags == 0);

	rule = get_rule(9);
	cl_assert_equal_s("pat9", rule->match.pattern);

	git_attr_file__free(file);
}
示例#12
0
文件: file.c 项目: Asquera/libgit2
void test_attr_file__assign_variants(void)
{
	git_attr_file *file;
	git_attr_rule *rule;
	git_attr_assignment *assign;

	cl_git_pass(git_attr_file__new_and_load(&file, cl_fixture("attr/attr2")));

	cl_assert_equal_s(cl_fixture("attr/attr2"), file->key + 2);
	cl_assert(file->rules.length == 11);

	check_one_assign(file, 0, 0, "pat0", "simple", EXPECT_TRUE, NULL);
	check_one_assign(file, 1, 0, "pat1", "neg", EXPECT_FALSE, NULL);
	check_one_assign(file, 2, 0, "*", "notundef", EXPECT_TRUE, NULL);
	check_one_assign(file, 3, 0, "pat2", "notundef", EXPECT_UNDEFINED, NULL);
	check_one_assign(file, 4, 0, "pat3", "assigned", EXPECT_STRING, "test-value");
	check_one_assign(file, 5, 0, "pat4", "rule-with-more-chars", EXPECT_STRING, "value-with-more-chars");
	check_one_assign(file, 6, 0, "pat5", "empty", EXPECT_TRUE, NULL);
	check_one_assign(file, 7, 0, "pat6", "negempty", EXPECT_FALSE, NULL);

	rule = get_rule(8);
	cl_assert_equal_s("pat7", rule->match.pattern);
	cl_assert(rule->assigns.length == 5);
	/* assignments will be sorted by hash value, so we have to do
	 * lookups by search instead of by position
	 */
	assign = git_attr_rule__lookup_assignment(rule, "multiple");
	cl_assert(assign);
	cl_assert_equal_s("multiple", assign->name);
	cl_assert(GIT_ATTR_TRUE(assign->value));
	assign = git_attr_rule__lookup_assignment(rule, "single");
	cl_assert(assign);
	cl_assert_equal_s("single", assign->name);
	cl_assert(GIT_ATTR_FALSE(assign->value));
	assign = git_attr_rule__lookup_assignment(rule, "values");
	cl_assert(assign);
	cl_assert_equal_s("values", assign->name);
	cl_assert_equal_s("1", assign->value);
	assign = git_attr_rule__lookup_assignment(rule, "also");
	cl_assert(assign);
	cl_assert_equal_s("also", assign->name);
	cl_assert_equal_s("a-really-long-value/*", assign->value);
	assign = git_attr_rule__lookup_assignment(rule, "happy");
	cl_assert(assign);
	cl_assert_equal_s("happy", assign->name);
	cl_assert_equal_s("yes!", assign->value);
	assign = git_attr_rule__lookup_assignment(rule, "other");
	cl_assert(!assign);

	rule = get_rule(9);
	cl_assert_equal_s("pat8", rule->match.pattern);
	cl_assert(rule->assigns.length == 2);
	assign = git_attr_rule__lookup_assignment(rule, "again");
	cl_assert(assign);
	cl_assert_equal_s("again", assign->name);
	cl_assert(GIT_ATTR_TRUE(assign->value));
	assign = git_attr_rule__lookup_assignment(rule, "another");
	cl_assert(assign);
	cl_assert_equal_s("another", assign->name);
	cl_assert_equal_s("12321", assign->value);

	check_one_assign(file, 10, 0, "pat9", "at-eof", EXPECT_FALSE, NULL);

	git_attr_file__free(file);
}