diff: add ruby funcname pattern
PATCH 1/1 diff: add ruby funcname pattern
Provide a regexp that catches class, module and method definitions in Ruby scripts, since the built-in default only finds classes.
--- diff.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
diff.c +1 -0
@@ -1381,6 +1381,7 @@ static struct builtin_funcname_pattern { "[A-Za-z_][A-Za-z_0-9]*\\)\\{2,\\}" "[ ]*([^;]*\\)$" }, { "tex", "^\\(\\\\\\(sub\\)*section{.*\\)$" }, + { "ruby", "^\\s*\\(\\(class\\|module\\|def\\)\\s.*\\)$" }, };static const char *diff_funcname_pattern (struct diff_filespec *one)
Signature · 1 line
1.5.6.3
Quoted 13 lines · Giuseppe Bilotta
Provide a regexp that catches class, module and method definitions in Ruby scripts, since the built-in default only finds classes.
Signed-off-by Giuseppe Bilotta <[email protected]>--- diff.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)diff.c +0
-0
diff.c static struct builtin_funcname_pattern { · line 1387
Quoted 7 lines
diff.c +1
-0@@ -1381,6 +1381,7 @@ static struct builtin_funcname_pattern { "[A-Za-z_][A-Za-z_0-9]*\\)\\{2,\\}" "[ ]*([^;]*\\)$" }, { "tex", "^\\(\\\\\\(sub\\)*section{.*\\)$" }, + { "ruby", "^\\s*\\(\\(class\\|module\\|def\\)\\s.*\\)$" }, };static const char *diff_funcname_pattern (struct diff_filespec *one)
Thanks.
I do not talk Ruby, so I'll wait for a few days to hear any one of the following happen before deciding what to do with this patch:
(1) Yeah, this is a sufficient and necessary set of keywords, and it
would make my Ruby life so much better;
(2) This might be a good start but you need to cover this and that
keywords as well;
(3) This will misidentify a line that is not the beginning of a
definition, and should not be applied;
Needless to say, "Here is a better patch" is appreciated if somebody says
(2) or (3).
Quoted 3 lines · Junio C Hamano
Thanks.
I do not talk Ruby,
You're really missing into something ;)
Quoted 6 lines
so I'll wait for a few days to hear any one of the following happen before deciding what to do with this patch:
(1) Yeah, this is a sufficient and necessary set of keywords, and it
would make my Ruby life so much better;
Quoted 8 lines
(2) This might be a good start but you need to cover this and that
keywords as well;(3) This will misidentify a line that is not the beginning of a
definition, and should not be applied;Needless to say, "Here is a better patch" is appreciated if somebody says
(2) or (3).
I wasn't sure about the completeness of the regexp myself, which is why I asked in #ruby on freenode for additional suggestions. The only reply I got was an idea to add a number of block-based coding sections such as Procs an Threads by matching .*\.new ({|do) as well.
This is something I had been thinking about myself, but I decided to discard the idea because the current chunk text detection in git does not have a way to say 'this is the end of a function, so get back to the previous chunk (con)text' instead of using the last chunk text: so if I have methodx followed by methody and make a change near the top of methody I get methodx in the chunk text.
This limitation, that affects all funcname parsers, has kept me from adding Proc, Thread and other anonymous code blocks to the Ruby funcname, because having the proper context for changed code after an anonymous block is IMO better than having specific context in the anonymous block itself.
OTOH, if the funcname capability was expand to a full stack manipulation (push chunk text, pop chunk text) ... (and yes, if I ever find a sane way to do it myself I *will* provide a patch)
Signature · 1 line
Giuseppe "Oblomov" Bilotta
Quoted 11 lines · Giuseppe Bilotta
On Fri, Aug 1, 2008 at 9:30 AM, Junio C Hamano <[email protected]> wrote:
...Quoted 9 lines
so I'll wait for a few days to hear any one of the following happen before deciding what to do with this patch:
(1) Yeah, this is a sufficient and necessary set of keywords, and it
would make my Ruby life so much better;(2) This might be a good start but you need to cover this and that
keywords as well;
Quoted 7 lines
Quoted 5 lines
(3) This will misidentify a line that is not the beginning of a
definition, and should not be applied;Needless to say, "Here is a better patch" is appreciated if somebody says
(2) or (3).I wasn't sure about the completeness of the regexp myself, which is
Well, I forgot to say but the above was soliciting third party review; original submitter does not count ;-)
... nah, I am just joking.
All of the things you said in the message I am responding to are good background information. It would have been nicer if it were part of the initial message, perhaps below the three dash lines, which would have avoided this extra exchange.
Thanks again for the patch. Somewhere I heard that there are 10 Rubyista git users for every non Rubyista git user, so I am sure somebody would comment on your patch in a day or two. Perhaps we might even get Python and Perl hunk patterns (although I suspect Perl people are happy with the default one we stole from GNU diff) to go with it ;-).
Quoted 24 lines · Junio C Hamano
Quoted 11 lines · Giuseppe Bilotta
On Fri, Aug 1, 2008 at 9:30 AM, Junio C Hamano <[email protected]> wrote:
...Quoted 9 lines
so I'll wait for a few days to hear any one of the following happen before deciding what to do with this patch:
(1) Yeah, this is a sufficient and necessary set of keywords, and it would make my Ruby life so much better;
(2) This might be a good start but you need to cover this and that keywords as well;
Quoted 7 lines
Quoted 5 lines
(3) This will misidentify a line that is not the beginning of a definition, and should not be applied;
Needless to say, "Here is a better patch" is appreciated if somebody says
(2) or (3).I wasn't sure about the completeness of the regexp myself, which is
Well, I forgot to say but the above was soliciting third party review; original submitter does not count ;-)
Quoted 6 lines
... nah, I am just joking.
All of the things you said in the message I am responding to are good background information. It would have been nicer if it were part of the initial message, perhaps below the three dash lines, which would have avoided this extra exchange.
As a Ruby user, the regex for the funcname looks fine to me.
Quoted 5 lines
Thanks again for the patch. Somewhere I heard that there are 10 Rubyista git users for every non Rubyista git user, so I am sure somebody would comment on your patch in a day or two. Perhaps we might even get Python and Perl hunk patterns (although I suspect Perl people are happy with the default one we stole from GNU diff) to go with it ;-).
I'd like to point out that Python users are called Pythonistas, Ruby users are called... uh, Ruby users, I guess.
-Kevin Ballard
Signature · 4 lines
Kevin Ballard http://kevin.sb.org [email protected] http://www.tildesoft.com
Quoted 5 lines · Kevin Ballard
Quoted 4 lines
Quoted 2 lines · Giuseppe Bilotta
...
I wasn't sure about the completeness of the regexp myself, which is...
As a Ruby user, the regex for the funcname looks fine to me.
Thanks, will apply.
Quoted 2 lines · Kevin Ballard
As a Ruby user, the regex for the funcname looks fine to me.
What is your opinion about the anonymous code blocks?
I've been thinking that another possibility could be to have two ruby funcnames, a simpler one (the one I presented) that only has 'named' blocks, and a more thorough one that also matches up anonymous blocks. User could then choose which one to use in their code by having gitattributes such as *.rb diff=ruby or *.rb diff=ruby-full (or whatever else).
I'm not sure this would be a sensible policy though.
Signature · 1 line
Giuseppe "Oblomov" Bilotta
Quoted 6 lines · Giuseppe Bilotta
Quoted 2 lines · Kevin Ballard
As a Ruby user, the regex for the funcname looks fine to me.
What is your opinion about the anonymous code blocks?
Quoted 8 lines
I've been thinking that another possibility could be to have two ruby funcnames, a simpler one (the one I presented) that only has 'named' blocks, and a more thorough one that also matches up anonymous blocks. User could then choose which one to use in their code by having gitattributes such as *.rb diff=ruby or *.rb diff=ruby-full (or whatever else).
I'm not sure this would be a sensible policy though.
If you're going to get into anonymous code blocks, you're going to have a really tough time deciding which blocks are interesting and which aren't. And as you stated before, without a stack-based approach, this could really fall apart, as anonymous blocks are (almost) always going to be inside a method.
I think it's far simpler to stick with class/module/def.
-Kevin Ballard
Signature · 4 lines
Kevin Ballard http://kevin.sb.org [email protected] http://www.tildesoft.com
Quoted 6 lines · Kevin Ballard
If you're going to get into anonymous code blocks, you're going to have a really tough time deciding which blocks are interesting and which aren't. And as you stated before, without a stack-based approach, this could really fall apart, as anonymous blocks are (almost) always going to be inside a method.
I was just looking for a libxdiff issue tracker but I couldn't find one, so I guess I'll ask the author directly about the possibility to implement such a thing. The matchit plugin for vim seems to manage (even user-defined) code blocks very well, even for multi-state blocks (if ... else ... end), using regexps; so maybe a reimplementation in C for libxdiff could be a solution. Of course, one wonders how much slower such an approach would be as opposed to the current "look back until the first matching line" solution ...
Signature · 1 line
Giuseppe "Oblomov" Bilotta
Quoted 5 lines · Junio C Hamano
Thanks again for the patch. Somewhere I heard that there are 10 Rubyista git users for every non Rubyista git user, so I am sure somebody would comment on your patch in a day or two. Perhaps we might even get Python and Perl hunk patterns (although I suspect Perl people are happy with the default one we stole from GNU diff) to go with it ;-).
I keep a lot of Perl in git, and yes, I am quite happy with the default regex.
-Peff
Quoted 9 lines · Junio C Hamano
Well, I forgot to say but the above was soliciting third party review; original submitter does not count ;-)
... nah, I am just joking.
All of the things you said in the message I am responding to are good background information. It would have been nicer if it were part of the initial message, perhaps below the three dash lines, which would have avoided this extra exchange.
Yeah, I know, I'm sorry, I realized I should have written it there as I was replying to your email. I'll try to keep it in mind the next time I submit a patch :)
Quoted 5 lines
Thanks again for the patch. Somewhere I heard that there are 10 Rubyista git users for every non Rubyista git user, so I am sure somebody would comment on your patch in a day or two. Perhaps we might even get Python and Perl hunk patterns (although I suspect Perl people are happy with the default one we stole from GNU diff) to go with it ;-).
You know, I think the Ruby funcname would work pretty well with Python as well. Or something very similar. I'll try cooking up a patch for that too. (But I thought Python users used mercurial? 8-D)
Signature · 1 line
Giuseppe "Oblomov" Bilotta
Hi,
Quoted 11 lines · Giuseppe Bilotta
Quoted 6 lines · Kevin Ballard
If you're going to get into anonymous code blocks, you're going to have a really tough time deciding which blocks are interesting and which aren't. And as you stated before, without a stack-based approach, this could really fall apart, as anonymous blocks are (almost) always going to be inside a method.
I was just looking for a libxdiff issue tracker but I couldn't find one, so I guess I'll ask the author directly about the possibility to implement such a thing.
The funcname thing was introduced by us, in Git. I do not know if Davide picked the changes up; at least for the merge stuff he seemed to be pretty reluctant.
Quoted 4 lines
The matchit plugin for vim seems to manage (even user-defined) code blocks very well, even for multi-state blocks (if ... else ... end), using regexps; so maybe a reimplementation in C for libxdiff could be a solution.
Bzzt. You say vi manages it with regexps, and then you go on and say that you therefore do _not_ want to use a regexp?
BTW having funcname calculation in C was shot down by Junio as being too inflexible, as the user cannot add new languages without recompiling. That's why we have regexps now.
Ciao,
Dscho
Hello,
Quoted 3 lines · Johannes Schindelin
The funcname thing was introduced by us, in Git. I do not know if Davide picked the changes up; at least for the merge stuff he seemed to be pretty reluctant.
Ah, it's a Git-only thing? didn't know about that. I guess that knowing that git's libxdiff is already hacked up from the original means I can think more freely about hacking it up some more, if I can come up with a proper solution 8-)
Quoted 11 lines
Quoted 4 lines
The matchit plugin for vim seems to manage (even user-defined) code blocks very well, even for multi-state blocks (if ... else ... end), using regexps; so maybe a reimplementation in C for libxdiff could be a solution.
Bzzt. You say vi manages it with regexps, and then you go on and say that you therefore do _not_ want to use a regexp?
BTW having funcname calculation in C was shot down by Junio as being too inflexible, as the user cannot add new languages without recompiling. That's why we have regexps now.
Sorry, I think there's a misunderstanding here ... I have all intentions to use regexps. What I was planning on reimplementing in C was the way matchit uses the regexps to determine the blocks (because, obviously, it being a vim script means it's coded in vim's own langauge instead of C). The actual definitions for the start and end of the block would still be done via regexps. 8-)
Signature · 1 line
Giuseppe "Oblomov" Bilotta
Quoted 6 lines · Kevin Ballard
Quoted 1 line · Giuseppe Bilotta
On Sat, Aug 2, 2008 at 2:31 AM, Kevin Ballard <[email protected]> wrote:
I think it's far simpler to stick with class/module/def.
I agree with Kevin.
It's simpler and I'm not sure what value it would bring to show anonymous code blocks. The funcname is just to provide some additional context around the diff hunk, so you know where you are. What would be shown for an anonymous code block or proc in the diff? The module/class/method seems to provide the most useful context.
-Lee