git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 8, 2007, 07:23 UTC
Message-ID
<7v1wfj4auu.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.64.0707071317060.4093@racer.site>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 11 quoted lines
>> > +	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@pobox.com>
---
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;
 }
Previous: Junio C HamanoNext: Johannes Schindelin
Message 22 of 29 in “diff: add custom regular expressions for function names”
  1. 2/2 diff: add custom regular expressions for function namesJohannes Schindelin, Jul 4, 2007
  2. Linus TorvaldsJul 4, 2007
  3. Johannes SchindelinJul 4, 2007
  4. Junio C HamanoJul 4, 2007
  5. Johannes SchindelinJul 4, 2007
  6. Junio C HamanoJul 5, 2007
  7. 1/2 Future-proof source for changes in xdemitconf_tJunio C Hamano, Jul 5, 2007
  8. Johannes SchindelinJul 5, 2007
  9. 2/2 WIP per-path attribute based hunk header selection.Junio C Hamano, Jul 5, 2007
  10. Johannes SchindelinJul 5, 2007
  11. Junio C HamanoJul 5, 2007
  12. 1/3 Introduce diff_filespec_is_binary()Junio C Hamano, Jul 6, 2007
  13. Johannes SchindelinJul 6, 2007
  14. Per-path attribute based hunk header selection.Junio C Hamano, Jul 6, 2007
  15. Johannes SchindelinJul 6, 2007
  16. Linus TorvaldsJul 6, 2007
  17. Junio C HamanoJul 7, 2007
  18. しらいしななこJul 7, 2007
  19. Junio C HamanoJul 7, 2007
  20. Johannes SchindelinJul 7, 2007
  21. Junio C HamanoJul 7, 2007
  22. Junio C HamanoJul 8, 2007
  23. Johannes SchindelinJul 8, 2007
  24. Nicolas PitreJul 9, 2007
  25. Junio C HamanoJul 9, 2007
  26. Johannes SchindelinJul 9, 2007
  27. Fix configuration syntax to specify customized hunk header patterns.Junio C Hamano, Jul 7, 2007
  28. Florian WeimerJul 5, 2007
  29. Johannes SchindelinJul 5, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.