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

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

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jul 7, 2007, 12:17 UTC
Message-ID
<Pine.LNX.4.64.0707071317060.4093@racer.site>
In-Reply-To
<7vabu88qem.fsf@assigned-by-dhcp.cox.net>
Hi,
On Sat, 7 Jul 2007, Junio C Hamano wrote:
Show 12 quoted lines
> しらいしななこ  <nanako3@bluebottle.com> writes:
> 
> > I would love to see "diff=tex" attribute to work on my manuscripts, 
> > [...]
> > It does not work well, however.  It shows only part of lines.
> >
> > 	@@ -8,7 +8,8 @@ \section{
> > 	@@ -224,7 +225,7 @@ sub
> > 	@@ -240,7 +241,7 @@ subsub
> >
> > I have no idea what am I doing wrong (truthfully, I do not know what I 
> > am doing, period).
Those are regular expressions. Read more about them here:
	http://en.wikipedia.org/wiki/Regular_expression
> > +	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.

You could write that much simpler, though:
	\\[a-z]*section.*

It would work the same, in practice, because if something like \supercoolsection is defined, you are likely wanting to match that, too.

> Johannes, it strikes me that it is very odd having to add ".*$" at the 
> end and to surround the whole thing in a parentheses. Shouldn't the 
> ff_regexp() grabber simply pick the whole line? After all, that is what 
> GNU "diff -p -F RE" does.
Yes, but then you can forget about your hierarchical idea.

Or maybe not, since I am still awaiting a sane syntax for that, which would probably have to solve just one more problem.

Here is a patch for the rest of the line thing:
diff --git a/xdiff-interface.c b/xdiff-interface.c
index be866d1..9503dfb 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -156,7 +156,7 @@ static long ff_regexp(const char *line, long len,
 	}
 	i = pmatch[1].rm_so >= 0 ? 1 : 0;
 	line += pmatch[i].rm_so;
-	result = pmatch[i].rm_eo - pmatch[i].rm_so;
+	result = (int)len - pmatch[i].rm_so;
 	if (result > buffer_size)
 		result = buffer_size;
 	else

> Also this makes me realize that not all contents in the world are not 
> programming language source files, and "funcname" is a misnomer.  For 
> this one, however, we _can_ blame GNU diff, as they call this 
> --show-function-line option ;-)

Okay.

How about sorting out the other technical issues first 
(diff.<type>.funcname instead of funcname.<type>), leaving the names 
alone, and then rename the remaining references of funcname to hunkheader?

Ciao,
Dscho
Previous: Junio C HamanoNext: Junio C Hamano
Message 20 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.