* [PATCH 1/2] userdiff: add support for R programming language
@ 2025-05-25 21:02 Rodrigo Carvalho
2025-05-25 21:02 ` [PATCH 2/2] t4018: add two userdiff tests for R language Rodrigo Carvalho
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Rodrigo Carvalho @ 2025-05-25 21:02 UTC (permalink / raw)
To: git; +Cc: Rodrigo Carvalho
The patch appends userdiff.c file in order to support R programming
language function header. This will be useful for those who use Git
for versioning .R files.
Signed-off-by: Rodrigo Carvalho <rodrigorsdc@gmail.com>
---
userdiff.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/userdiff.c b/userdiff.c
index da75625020..d1d31ea67e 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -317,6 +317,10 @@ PATTERNS("python",
"|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?"
"|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\*\\*=?"),
/* -- */
+PATTERNS("r",
+ "^[ \t]*([a-zA-z][a-zA-Z0-9_.]*[ \t]*<-[ \t]*function.*)$",
+ /* -- */
+ "[a-zA-Z_][a-zA-Z0-9_.]*"),
PATTERNS("ruby",
"^[ \t]*((class|module|def)[ \t].*)$",
/* -- */
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/2] t4018: add two userdiff tests for R language
2025-05-25 21:02 [PATCH 1/2] userdiff: add support for R programming language Rodrigo Carvalho
@ 2025-05-25 21:02 ` Rodrigo Carvalho
2025-05-25 22:42 ` Eric Sunshine
2025-05-26 5:57 ` [PATCH 1/2] userdiff: add support for R programming language Johannes Sixt
2025-05-29 22:16 ` [PATCH v2] " Rodrigo Carvalho
2 siblings, 1 reply; 9+ messages in thread
From: Rodrigo Carvalho @ 2025-05-25 21:02 UTC (permalink / raw)
To: git; +Cc: Rodrigo Carvalho
This patch adds two userdiff tests for R programming language
files. These files define a simple function, with and without
indentation.
Signed-off-by: Rodrigo Carvalho <rodrigorsdc@gmail.com>
---
t/t4018/r-indent | 6 ++++++
t/t4018/r-noindent | 6 ++++++
2 files changed, 12 insertions(+)
create mode 100644 t/t4018/r-indent
create mode 100644 t/t4018/r-noindent
diff --git a/t/t4018/r-indent b/t/t4018/r-indent
new file mode 100644
index 0000000000..9df440f2a4
--- /dev/null
+++ b/t/t4018/r-indent
@@ -0,0 +1,6 @@
+RIGHT <- function(a, b) {
+ c = mean(a, b)
+ d = c + 2
+ ChangeMe()
+ return (d)
+}
diff --git a/t/t4018/r-noindent b/t/t4018/r-noindent
new file mode 100644
index 0000000000..6d9b01ffe3
--- /dev/null
+++ b/t/t4018/r-noindent
@@ -0,0 +1,6 @@
+RIGHT <- function(a, b) {
+c = mean(a, b)
+d = c + 2
+ChangeMe()
+return (c)
+}
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] t4018: add two userdiff tests for R language
2025-05-25 21:02 ` [PATCH 2/2] t4018: add two userdiff tests for R language Rodrigo Carvalho
@ 2025-05-25 22:42 ` Eric Sunshine
0 siblings, 0 replies; 9+ messages in thread
From: Eric Sunshine @ 2025-05-25 22:42 UTC (permalink / raw)
To: Rodrigo Carvalho; +Cc: git
On Sun, May 25, 2025 at 5:03 PM Rodrigo Carvalho <rodrigorsdc@gmail.com> wrote:
> This patch adds two userdiff tests for R programming language
> files. These files define a simple function, with and without
> indentation.
>
> Signed-off-by: Rodrigo Carvalho <rodrigorsdc@gmail.com>
> ---
> diff --git a/t/t4018/r-indent b/t/t4018/r-indent
> @@ -0,0 +1,6 @@
> +RIGHT <- function(a, b) {
> + c = mean(a, b)
> + d = c + 2
> + ChangeMe()
> + return (d)
> +}
Although nontraditional, do we care that some people define functions
using `=` rather than `<-`?
foo = function(x) {...}
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] userdiff: add support for R programming language
2025-05-25 21:02 [PATCH 1/2] userdiff: add support for R programming language Rodrigo Carvalho
2025-05-25 21:02 ` [PATCH 2/2] t4018: add two userdiff tests for R language Rodrigo Carvalho
@ 2025-05-26 5:57 ` Johannes Sixt
2025-05-27 15:04 ` Junio C Hamano
2025-05-29 22:16 ` [PATCH v2] " Rodrigo Carvalho
2 siblings, 1 reply; 9+ messages in thread
From: Johannes Sixt @ 2025-05-26 5:57 UTC (permalink / raw)
To: Rodrigo Carvalho; +Cc: git
Am 25.05.25 um 23:02 schrieb Rodrigo Carvalho:
> The patch appends userdiff.c file in order to support R programming
> language function header. This will be useful for those who use Git
> for versioning .R files.
>
> Signed-off-by: Rodrigo Carvalho <rodrigorsdc@gmail.com>
> ---
> userdiff.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/userdiff.c b/userdiff.c
> index da75625020..d1d31ea67e 100644
> --- a/userdiff.c
> +++ b/userdiff.c
> @@ -317,6 +317,10 @@ PATTERNS("python",
> "|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?"
> "|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\*\\*=?"),
> /* -- */
> +PATTERNS("r",
Rant mode: I am not a fan of the name "R". It is so un-searchable. It
hijacks a single character for its own purpose.
I don't see a negative impact in this case, though.
> + "^[ \t]*([a-zA-z][a-zA-Z0-9_.]*[ \t]*<-[ \t]*function.*)$",
I wonder how useful this is in practice. Unlike C or Java for example,
code can live outside of functions in R scripts. If you have a script
without any functions, there would not be any hunk headers. If you have
a script with a mix of functions and code outside of functions, the code
after a function would be attributed to the function. I'm not saying
that this is bad, but just asking if this is part of the plan.
> + /* -- */
> + "[a-zA-Z_][a-zA-Z0-9_.]*"),
This singles out identifiers. Every single other characters would be its
own word. I'd consider this a disimprovement. If you are not prepared to
provide worddiff patterns, I recommend to use "[^ \t]+", which roughly
amounts to the default behavior. It can be improved incrementally in
later patches.
> PATTERNS("ruby",
> "^[ \t]*((class|module|def)[ \t].*)$",
> /* -- */
Please squash the test cases into this patch. Don't forget to test an
indented function, and while at it, test a function definition *nested*
in a function definition: that documents what the expected outcome is.
-- Hannes
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] userdiff: add support for R programming language
2025-05-26 5:57 ` [PATCH 1/2] userdiff: add support for R programming language Johannes Sixt
@ 2025-05-27 15:04 ` Junio C Hamano
2025-05-29 21:36 ` Rodrigo Carvalho
0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2025-05-27 15:04 UTC (permalink / raw)
To: Johannes Sixt; +Cc: Rodrigo Carvalho, git
Johannes Sixt <j6t@kdbg.org> writes:
>> + "^[ \t]*([a-zA-z][a-zA-Z0-9_.]*[ \t]*<-[ \t]*function.*)$",
>
> I wonder how useful this is in practice. Unlike C or Java for example,
> code can live outside of functions in R scripts. If you have a script
> without any functions, there would not be any hunk headers. If you have
> a script with a mix of functions and code outside of functions, the code
> after a function would be attributed to the function. I'm not saying
> that this is bad, but just asking if this is part of the plan.
Isn't it the same as shell, perl, python, e-lisp and perhaps others?
If we can reliably detect that we are outside of any function and
set it to an empty string that would be great ;-).
>> + /* -- */
>> + "[a-zA-Z_][a-zA-Z0-9_.]*"),
>
> This singles out identifiers. Every single other characters would be its
> own word. I'd consider this a disimprovement. If you are not prepared to
> provide worddiff patterns, I recommend to use "[^ \t]+", which roughly
> amounts to the default behavior. It can be improved incrementally in
> later patches.
Good point.
> Please squash the test cases into this patch. Don't forget to test an
> indented function, and while at it, test a function definition *nested*
> in a function definition: that documents what the expected outcome is.
Again, good point.
Thanks.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] userdiff: add support for R programming language
2025-05-27 15:04 ` Junio C Hamano
@ 2025-05-29 21:36 ` Rodrigo Carvalho
0 siblings, 0 replies; 9+ messages in thread
From: Rodrigo Carvalho @ 2025-05-29 21:36 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Johannes Sixt, git
> > This singles out identifiers. Every single other characters would be its
> > own word. I'd consider this a disimprovement. If you are not prepared to
> > provide worddiff patterns, I recommend to use "[^ \t]+", which roughly
> > amounts to the default behavior. It can be improved incrementally in
> > later patches.
>
> Good point.
Thanks for the remark. I'll change to this approach in v2
> > Please squash the test cases into this patch. Don't forget to test an
> > indented function, and while at it, test a function definition *nested*
> > in a function definition: that documents what the expected outcome is.
>
> Again, good point.
Sure, that is an important feature that a userdiff driver should
address. Thanks again
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2] userdiff: add support for R programming language
2025-05-25 21:02 [PATCH 1/2] userdiff: add support for R programming language Rodrigo Carvalho
2025-05-25 21:02 ` [PATCH 2/2] t4018: add two userdiff tests for R language Rodrigo Carvalho
2025-05-26 5:57 ` [PATCH 1/2] userdiff: add support for R programming language Johannes Sixt
@ 2025-05-29 22:16 ` Rodrigo Carvalho
2025-06-03 18:20 ` Junio C Hamano
2 siblings, 1 reply; 9+ messages in thread
From: Rodrigo Carvalho @ 2025-05-29 22:16 UTC (permalink / raw)
To: git; +Cc: Rodrigo Carvalho
The patch appends userdiff.c file in order to support R programming
language function header. This will be useful for those who use Git
for versioning .R files.
Also, add three userdiff tests for R programming language
files. These files define simple function and nested function,
with and without indentation.
Signed-off-by: Rodrigo Carvalho <rodrigorsdc@gmail.com>
---
Changes in v2:
- Add support for function defined by '='
- Replace word regex to '[^ \t']
- Add new test that handles with nested function
t/t4018/r-indent | 6 ++++++
t/t4018/r-indent-nested | 10 ++++++++++
t/t4018/r-noindent | 6 ++++++
userdiff.c | 4 ++++
4 files changed, 26 insertions(+)
create mode 100644 t/t4018/r-indent
create mode 100644 t/t4018/r-indent-nested
create mode 100644 t/t4018/r-noindent
diff --git a/t/t4018/r-indent b/t/t4018/r-indent
new file mode 100644
index 0000000000..9df440f2a4
--- /dev/null
+++ b/t/t4018/r-indent
@@ -0,0 +1,6 @@
+RIGHT <- function(a, b) {
+ c = mean(a, b)
+ d = c + 2
+ ChangeMe()
+ return (d)
+}
diff --git a/t/t4018/r-indent-nested b/t/t4018/r-indent-nested
new file mode 100644
index 0000000000..30412e6c79
--- /dev/null
+++ b/t/t4018/r-indent-nested
@@ -0,0 +1,10 @@
+LEFT = function(a, b) {
+ c = mean(a, b)
+ RIGHT = function(d, e) {
+ f = var(d, e)
+ g = f + 1
+ ChangeMe()
+ return (g)
+ }
+ return (RIGHT(2, 3))
+}
diff --git a/t/t4018/r-noindent b/t/t4018/r-noindent
new file mode 100644
index 0000000000..6d9b01ffe3
--- /dev/null
+++ b/t/t4018/r-noindent
@@ -0,0 +1,6 @@
+RIGHT <- function(a, b) {
+c = mean(a, b)
+d = c + 2
+ChangeMe()
+return (c)
+}
diff --git a/userdiff.c b/userdiff.c
index da75625020..64e5005682 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -317,6 +317,10 @@ PATTERNS("python",
"|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?"
"|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\*\\*=?"),
/* -- */
+PATTERNS("r",
+ "^[ \t]*([a-zA-z][a-zA-Z0-9_.]*[ \t]*(<-|=)[ \t]*function.*)$",
+ /* -- */
+ "[^ \t]+"),
PATTERNS("ruby",
"^[ \t]*((class|module|def)[ \t].*)$",
/* -- */
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2] userdiff: add support for R programming language
2025-05-29 22:16 ` [PATCH v2] " Rodrigo Carvalho
@ 2025-06-03 18:20 ` Junio C Hamano
2025-06-03 21:15 ` Johannes Sixt
0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2025-06-03 18:20 UTC (permalink / raw)
To: Rodrigo Carvalho; +Cc: git, Eric Sunshine, Johannes Sixt
Rodrigo Carvalho <rodrigorsdc@gmail.com> writes:
> The patch appends userdiff.c file in order to support R programming
> language function header. This will be useful for those who use Git
> for versioning .R files.
>
> Also, add three userdiff tests for R programming language
> files. These files define simple function and nested function,
> with and without indentation.
>
> Signed-off-by: Rodrigo Carvalho <rodrigorsdc@gmail.com>
> ---
> Changes in v2:
> - Add support for function defined by '='
> - Replace word regex to '[^ \t']
> - Add new test that handles with nested function
Sorry, but this fell of the radar.
It seems all the reviewer comments on the previous round have been
addressed. If everybody is happy with this version, let's merge it
down to 'next', for the next cycle.
Thanks.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] userdiff: add support for R programming language
2025-06-03 18:20 ` Junio C Hamano
@ 2025-06-03 21:15 ` Johannes Sixt
0 siblings, 0 replies; 9+ messages in thread
From: Johannes Sixt @ 2025-06-03 21:15 UTC (permalink / raw)
To: Junio C Hamano, Rodrigo Carvalho; +Cc: git, Eric Sunshine
Am 03.06.25 um 20:20 schrieb Junio C Hamano:
> Rodrigo Carvalho <rodrigorsdc@gmail.com> writes:
>
>> The patch appends userdiff.c file in order to support R programming
>> language function header. This will be useful for those who use Git
>> for versioning .R files.
>>
>> Also, add three userdiff tests for R programming language
>> files. These files define simple function and nested function,
>> with and without indentation.
>>
>> Signed-off-by: Rodrigo Carvalho <rodrigorsdc@gmail.com>
>> ---
>> Changes in v2:
>> - Add support for function defined by '='
>> - Replace word regex to '[^ \t']
>> - Add new test that handles with nested function
>
> Sorry, but this fell of the radar.
>
> It seems all the reviewer comments on the previous round have been
> addressed. If everybody is happy with this version, let's merge it
> down to 'next', for the next cycle.
>
> Thanks.
Sorry for being slow. This round looks good to me, too.
-- Hannes
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-06-03 21:16 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-25 21:02 [PATCH 1/2] userdiff: add support for R programming language Rodrigo Carvalho
2025-05-25 21:02 ` [PATCH 2/2] t4018: add two userdiff tests for R language Rodrigo Carvalho
2025-05-25 22:42 ` Eric Sunshine
2025-05-26 5:57 ` [PATCH 1/2] userdiff: add support for R programming language Johannes Sixt
2025-05-27 15:04 ` Junio C Hamano
2025-05-29 21:36 ` Rodrigo Carvalho
2025-05-29 22:16 ` [PATCH v2] " Rodrigo Carvalho
2025-06-03 18:20 ` Junio C Hamano
2025-06-03 21:15 ` Johannes Sixt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).