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

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

 



Hi,

On Sat, 7 Jul 2007, Junio C Hamano wrote:

> しらいしななこ  <nanako3@xxxxxxxxxxxxxx> 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

[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