[PATCH 3/2] pathattr: read from git_config().

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Now we read the path traits from the usual configuration
mechanism.  No per-directory .gitattributes yet, though.

Signed-off-by: Junio C Hamano <junkio@xxxxxxx>
---
 * [3/2] (this one) and [4/2] are the follow-up to the pathattr
   series.

 pathattr.c |   63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 62 insertions(+), 1 deletions(-)

diff --git a/pathattr.c b/pathattr.c
index c84be39..2532c9a 100644
--- a/pathattr.c
+++ b/pathattr.c
@@ -85,6 +85,67 @@ static void add_match(struct pathattr_stack *s, struct pathattr *a, const char *
 	m->attr = a;
 }
 
+static convi_fn conv_i_trait(const char *value)
+{
+	if (!strcmp(value, "crlf"))
+		return convi_crlf;
+	return NULL;
+}
+
+static convo_fn conv_o_trait(const char *value)
+{
+	if (!strcmp(value, "crlf"))
+		return convo_crlf;
+	return NULL;
+}
+
+static pretty_fn pretty_trait(const char *value)
+{
+	if (!strcmp(value, "display"))
+		return show_display;
+	return NULL;
+}
+
+static int attr_config(const char *var, const char *value)
+{
+	struct pathattr *a;
+	static const char pa[] = "pathattr.";
+	const char *trait;
+	char group[256];
+	int group_len;
+
+	if (prefixcmp(var, pa))
+		return 0; /* we are not interested in other configs */
+	trait = strrchr(var, '.');
+	if (!trait)
+		return 0; /* huh? */
+	group_len = trait - var - (sizeof(pa) - 1);
+	if (group_len <= 0)
+		return 0; /* huh? */
+	trait++;
+	if (sizeof(group) < group_len)
+		die("'%.*s' is too long as a group name", group_len,
+		    var + sizeof(pa) - 1);
+	memcpy(group, var + sizeof(pa) - 1, group_len);
+	group[group_len] = 0;
+	a = locate(stk, group);
+
+	if (!strcmp(trait, "path"))
+		add_match(stk, a, value);
+	else if (!strcmp(trait, "conv_i"))
+		a->conv_i = conv_i_trait(value);
+	else if (!strcmp(trait, "conv_o"))
+		a->conv_i = conv_o_trait(value);
+	else if (!strcmp(trait, "pretty"))
+		a->pretty = pretty_trait(value);
+	/*
+	 * Do not barf if the configuration has unknown trait.
+	 * the user might be bisecting git and trying an older
+	 * version on the latest repository.
+	 */
+	return 0;
+}
+
 static void init_stack(void)
 {
 	struct pathattr *a;
@@ -105,7 +166,7 @@ static void init_stack(void)
 	add_match(stk, a, "*.jpg");
 	add_match(stk, a, "*.gif");
 
-	/* NEEDSWORK: read from config */
+	git_config(attr_config);
 }
 
 static void pop_stack(void)
-- 
1.5.0.2.809.g0f936


-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]