Re: [PATCH] Per-path attribute based hunk header selection.

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

 



Johannes Schindelin <Johannes.Schindelin@xxxxxx> writes:

>> > +	if (!strcmp(ident, "tex"))
>> > +		return "^\\\\\\(sub\\)*section{";
>
> It is always easier, and will never require C skills, to put this into the 
> config. With Junio's current version:
>
> 	echo '*.tex funcname=tex' >> .gitattributes
> 	echo '[funcname] tex = ^\(\\\(sub\)*section{.*\)' >> .git/config
>
> The problem is of course that the backslashes have to be escaped _both_ in 
> C and in regexps.

I think giving a reasonable set of basic language support as
built-in patterns is important for usability.  Otherwise the
users end up needing to have them in their $HOME/.gitconfig.

I am not sure if Java and LaTeX qualify as the first two most
important cases, but they are what we already have
demonstrated.  How about doing something like this?


-- >8 --
diff.c: make built-in hunk header pattern a separate table

This would hopefully make it easier to maintain.  Initially we
would have "java" and "tex" defined, as they are the only ones
we already have.

Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx>
---
diff --git a/diff.c b/diff.c
index b8473f5..cd6b0c4 100644
--- a/diff.c
+++ b/diff.c
@@ -1216,9 +1216,22 @@ static const char *funcname_pattern(const char *ident)
 	return NULL;
 }
 
+static struct builtin_funcname_pattern {
+	const char *name;
+	const char *pattern;
+} builtin_funcname_pattern[] = {
+	{ "java", "!^[ 	]*\\(catch\\|do\\|for\\|if\\|instanceof\\|"
+			"new\\|return\\|switch\\|throw\\|while\\)\n"
+			"^[ 	]*\\(\\([ 	]*"
+			"[A-Za-z_][A-Za-z_0-9]*\\)\\{2,\\}"
+			"[ 	]*([^;]*$\\)" },
+	{ "tex", "^\\(\\\\\\(sub\\)*section{.*\\)$" },
+};
+
 static const char *diff_funcname_pattern(struct diff_filespec *one)
 {
 	const char *ident, *pattern;
+	int i;
 
 	diff_filespec_check_attr(one);
 	ident = one->funcname_pattern_ident;
@@ -1240,12 +1253,9 @@ static const char *diff_funcname_pattern(struct diff_filespec *one)
 	 * And define built-in fallback patterns here.  Note that
 	 * these can be overriden by the user's config settings.
 	 */
-	if (!strcmp(ident, "java"))
-		return "!^[ 	]*\\(catch\\|do\\|for\\|if\\|instanceof\\|"
-			"new\\|return\\|switch\\|throw\\|while\\)\n"
-			"^[ 	]*\\(\\([ 	]*"
-			"[A-Za-z_][A-Za-z_0-9]*\\)\\{2,\\}"
-			"[ 	]*([^;]*$\\)";
+	for (i = 0; i < ARRAY_SIZE(builtin_funcname_pattern); i++)
+		if (!strcmp(ident, builtin_funcname_pattern[i].name))
+			return builtin_funcname_pattern[i].pattern;
 
 	return NULL;
 }





-
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]

  Powered by Linux