threads / rfc / 60710

[GSOC][RFC] Add more builtin patterns for userdiff, as Mircroproject.

Subject: [GSOC][RFC] Add more builtin patterns for userdiff, as Mircroproject.

## tl;dr

33 messages between Jan 9, 2024 and Mar 19, 2024.

replies: 32people: 5as markdown or json

Sergius Nyah· Jan 9, 2024, 19:55 UTC · lore

Hello everyone, I'm Sergius, a Computer Science undergraduate student, and I want to begin Contributing to the Git project. So far, I've gone through Matheus' tutorial on First steps Contributing to Git, and I found it very helpful. I've also read the Contribution guidelines keenly and built Git from source.

In accordance to the contributor guidelines, I came across this Mircoproject idea from: https://git.github.io/SoC-2022-Microprojects/ which I'm willing to work on. It talked about enhancing Git's "userdiff" feature in "userdiff.c" which is crucial for identifying function names in various programming languages, thereby improving the readability of "git diff" outputs.

From my understanding, the project involves extending the `userdiff` feature to support additional programming languages that are currently not covered such as Shell, Swift, Go and the others.

Here is a sample of how a language is defined in `userdiff.c`:
Show 10 quoted lines
> #define PATTERNS(lang, rx, wrx) { \
> .name = lang, \
> .binary = -1, \
> .funcname = { \
> .pattern = rx, \
> .cflags = REG_EXTENDED, \
> }, \
> .word_regex = wrx "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+", \
> .word_regex_multi_byte = wrx "|[^[:space:]]", \
> }

In this code, `lang` is the name of the language, `rx` is the regular expression for identifying function names, and `wrx` is the word regex.

Approach: I Identified the Programming Languages that are not
currently supported by the userdiff feature by reviewing the existing
patterns in userdiff.c and comparing them with some popular
programming languages.
For each supported language, I would define a regular expression that
could help identify function names in that language. This could
include researching each language's syntax and testing their
expressions to ensure that they work well.
Also, I'd add a new IPATTERN definition for each language to the
"userdiff.c" file, then rebuild Git and test the changes by creating a
repo with files in the newly supported languages then run "git diff"
to ensure the line @@ ... @@ produces their correct function names.
Then submit a patch.

Best Regards! Sergius.

Christian Couder· Jan 10, 2024, 11:33 UTC · re: Sergius Nyah · lore

Re: [GSOC][RFC] Add more builtin patterns for userdiff, as Mircroproject.

Hi Sergius,
On Tue, Jan 9, 2024 at 8:59 PM Sergius Nyah <sergiusnyah@gmail.com> wrote:
Show 7 quoted lines
>
> Hello everyone,
> I'm Sergius, a Computer Science undergraduate student, and I want to
> begin Contributing to the Git project. So far, I've gone through
> Matheus' tutorial on First steps Contributing to Git, and I found it
> very helpful. I've also read the Contribution guidelines keenly and
> built Git from source.
Thanks for your interest in contributing to Git!
> In accordance to the contributor guidelines, I came across this
> Mircoproject idea from: https://git.github.io/SoC-2022-Microprojects/
s/Mircoproject/microproject/
There is a similar typo in the subject of your email too.
Show 8 quoted lines
> which I'm willing to work on. It talked about enhancing Git's
> "userdiff" feature in "userdiff.c" which is crucial for identifying
> function names in various programming languages, thereby improving the
> readability of "git diff" outputs.
>
> From my understanding, the project involves extending the `userdiff`
> feature to support additional programming languages that are currently
> not covered such as Shell, Swift, Go and the others.
As far as I can see in userdiff.c, Golang and Bash seem to be supported.
Show 25 quoted lines
> Here is a sample of how a language is defined in `userdiff.c`:
>
> > #define PATTERNS(lang, rx, wrx) { \
> > .name = lang, \
> > .binary = -1, \
> > .funcname = { \
> > .pattern = rx, \
> > .cflags = REG_EXTENDED, \
> > }, \
> > .word_regex = wrx "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+", \
> > .word_regex_multi_byte = wrx "|[^[:space:]]", \
> > }
>
> In this code, `lang` is the name of the language, `rx` is the regular
> expression for identifying function names, and `wrx` is the word
> regex.
>
> Approach: I Identified the Programming Languages that are not
> currently supported by the userdiff feature by reviewing the existing
> patterns in userdiff.c and comparing them with some popular
> programming languages.
> For each supported language, I would define a regular expression that
> could help identify function names in that language. This could
> include researching each language's syntax and testing their
> expressions to ensure that they work well.

In your microproject, you only need to add support for ONE language that is not supported yet. Please don't try to do more than that.

Show 5 quoted lines
> Also, I'd add a new IPATTERN definition for each language to the
> "userdiff.c" file, then rebuild Git and test the changes by creating a
> repo with files in the newly supported languages then run "git diff"
> to ensure the line @@ ... @@ produces their correct function names.
> Then submit a patch.
Except for my comments above, this looks like a good plan. Thanks.
Sergius Nyah· Jan 11, 2024, 14:23 UTC · lore

Fwd: [GSOC][RFC] Add more builtin patterns for userdiff, as Mircroproject.

---------- Forwarded message ---------
From: Christian Couder <christian.couder@gmail.com>
Date: Thu, Jan 11, 2024 at 11:51 AM
Subject: Re: [GSOC][RFC] Add more builtin patterns for userdiff, as
Mircroproject.
To: Sergius Nyah <sergiusnyah@gmail.com>

On Thu, Jan 11, 2024 at 11:48 AM Christian Couder <christian.couder@gmail.com> wrote:

>
> On Wed, Jan 10, 2024 at 9:10 PM Sergius Nyah <sergiusnyah@gmail.com> wrote:
Show 9 quoted lines
> > > Okay then. I will add support for shell, as it was primarily suggested
> > > in the idea itself.
>
> As Bash is a shell and is already supported, I am not sure which kind
> of shell you want to support. There are other shells or kinds of shell
> with different syntax that might be worth supporting, but then you
> might want to tell us which shell or which new kind of shell.
>
> Thanks!

I've definitely learned one more thing. Thank you! Also, after taking another keen look at the Patterns defined in userdiff.c, In accordance with what you've said, I realized that Kotlin isn't supported yet. So, I'd begin working on it. Thanks!

By the way I realized that you replied privately to me instead of keeping the mailing list in Cc: This made me reply privately to you.

Thank you for the correction Christian. Noted!

I think it would be better if the discussions were all public as this way others could give you their opinion on this.

Definitely True.
Christian Couder· Jan 11, 2024, 15:11 UTC · re: Sergius Nyah · lore

Re: [GSOC][RFC] Add more builtin patterns for userdiff, as Mircroproject.

On Thu, Jan 11, 2024 at 3:23 PM Sergius Nyah <sergiusnyah@gmail.com> wrote:
Show 28 quoted lines
>
> ---------- Forwarded message ---------
> From: Christian Couder <christian.couder@gmail.com>
> Date: Thu, Jan 11, 2024 at 11:51 AM
> Subject: Re: [GSOC][RFC] Add more builtin patterns for userdiff, as
> Mircroproject.
> To: Sergius Nyah <sergiusnyah@gmail.com>
>
>
> On Thu, Jan 11, 2024 at 11:48 AM Christian Couder
> <christian.couder@gmail.com> wrote:
> >
> > On Wed, Jan 10, 2024 at 9:10 PM Sergius Nyah <sergiusnyah@gmail.com> wrote:
>
> > > > Okay then. I will add support for shell, as it was primarily suggested
> > > > in the idea itself.
> >
> > As Bash is a shell and is already supported, I am not sure which kind
> > of shell you want to support. There are other shells or kinds of shell
> > with different syntax that might be worth supporting, but then you
> > might want to tell us which shell or which new kind of shell.
> >
> > Thanks!
>
> I've definitely learned one more thing. Thank you!
> Also, after taking another keen look at the Patterns defined in userdiff.c,
> In accordance with what you've said, I realized that Kotlin isn't
> supported yet.
It is actually already supported too:

$ grep -i -n kotlin userdiff.c 186:PATTERNS("kotlin",

To help you a bit, you can get the list of already supported languages using:

$ perl -ne 'print "$1\n" if m/PATTERNS\(\"(\w+)\"/ or m/IPATTERN\(\"(\w+)\"/' <userdiff.c ada bash bibtex cpp csharp css dts elixir fortran fountain golang html java kotlin markdown matlab objc pascal perl php python ruby rust scheme tex

Sergius Nyah· Jan 11, 2024, 15:42 UTC · re: Christian Couder · lore

Re: [GSOC][RFC] Add more builtin patterns for userdiff, as Mircroproject.

On Thu, Jan 11, 2024 at 4:11 PM Christian Couder <christian.couder@gmail.com> wrote:

Show 40 quoted lines
>
> On Thu, Jan 11, 2024 at 3:23 PM Sergius Nyah <sergiusnyah@gmail.com> wrote:
> >
> > ---------- Forwarded message ---------
> > From: Christian Couder <christian.couder@gmail.com>
> > Date: Thu, Jan 11, 2024 at 11:51 AM
> > Subject: Re: [GSOC][RFC] Add more builtin patterns for userdiff, as
> > Mircroproject.
> > To: Sergius Nyah <sergiusnyah@gmail.com>
> >
> >
> > On Thu, Jan 11, 2024 at 11:48 AM Christian Couder
> > <christian.couder@gmail.com> wrote:
> > >
> > > On Wed, Jan 10, 2024 at 9:10 PM Sergius Nyah <sergiusnyah@gmail.com> wrote:
> >
> > > > > Okay then. I will add support for shell, as it was primarily suggested
> > > > > in the idea itself.
> > >
> > > As Bash is a shell and is already supported, I am not sure which kind
> > > of shell you want to support. There are other shells or kinds of shell
> > > with different syntax that might be worth supporting, but then you
> > > might want to tell us which shell or which new kind of shell.
> > >
> > > Thanks!
> >
> > I've definitely learned one more thing. Thank you!
> > Also, after taking another keen look at the Patterns defined in userdiff.c,
> > In accordance with what you've said, I realized that Kotlin isn't
> > supported yet.
>
> It is actually already supported too:
>
> $ grep -i -n kotlin userdiff.c
> 186:PATTERNS("kotlin",
>
> To help you a bit, you can get the list of already supported languages using:
>
> $ perl -ne 'print "$1\n" if m/PATTERNS\(\"(\w+)\"/ or
> m/IPATTERN\(\"(\w+)\"/' <userdiff.c

Thank you for these. $ perl -ne 'print "$1\n" if m/IPATTERN\(\"(\w+)\"/' userdiff.c works too.

Show 25 quoted lines
> ada
> bash
> bibtex
> cpp
> csharp
> css
> dts
> elixir
> fortran
> fountain
> golang
> html
> java
> kotlin
> markdown
> matlab
> objc
> pascal
> perl
> php
> python
> ruby
> rust
> scheme
> tex

Great! JavaScript, despite its widespread use, isn't implemented, so I will take it. Thank you!

Sergius Nyah· Feb 27, 2024, 14:19 UTC · re: Sergius Nyah · lore

[GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject.

Firstly, I'm so sorry for the delay between selecting the Microproject and sending the patch series. Learning about regular expressions took me a bit longer than I expected, but it was all worth it. I'm very grateful for the opportunity to work on this project and I'm looking forward to contributing more to Git.

This patch series adds builtin patterns for JavaScript function detection in userdiff, as my Microproject for GSOC. The first patch adds a regular expression for detecting JavaScript functions in Git diffs while the second adds a test for JavaScript function detection in Git diffs. This new pattern looks for lines that start with optional whitespace, followed by 'function' and any characters (for function declarations), or valid JavaScript identifiers, equals sign '=', 'function' keyword and any characters (for function expressions). It also considers functions defined inside blocks with '{...}'.

 t/t4018-diff-funcname.sh | 25 +++++++++++++++++++++++--
 userdiff.c               | 17 +++++++++++++++--
 2 files changed, 38 insertions(+), 4 deletions(-)
 
base-commit: c5b454771e6b086f60c7f1f139025f174bcedac9
-- 
2.43.2

I would greatly appreciate any feedback on the patch series.
Best, 
Sergius.
Sergius Nyah· Feb 27, 2024, 14:19 UTC · re: Sergius Nyah · lore

[PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff.

From: Sergius Justus Chesami Nyah <74214119+Sergius-Nyah@users.noreply.github.com>
This patch adds the regular expression for detecting JavaScript functions and expressions in Git diffs. The pattern accurately identifies function declerations, expressions, and definitions inside blocks.
---
 userdiff.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/userdiff.c b/userdiff.c
index e399543823..12e31ff14d 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -1,7 +1,7 @@
 #include "git-compat-util.h"
 #include "config.h"
 #include "userdiff.h"
-#include "attr.h"
+#include "attr.h" 
 #include "strbuf.h"
 
 static struct userdiff_driver *drivers;
@@ -183,6 +183,19 @@ PATTERNS("java",
 	 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
 	 "|[-+*/<>%&^|=!]="
 	 "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
+PATTERNS("javascript",
+     /* 
+	  * Looks for lines that start with optional whitespace, followed 
+	  * by 'function'* and any characters (for function declarations), 
+      * or valid JavaScript identifiers, equals sign '=', 'function' keyword
+	  * and any characters (for function expressions).
+      * Also considers functions defined inside blocks with '{...}'.
+	  */ 
+	 "^[ \t]*(function[ \t]*.*|[a-zA-Z_$][0-9a-zA-Z_$]*[ \t]*=[ \t]*function[ \t]*.*|(\\{[ \t]*)?)\n",
+     /* This pattern matches JavaScript identifiers */
+     "[a-zA-Z_$][0-9a-zA-Z_$]*"
+     "|[-+0-9.eE]+|0[xX][0-9a-fA-F]+" 
+     "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\|"), 
 PATTERNS("kotlin",
 	 "^[ \t]*(([a-z]+[ \t]+)*(fun|class|interface)[ \t]+.*)$",
 	 /* -- */
@@ -192,7 +205,7 @@ PATTERNS("kotlin",
 	 /* integers and floats */
 	 "|[0-9][0-9_]*([.][0-9_]*)?([Ee][-+]?[0-9]+)?[fFlLuU]*"
 	 /* floating point numbers beginning with decimal point */
-	 "|[.][0-9][0-9_]*([Ee][-+]?[0-9]+)?[fFlLuU]?"
+	 "|[.][0-9][0-9_]*([Ee][-+]?[0-9]+ )?[fFlLuU]?"
 	 /* unary and binary operators */
 	 "|[-+*/<>%&^|=!]==?|--|\\+\\+|<<=|>>=|&&|\\|\\||->|\\.\\*|!!|[?:.][.:]"),
 PATTERNS("markdown",
-- 
2.43.2
Sergius Nyah· Feb 27, 2024, 14:19 UTC · re: Sergius Nyah · lore

[PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs

From: Sergius Justus Chesami Nyah <74214119+Sergius-Nyah@users.noreply.github.com>
This commit introduces a new test case in t4018-diff-funcname.sh to verify the enhanced JavaScript function detection in Git diffs. The test creates a JavaScript file with function declarations and expressions, modifies them, and then checks the output of git diff to ensure that the changes are correctly identified. This test validates the changes made to userdiff.c for improved JavaScript function detection.
---
 t/t4018-diff-funcname.sh | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index e026fac1f4..e88e63bd1f 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -11,7 +11,7 @@ test_expect_success 'setup' '
 	# a non-trivial custom pattern
 	git config diff.custom1.funcname "!static
 !String
-[^ 	].*s.*" &&
+[^ 	].*s.*" && 
 
 	# a custom pattern which matches to end of line
 	git config diff.custom2.funcname "......Beer\$" &&
@@ -119,4 +119,25 @@ do
 	"
 done
 
-test_done
+test_expect_success 'identify builtin patterns in Javascript' '
+    # setup
+    echo "function myFunction() { return true; }" > test.js &&
+    echo "var myVar = function() { return false; }" >> test.js &&
+    git add test.js &&
+    git commit -m "add test.js" &&
+
+    # modify the file
+    echo "function myFunction() { return false; }" > test.js &&
+    echo "var myVar = function() { return true; }" >> test.js &&
+
+    # command under test
+    git diff >output &&
+
+    # check results
+    test_i18ngrep "function myFunction() { return true; }" output &&
+    test_i18ngrep "function myFunction() { return false; }" output &&
+    test_i18ngrep "var myVar = function() { return false; }" output &&
+    test_i18ngrep "var myVar = function() { return true; }" output
+'
+
+test_done 
\ No newline at end of file
-- 
2.43.2
Sergius Nyah· Feb 27, 2024, 14:21 UTC · re: Sergius Nyah · lore

[GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject.

Firstly, I'm so sorry for the delay between selecting the Microproject and sending the patch series. Learning about regular expressions took me a bit longer than I expected, but it was all worth it. I'm very grateful for the opportunity to work on this project and I'm looking forward to contributing more to Git.

This patch series adds builtin patterns for JavaScript function detection in userdiff, as my Microproject for GSOC. The first patch adds a regular expression for detecting JavaScript functions in Git diffs while the second adds a test for JavaScript function detection in Git diffs. This new pattern looks for lines that start with optional whitespace, followed by 'function' and any characters (for function declarations), or valid JavaScript identifiers, equals sign '=', 'function' keyword and any characters (for function expressions). It also considers functions defined inside blocks with '{...}'.

 t/t4018-diff-funcname.sh | 25 +++++++++++++++++++++++--
 userdiff.c               | 17 +++++++++++++++--
 2 files changed, 38 insertions(+), 4 deletions(-)
 
base-commit: c5b454771e6b086f60c7f1f139025f174bcedac9
-- 
2.43.2

I would greatly appreciate any feedback on the patch series.
Best, 
Sergius.
Sergius Nyah· Feb 27, 2024, 14:21 UTC · re: Sergius Nyah · lore

[PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff.

From: Sergius Justus Chesami Nyah <74214119+Sergius-Nyah@users.noreply.github.com>
This patch adds the regular expression for detecting JavaScript functions and expressions in Git diffs. The pattern accurately identifies function declerations, expressions, and definitions inside blocks.
---
 userdiff.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/userdiff.c b/userdiff.c
index e399543823..12e31ff14d 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -1,7 +1,7 @@
 #include "git-compat-util.h"
 #include "config.h"
 #include "userdiff.h"
-#include "attr.h"
+#include "attr.h" 
 #include "strbuf.h"
 
 static struct userdiff_driver *drivers;
@@ -183,6 +183,19 @@ PATTERNS("java",
 	 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
 	 "|[-+*/<>%&^|=!]="
 	 "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
+PATTERNS("javascript",
+     /* 
+	  * Looks for lines that start with optional whitespace, followed 
+	  * by 'function'* and any characters (for function declarations), 
+      * or valid JavaScript identifiers, equals sign '=', 'function' keyword
+	  * and any characters (for function expressions).
+      * Also considers functions defined inside blocks with '{...}'.
+	  */ 
+	 "^[ \t]*(function[ \t]*.*|[a-zA-Z_$][0-9a-zA-Z_$]*[ \t]*=[ \t]*function[ \t]*.*|(\\{[ \t]*)?)\n",
+     /* This pattern matches JavaScript identifiers */
+     "[a-zA-Z_$][0-9a-zA-Z_$]*"
+     "|[-+0-9.eE]+|0[xX][0-9a-fA-F]+" 
+     "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\|"), 
 PATTERNS("kotlin",
 	 "^[ \t]*(([a-z]+[ \t]+)*(fun|class|interface)[ \t]+.*)$",
 	 /* -- */
@@ -192,7 +205,7 @@ PATTERNS("kotlin",
 	 /* integers and floats */
 	 "|[0-9][0-9_]*([.][0-9_]*)?([Ee][-+]?[0-9]+)?[fFlLuU]*"
 	 /* floating point numbers beginning with decimal point */
-	 "|[.][0-9][0-9_]*([Ee][-+]?[0-9]+)?[fFlLuU]?"
+	 "|[.][0-9][0-9_]*([Ee][-+]?[0-9]+ )?[fFlLuU]?"
 	 /* unary and binary operators */
 	 "|[-+*/<>%&^|=!]==?|--|\\+\\+|<<=|>>=|&&|\\|\\||->|\\.\\*|!!|[?:.][.:]"),
 PATTERNS("markdown",
-- 
2.43.2
Sergius Nyah· Feb 27, 2024, 14:21 UTC · re: Sergius Nyah · lore

[PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs

From: Sergius Justus Chesami Nyah <74214119+Sergius-Nyah@users.noreply.github.com>
This commit introduces a new test case in t4018-diff-funcname.sh to verify the enhanced JavaScript function detection in Git diffs. The test creates a JavaScript file with function declarations and expressions, modifies them, and then checks the output of git diff to ensure that the changes are correctly identified. This test validates the changes made to userdiff.c for improved JavaScript function detection.
---
 t/t4018-diff-funcname.sh | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index e026fac1f4..e88e63bd1f 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -11,7 +11,7 @@ test_expect_success 'setup' '
 	# a non-trivial custom pattern
 	git config diff.custom1.funcname "!static
 !String
-[^ 	].*s.*" &&
+[^ 	].*s.*" && 
 
 	# a custom pattern which matches to end of line
 	git config diff.custom2.funcname "......Beer\$" &&
@@ -119,4 +119,25 @@ do
 	"
 done
 
-test_done
+test_expect_success 'identify builtin patterns in Javascript' '
+    # setup
+    echo "function myFunction() { return true; }" > test.js &&
+    echo "var myVar = function() { return false; }" >> test.js &&
+    git add test.js &&
+    git commit -m "add test.js" &&
+
+    # modify the file
+    echo "function myFunction() { return false; }" > test.js &&
+    echo "var myVar = function() { return true; }" >> test.js &&
+
+    # command under test
+    git diff >output &&
+
+    # check results
+    test_i18ngrep "function myFunction() { return true; }" output &&
+    test_i18ngrep "function myFunction() { return false; }" output &&
+    test_i18ngrep "var myVar = function() { return false; }" output &&
+    test_i18ngrep "var myVar = function() { return true; }" output
+'
+
+test_done 
\ No newline at end of file
-- 
2.43.2
Sergius Nyah· Feb 27, 2024, 14:25 UTC · re: Sergius Nyah · lore

[GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject.

From: Sergius Nyah <sergiusnyah@gmail.com>

Firstly, I'm so sorry for the delay between selecting the Microproject and sending the patch series. Learning about regular expressions took me a bit longer than I expected, but it was all worth it. I'm very grateful for the opportunity to work on this project and I'm looking forward to contributing more to Git.

This patch series adds builtin patterns for JavaScript function detection in userdiff, as my Microproject for GSOC. The first patch adds a regular expression for detecting JavaScript functions in Git diffs while the second adds a test for JavaScript function detection in Git diffs. This new pattern looks for lines that start with optional whitespace, followed by 'function' and any characters (for function declarations), or valid JavaScript identifiers, equals sign '=', 'function' keyword and any characters (for function expressions). It also considers functions defined inside blocks with '{...}'.

 t/t4018-diff-funcname.sh | 25 +++++++++++++++++++++++--
 userdiff.c               | 17 +++++++++++++++--
 2 files changed, 38 insertions(+), 4 deletions(-)
 
base-commit: c5b454771e6b086f60c7f1f139025f174bcedac9
-- 
2.43.2

I would greatly appreciate any feedback on the patch series.
Best, 
Sergius.
Sergius Nyah· Feb 27, 2024, 14:25 UTC · re: Sergius Nyah · lore

[PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff.

From: Sergius Justus Chesami Nyah <74214119+Sergius-Nyah@users.noreply.github.com>
This patch adds the regular expression for detecting JavaScript functions and expressions in Git diffs. The pattern accurately identifies function declerations, expressions, and definitions inside blocks.
---
 userdiff.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/userdiff.c b/userdiff.c
index e399543823..12e31ff14d 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -1,7 +1,7 @@
 #include "git-compat-util.h"
 #include "config.h"
 #include "userdiff.h"
-#include "attr.h"
+#include "attr.h" 
 #include "strbuf.h"
 
 static struct userdiff_driver *drivers;
@@ -183,6 +183,19 @@ PATTERNS("java",
 	 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
 	 "|[-+*/<>%&^|=!]="
 	 "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
+PATTERNS("javascript",
+     /* 
+	  * Looks for lines that start with optional whitespace, followed 
+	  * by 'function'* and any characters (for function declarations), 
+      * or valid JavaScript identifiers, equals sign '=', 'function' keyword
+	  * and any characters (for function expressions).
+      * Also considers functions defined inside blocks with '{...}'.
+	  */ 
+	 "^[ \t]*(function[ \t]*.*|[a-zA-Z_$][0-9a-zA-Z_$]*[ \t]*=[ \t]*function[ \t]*.*|(\\{[ \t]*)?)\n",
+     /* This pattern matches JavaScript identifiers */
+     "[a-zA-Z_$][0-9a-zA-Z_$]*"
+     "|[-+0-9.eE]+|0[xX][0-9a-fA-F]+" 
+     "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\|"), 
 PATTERNS("kotlin",
 	 "^[ \t]*(([a-z]+[ \t]+)*(fun|class|interface)[ \t]+.*)$",
 	 /* -- */
@@ -192,7 +205,7 @@ PATTERNS("kotlin",
 	 /* integers and floats */
 	 "|[0-9][0-9_]*([.][0-9_]*)?([Ee][-+]?[0-9]+)?[fFlLuU]*"
 	 /* floating point numbers beginning with decimal point */
-	 "|[.][0-9][0-9_]*([Ee][-+]?[0-9]+)?[fFlLuU]?"
+	 "|[.][0-9][0-9_]*([Ee][-+]?[0-9]+ )?[fFlLuU]?"
 	 /* unary and binary operators */
 	 "|[-+*/<>%&^|=!]==?|--|\\+\\+|<<=|>>=|&&|\\|\\||->|\\.\\*|!!|[?:.][.:]"),
 PATTERNS("markdown",
-- 
2.43.2
Sergius Nyah· Feb 27, 2024, 14:25 UTC · re: Sergius Nyah · lore

[PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs

From: Sergius Justus Chesami Nyah <74214119+Sergius-Nyah@users.noreply.github.com>
This commit introduces a new test case in t4018-diff-funcname.sh to verify the enhanced JavaScript function detection in Git diffs. The test creates a JavaScript file with function declarations and expressions, modifies them, and then checks the output of git diff to ensure that the changes are correctly identified. This test validates the changes made to userdiff.c for improved JavaScript function detection.
---
 t/t4018-diff-funcname.sh | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index e026fac1f4..e88e63bd1f 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -11,7 +11,7 @@ test_expect_success 'setup' '
 	# a non-trivial custom pattern
 	git config diff.custom1.funcname "!static
 !String
-[^ 	].*s.*" &&
+[^ 	].*s.*" && 
 
 	# a custom pattern which matches to end of line
 	git config diff.custom2.funcname "......Beer\$" &&
@@ -119,4 +119,25 @@ do
 	"
 done
 
-test_done
+test_expect_success 'identify builtin patterns in Javascript' '
+    # setup
+    echo "function myFunction() { return true; }" > test.js &&
+    echo "var myVar = function() { return false; }" >> test.js &&
+    git add test.js &&
+    git commit -m "add test.js" &&
+
+    # modify the file
+    echo "function myFunction() { return false; }" > test.js &&
+    echo "var myVar = function() { return true; }" >> test.js &&
+
+    # command under test
+    git diff >output &&
+
+    # check results
+    test_i18ngrep "function myFunction() { return true; }" output &&
+    test_i18ngrep "function myFunction() { return false; }" output &&
+    test_i18ngrep "var myVar = function() { return false; }" output &&
+    test_i18ngrep "var myVar = function() { return true; }" output
+'
+
+test_done 
\ No newline at end of file
-- 
2.43.2
Sergius Nyah· Feb 27, 2024, 16:02 UTC · re: Sergius Nyah · lore

[GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject.

I would like to apologize for the numerous irrelevant emails that have been sent to this mailing list recently. They were the result of a configuration issue with my setup, which caused my patches to be sent from a `noreply` GitHub address. This led to a series of failed delivery attempts and unnecessary emails.

Firstly, I'm so sorry for the delay between selecting the Microproject and sending the patch series. Learning about regular expressions took me a bit longer than I expected, but it was all worth it. I'm very grateful for the opportunity to work on this project and I'm looking forward to contributing more to Git.

This patch series adds builtin patterns for JavaScript function detection in userdiff, as my Microproject for GSOC. The first patch adds a regular expression for detecting JavaScript functions in Git diffs while the second adds a test for JavaScript function detection in Git diffs. This new pattern looks for lines that start with optional whitespace, followed by 'function' and any characters (for function declarations), or valid JavaScript identifiers, equals sign '=', 'function' keyword and any characters (for function expressions). It also considers functions defined inside blocks with '{...}'.

 t/t4018-diff-funcname.sh | 25 +++++++++++++++++++++++--
 userdiff.c               | 17 +++++++++++++++--
 2 files changed, 38 insertions(+), 4 deletions(-)
 
base-commit: c5b454771e6b086f60c7f1f139025f174bcedac9
-- 
2.43.2

I would greatly appreciate any feedback on the patch series.
Best, 
Sergius.
Sergius Nyah· Feb 27, 2024, 16:02 UTC · re: Sergius Nyah · lore

[PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff.

This patch adds the regular expression for detecting JavaScript functions and expressions in Git diffs. The pattern accurately identifies function declerations, expressions, and definitions inside blocks.
---
 userdiff.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/userdiff.c b/userdiff.c
index e399543823..12e31ff14d 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -1,7 +1,7 @@
 #include "git-compat-util.h"
 #include "config.h"
 #include "userdiff.h"
-#include "attr.h"
+#include "attr.h" 
 #include "strbuf.h"
 
 static struct userdiff_driver *drivers;
@@ -183,6 +183,19 @@ PATTERNS("java",
 	 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
 	 "|[-+*/<>%&^|=!]="
 	 "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
+PATTERNS("javascript",
+     /* 
+	  * Looks for lines that start with optional whitespace, followed 
+	  * by 'function'* and any characters (for function declarations), 
+      * or valid JavaScript identifiers, equals sign '=', 'function' keyword
+	  * and any characters (for function expressions).
+      * Also considers functions defined inside blocks with '{...}'.
+	  */ 
+	 "^[ \t]*(function[ \t]*.*|[a-zA-Z_$][0-9a-zA-Z_$]*[ \t]*=[ \t]*function[ \t]*.*|(\\{[ \t]*)?)\n",
+     /* This pattern matches JavaScript identifiers */
+     "[a-zA-Z_$][0-9a-zA-Z_$]*"
+     "|[-+0-9.eE]+|0[xX][0-9a-fA-F]+" 
+     "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\|"), 
 PATTERNS("kotlin",
 	 "^[ \t]*(([a-z]+[ \t]+)*(fun|class|interface)[ \t]+.*)$",
 	 /* -- */
@@ -192,7 +205,7 @@ PATTERNS("kotlin",
 	 /* integers and floats */
 	 "|[0-9][0-9_]*([.][0-9_]*)?([Ee][-+]?[0-9]+)?[fFlLuU]*"
 	 /* floating point numbers beginning with decimal point */
-	 "|[.][0-9][0-9_]*([Ee][-+]?[0-9]+)?[fFlLuU]?"
+	 "|[.][0-9][0-9_]*([Ee][-+]?[0-9]+ )?[fFlLuU]?"
 	 /* unary and binary operators */
 	 "|[-+*/<>%&^|=!]==?|--|\\+\\+|<<=|>>=|&&|\\|\\||->|\\.\\*|!!|[?:.][.:]"),
 PATTERNS("markdown",
-- 
2.43.2
:wq
Ghanshyam Thakkar· Feb 27, 2024, 19:06 UTC · re: Sergius Nyah · lore

Re: [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff.

On Tue Feb 27, 2024 at 9:32 PM IST, Sergius Nyah wrote:
> [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff.

I think these prefixes somehow got added twice. In any case, this makes it so that "Subject: [GSOC][RFC PATCH 1/2]" is part of the commit log, which shoud not be. And the subject can be better written as:

    userdiff: add builtin patterns for Javascript
> This patch adds the regular expression for detecting JavaScript functions and expressions in Git diffs. The pattern accurately identifies function declerations, expressions, and definitions inside blocks.
commit message should be wrapped at 72 characters.
Show 14 quoted lines
> ---
>  userdiff.c | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/userdiff.c b/userdiff.c
> index e399543823..12e31ff14d 100644
> --- a/userdiff.c
> +++ b/userdiff.c
> @@ -1,7 +1,7 @@
>  #include "git-compat-util.h"
>  #include "config.h"
>  #include "userdiff.h"
> -#include "attr.h"
> +#include "attr.h" 
This change adds trailing whitespace which is not desired.
Show 20 quoted lines
>  #include "strbuf.h"
>  
>  static struct userdiff_driver *drivers;
> @@ -183,6 +183,19 @@ PATTERNS("java",
>  	 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
>  	 "|[-+*/<>%&^|=!]="
>  	 "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
> +PATTERNS("javascript",
> +     /* 
> +	  * Looks for lines that start with optional whitespace, followed 
> +	  * by 'function'* and any characters (for function declarations), 
> +      * or valid JavaScript identifiers, equals sign '=', 'function' keyword
> +	  * and any characters (for function expressions).
> +      * Also considers functions defined inside blocks with '{...}'.
> +	  */ 
> +	 "^[ \t]*(function[ \t]*.*|[a-zA-Z_$][0-9a-zA-Z_$]*[ \t]*=[ \t]*function[ \t]*.*|(\\{[ \t]*)?)\n",
> +     /* This pattern matches JavaScript identifiers */
> +     "[a-zA-Z_$][0-9a-zA-Z_$]*"
> +     "|[-+0-9.eE]+|0[xX][0-9a-fA-F]+" 
> +     "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\|"), 

Majority of the lines above (including comment) have trailing whitespace. Consider removing them. Also, tabs should be used for indentation instead of spaces. (cf. Documentation/CodingGuidelines)

Show 9 quoted lines
>  PATTERNS("kotlin",
>  	 "^[ \t]*(([a-z]+[ \t]+)*(fun|class|interface)[ \t]+.*)$",
>  	 /* -- */
> @@ -192,7 +205,7 @@ PATTERNS("kotlin",
>  	 /* integers and floats */
>  	 "|[0-9][0-9_]*([.][0-9_]*)?([Ee][-+]?[0-9]+)?[fFlLuU]*"
>  	 /* floating point numbers beginning with decimal point */
> -	 "|[.][0-9][0-9_]*([Ee][-+]?[0-9]+)?[fFlLuU]?"
> +	 "|[.][0-9][0-9_]*([Ee][-+]?[0-9]+ )?[fFlLuU]?"

This adds extra whitespace in the middle. Changes not related to the patch topic should be avoided.

Also this was attempted before, see [1]. I think you can take some inspiration and inputs from that also. Aside from that I think the separate patch which adds tests for this can be squashed into this one.

[1]: https://lore.kernel.org/git/20220403132508.28196-1-a97410985new@gmail.com/

Thanks.
Sergius Nyah· Feb 27, 2024, 21:05 UTC · re: Ghanshyam Thakkar · lore

Re: [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff.

On Tue, Feb 27, 2024 at 8:06 PM Ghanshyam Thakkar <shyamthakkar001@gmail.com> wrote:

Show 10 quoted lines
>
> On Tue Feb 27, 2024 at 9:32 PM IST, Sergius Nyah wrote:
> > [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff.
>
> I think these prefixes somehow got added twice. In any case, this makes
> it so that "Subject: [GSOC][RFC PATCH 1/2]" is part of the commit log,
> which shoud not be. And the subject can be better written as:
>
>     userdiff: add builtin patterns for Javascript
>
Noted, thanks!
> > This patch adds the regular expression for detecting JavaScript functions and expressions in Git diffs. The pattern accurately identifies function declerations, expressions, and definitions inside blocks.
>
> commit message should be wrapped at 72 characters.
> > ---
Thank you for the correction.
Show 16 quoted lines
> >  userdiff.c | 17 +++++++++++++++--
> >  1 file changed, 15 insertions(+), 2 deletions(-)
> >
> > diff --git a/userdiff.c b/userdiff.c
> > index e399543823..12e31ff14d 100644
> > --- a/userdiff.c
> > +++ b/userdiff.c
> > @@ -1,7 +1,7 @@
> >  #include "git-compat-util.h"
> >  #include "config.h"
> >  #include "userdiff.h"
> > -#include "attr.h"
> > +#include "attr.h"
>
> This change adds trailing whitespace which is not desired.
>
Okay. Would avoid them in subsequent commits.
Show 24 quoted lines
> >  #include "strbuf.h"
> >
> >  static struct userdiff_driver *drivers;
> > @@ -183,6 +183,19 @@ PATTERNS("java",
> >        "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
> >        "|[-+*/<>%&^|=!]="
> >        "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
> > +PATTERNS("javascript",
> > +     /*
> > +       * Looks for lines that start with optional whitespace, followed
> > +       * by 'function'* and any characters (for function declarations),
> > +      * or valid JavaScript identifiers, equals sign '=', 'function' keyword
> > +       * and any characters (for function expressions).
> > +      * Also considers functions defined inside blocks with '{...}'.
> > +       */
> > +      "^[ \t]*(function[ \t]*.*|[a-zA-Z_$][0-9a-zA-Z_$]*[ \t]*=[ \t]*function[ \t]*.*|(\\{[ \t]*)?)\n",
> > +     /* This pattern matches JavaScript identifiers */
> > +     "[a-zA-Z_$][0-9a-zA-Z_$]*"
> > +     "|[-+0-9.eE]+|0[xX][0-9a-fA-F]+"
> > +     "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\|"),
>
> Majority of the lines above (including comment) have trailing whitespace.
> Consider removing them. Also, tabs should be used for indentation instead
> of spaces. (cf. Documentation/CodingGuidelines)
Well received. Thanks!
Show 13 quoted lines
>
> >  PATTERNS("kotlin",
> >        "^[ \t]*(([a-z]+[ \t]+)*(fun|class|interface)[ \t]+.*)$",
> >        /* -- */
> > @@ -192,7 +205,7 @@ PATTERNS("kotlin",
> >        /* integers and floats */
> >        "|[0-9][0-9_]*([.][0-9_]*)?([Ee][-+]?[0-9]+)?[fFlLuU]*"
> >        /* floating point numbers beginning with decimal point */
> > -      "|[.][0-9][0-9_]*([Ee][-+]?[0-9]+)?[fFlLuU]?"
> > +      "|[.][0-9][0-9_]*([Ee][-+]?[0-9]+ )?[fFlLuU]?"
>
> This adds extra whitespace in the middle. Changes not related to the patch
> topic should be avoided.
Sorry about that, I just touched what I shouldn't have.
Show 10 quoted lines
>
> Also this was attempted before, see [1]. I think you can take some
> inspiration and inputs from that also. Aside from that I think the
> separate patch which adds tests for this can be squashed into this
> one.
>
> [1]:
> https://lore.kernel.org/git/20220403132508.28196-1-a97410985new@gmail.com/
>
> Thanks.

Thank you for all the corrections. I'd submit a patch series with the correct practices.

Sergius Nyah· Feb 27, 2024, 16:02 UTC · re: Sergius Nyah · lore

[PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs

From: Sergius Justus Chesami Nyah <sergiusnyah@gmail.com>
This commit introduces a new test case in t4018-diff-funcname.sh to verify the enhanced JavaScript function detection in Git diffs. The test creates a JavaScript file with function declarations and expressions, modifies them, and then checks the output of git diff to ensure that the changes are correctly identified. This test validates the changes made to userdiff.c for improved JavaScript function detection.
---
 t/t4018-diff-funcname.sh | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index e026fac1f4..e88e63bd1f 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -11,7 +11,7 @@ test_expect_success 'setup' '
 	# a non-trivial custom pattern
 	git config diff.custom1.funcname "!static
 !String
-[^ 	].*s.*" &&
+[^ 	].*s.*" && 
 
 	# a custom pattern which matches to end of line
 	git config diff.custom2.funcname "......Beer\$" &&
@@ -119,4 +119,25 @@ do
 	"
 done
 
-test_done
+test_expect_success 'identify builtin patterns in Javascript' '
+    # setup
+    echo "function myFunction() { return true; }" > test.js &&
+    echo "var myVar = function() { return false; }" >> test.js &&
+    git add test.js &&
+    git commit -m "add test.js" &&
+
+    # modify the file
+    echo "function myFunction() { return false; }" > test.js &&
+    echo "var myVar = function() { return true; }" >> test.js &&
+
+    # command under test
+    git diff >output &&
+
+    # check results
+    test_i18ngrep "function myFunction() { return true; }" output &&
+    test_i18ngrep "function myFunction() { return false; }" output &&
+    test_i18ngrep "var myVar = function() { return false; }" output &&
+    test_i18ngrep "var myVar = function() { return true; }" output
+'
+
+test_done 
\ No newline at end of file
-- 
2.43.2
Sergius Nyah· Feb 28, 2024, 15:00 UTC · re: Sergius Nyah · lore

[GSOC][PATCH] Userdiff: add builtin patterns for JavaScript.

This commit introduces builtin patterns for JavaScript in userdiff and adds a new test
case in t4018-diff-funcname.sh to verify the enhanced JavaScript function detection in Git diffs.
Signed-off-by: Sergius Justus Chesami Nyah <sergiusnyah@gmail.com>
---
...-PATCH-1-2-Add-builtin-patterns-for-.patch | 53 ++++++-------------
t/t4018-diff-funcname.sh                      | 25 ++++++++-
2 files changed, 38 insertions(+), 40 deletions(-)
diff --git a/Pattern/0001-Subject-GSOC-RFC-PATCH-1-2-Add-builtin-patterns-for-.patch b/Pattern/0001-Subject-GSOC-RFC-PATCH-1-2-Add-builtin-patterns-for-.patch
index 43593866bc..9c3b80665e 100644
--- a/Pattern/0001-Subject-GSOC-RFC-PATCH-1-2-Add-builtin-patterns-for-.patch
+++ b/Pattern/0001-Subject-GSOC-RFC-PATCH-1-2-Add-builtin-patterns-for-.patch
-This patch adds the regular expression for detecting JavaScript functions and expressions in Git diffs. The pattern accurately identifies function declerations, expressions, and definitions inside blocks.
----
+This patch adds the regular expression for detecting JavaScript functions and expressions in Git diffs.
userdiff.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)

@@ -18,40 +16,19 @@ index e399543823..12e31ff14d 100644
#include "git-compat-util.h"
#include "config.h"
#include "userdiff.h"
#include "strbuf.h"

+PATTERNS("javascript",
-+     /*
++      * Looks for lines that start with optional whitespace, followed
++      * by 'function'* and any characters (for function declarations),
++      * or valid JavaScript identifiers, equals sign '=', 'function' keyword
+       * and any characters (for function expressions).
++      * Also considers functions defined inside blocks with '{...}'.
++      */
+      "^[ \t]*(function[ \t]*.*|[a-zA-Z_$][0-9a-zA-Z_$]*[ \t]*=[ \t]*function[ \t]*.*|(\\{[ \t]*)?)\n",
-+     /* This pattern matches JavaScript identifiers */
-+     "[a-zA-Z_$][0-9a-zA-Z_$]*"
-+     "|[-+0-9.eE]+|0[xX][0-9a-fA-F]+"
-+     "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\|"),

Here is the test file.

-test_done
+test_expect_success 'identify builtin patterns in Javascript' '
+    # setup
+    echo "function myFunction() { return true; }" > test.js &&
+    echo "var myVar = function() { return false; }" >> test.js &&
+    git add test.js &&
+    git commit -m "add test.js" &&
+
+    # modify the file
+    echo "function myFunction() { return false; }" > test.js &&
+    echo "var myVar = function() { return true; }" >> test.js &&
+
+    # command under test
+    git diff >output &&
+
+    # check results
+    test_i18ngrep "function myFunction() { return true; }" output &&
+    test_i18ngrep "function myFunction() { return false; }" output &&
+    test_i18ngrep "var myVar = function() { return false; }" output &&
+    test_i18ngrep "var myVar = function() { return true; }" output
+'
+
+test_done
--
2.43.2
Junio C Hamano· Feb 28, 2024, 18:19 UTC · re: Sergius Nyah · lore

Re: [GSOC][PATCH] Userdiff: add builtin patterns for JavaScript.

Sergius Nyah <sergiusnyah@gmail.com> writes:
Show 7 quoted lines
> This commit introduces builtin patterns for JavaScript in userdiff and adds a new test
> case in t4018-diff-funcname.sh to verify the enhanced JavaScript function detection in Git diffs.
> Signed-off-by: Sergius Justus Chesami Nyah <sergiusnyah@gmail.com>
> ---
> ...-PATCH-1-2-Add-builtin-patterns-for-.patch | 53 ++++++-------------
> t/t4018-diff-funcname.sh                      | 25 ++++++++-
> 2 files changed, 38 insertions(+), 40 deletions(-)

You apparently have done "git add" of a file that is a format-patch output, which led to ...

> diff --git a/Pattern/0001-Subject-GSOC-RFC-PATCH-1-2-Add-builtin-patterns-for-.patch b/Pattern/0001-Subject-GSOC-RFC-PATCH-1-2-Add-builtin-patterns-for-.patch
> index 43593866bc..9c3b80665e 100644
> --- a/Pattern/0001-Subject-GSOC-RFC-PATCH-1-2-Add-builtin-patterns-for-.patch
> +++ b/Pattern/0001-Subject-GSOC-RFC-PATCH-1-2-Add-builtin-patterns-for-.patch
... this thing.

Wrap the proposed commit log message to a reasonable length and have a blank line before your sign-off. Other pieces of advice about formatting and contents found in Documentation/SubmittingPatches are also helpful.

Thanks.
Sergius Nyah· Feb 29, 2024, 10:11 UTC · re: Junio C Hamano · lore

[GSOC][PATCH] userdiff: add builtin patterns for JavaScript.

This commit introduces builtin patterns for JavaScript in userdiff.

It adds a new test case in t4018-diff-funcname.sh to verify the enhanced JavaScript function detection in Git diffs.

Signed-off-by: Sergius Justus Chesami Nyah <sergiusnyah@gmail.com>
---
userdiff.c | 17 +++++++++++++++--
t/t4018-diff-funcname.sh | 25 ++++++++-
2 files changed, 38 insertions(+), 4 deletions(-)
diff --git a/userdiff.c b/userdiff.c
index e399543823..12e31ff14d 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -18,40 +16,19 @@
#include "git-compat-util.h"
#include "config.h"
#include "userdiff.h"
#include "strbuf.h"

PATTERNS("javascript",
      /* Looks for lines that start with optional whitespace, followed
      * by 'function'* and any characters (for function declarations),
      * or valid JavaScript identifiers, equals sign '=', 'function' keyword
      * and any characters (for function expressions).
      * Also considers functions defined inside blocks with '{...}'.
      */
      "^[ \t]*(function[ \t]*.*|[a-zA-Z_$][0-9a-zA-Z_$]*[ \t]*=[ \t]*function[ \t]*.*|(\\{[ \t]*)?)\n",
      /* This pattern matches JavaScript identifiers */
      "[a-zA-Z_$][0-9a-zA-Z_$]*"
      "|[-+0-9.eE]+|0[xX][0-9a-fA-F]+"
      "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\|"),

diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index 43593866bc..9c3b80665e 100644
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -18,40 +16,19 @@
test_expect_success 'identify builtin patterns in Javascript' '
    # setup
    echo "function myFunction() { return true; }" > test.js &&
    echo "var myVar = function() { return false; }" >> test.js &&
    git add test.js &&
    git commit -m "add test.js" &&

    # modify the file
    echo "function myFunction() { return false; }" > test.js &&
    echo "var myVar = function() { return true; }" >> test.js &&

    # command under test
    git diff >output &&

    # check results
    test_i18ngrep "function myFunction() { return true; }" output &&
    test_i18ngrep "function myFunction() { return false; }" output &&
    test_i18ngrep "var myVar = function() { return false; }" output &&
    test_i18ngrep "var myVar = function() { return true; }" output
'

test_done
--
2.43.2
Ghanshyam Thakkar· Feb 29, 2024, 12:01 UTC · re: Sergius Nyah · lore

Re: [GSOC][PATCH] userdiff: add builtin patterns for JavaScript.

On Thu Feb 29, 2024 at 3:41 PM IST, Sergius Nyah wrote:
> This commit introduces builtin patterns for JavaScript in userdiff.

"This commit introduces ..." -> "Introduce ...". I think describing which specification this adheres to (i.e. ECMA-262) would be helpful for the readers.

> It adds a new test case in t4018-diff-funcname.sh to verify the enhanced
> JavaScript function detection in Git diffs.
"It adds ..." -> "Add ..."
Show 28 quoted lines
> Signed-off-by: Sergius Justus Chesami Nyah <sergiusnyah@gmail.com>
> ---
> userdiff.c | 17 +++++++++++++++--
> t/t4018-diff-funcname.sh | 25 ++++++++-
> 2 files changed, 38 insertions(+), 4 deletions(-)
>
> diff --git a/userdiff.c b/userdiff.c
> index e399543823..12e31ff14d 100644
> --- a/userdiff.c
> +++ b/userdiff.c
> @@ -18,40 +16,19 @@
> #include "git-compat-util.h"
> #include "config.h"
> #include "userdiff.h"
> #include "strbuf.h"
>
> PATTERNS("javascript",
>       /* Looks for lines that start with optional whitespace, followed
>       * by 'function'* and any characters (for function declarations),
>       * or valid JavaScript identifiers, equals sign '=', 'function' keyword
>       * and any characters (for function expressions).
>       * Also considers functions defined inside blocks with '{...}'.
>       */
>       "^[ \t]*(function[ \t]*.*|[a-zA-Z_$][0-9a-zA-Z_$]*[ \t]*=[ \t]*function[ \t]*.*|(\\{[ \t]*)?)\n",
>       /* This pattern matches JavaScript identifiers */
>       "[a-zA-Z_$][0-9a-zA-Z_$]*"
>       "|[-+0-9.eE]+|0[xX][0-9a-fA-F]+"
>       "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\|"),

It seems like you manually manipulated the diff/format-patch output that is not the commit message. Usually all the new lines have '+' sign prefixed and all the removed lines have '-' sign prefixed. git am gives the following error:

    Applying: userdiff: add builtin patterns for JavaScript.
    error: corrupt patch at line 11
    Patch failed at 0022 userdiff: add builtin patterns for JavaScript.

If you find it difficult to use send-email/format-patch, you can always make a pull request on git/git or gitgitgadget/git on GitHub and GitGitGadget[1] will take care of the rest. If you still want to use format-patch, it is a good practice to version your patches (i.e. [PATCH v2 1/2] ...) so that it is easy to follow. (cf. Documentation/SubmittingPatches or Documentation/MyFirstContribution)

[1]: https://gitgitgadget.github.io/
Thanks.
Show 29 quoted lines
> diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
> index 43593866bc..9c3b80665e 100644
> --- a/t/t4018-diff-funcname.sh
> +++ b/t/t4018-diff-funcname.sh
> @@ -18,40 +16,19 @@
> test_expect_success 'identify builtin patterns in Javascript' '
>     # setup
>     echo "function myFunction() { return true; }" > test.js &&
>     echo "var myVar = function() { return false; }" >> test.js &&
>     git add test.js &&
>     git commit -m "add test.js" &&
>
>     # modify the file
>     echo "function myFunction() { return false; }" > test.js &&
>     echo "var myVar = function() { return true; }" >> test.js &&
>
>     # command under test
>     git diff >output &&
>
>     # check results
>     test_i18ngrep "function myFunction() { return true; }" output &&
>     test_i18ngrep "function myFunction() { return false; }" output &&
>     test_i18ngrep "var myVar = function() { return false; }" output &&
>     test_i18ngrep "var myVar = function() { return true; }" output
> '
>
> test_done
> --
> 2.43.2
Sergius Nyah· Mar 1, 2024, 07:40 UTC · re: Junio C Hamano · lore

[GSOC][PATCH] userdiff: Add JavaScript function patterns

This commit adds a patterns used to match JavaScript functions. It now correctly identifies function declarations, function expressions, and functions defined inside blocks. Add test for corresponding change in userdiff.

Signed-off-by: Sergius Nyah <sergiusnyah@gmail.com>
---
 t/t4018-diff-funcname.sh | 22 ++++++++++++++++++++++
 userdiff.c               | 12 ++++++++++++
 2 files changed, 34 insertions(+)
diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index e026fac1f4..d35cce18a0 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -120,3 +120,25 @@ do
 done

 test_done
+
+test_expect_success 'identify builtin patterns in JavaScript' '
+	# setup
+	echo "function myFunction() { return true; }" > test.js &&
+	echo "var myVar = function() { return false; }" >> test.js &&
+	git add test.js &&
+	git commit -m "add test.js" &&
+
+	# modify the file
+	echo "function myFunction() { return false; }" > test.js &&
+	echo "var myVar = function() { return true; }" >> test.js &&
+
+	# command under test
+	git diff >output &&
+
+	# check results
+	test_i18ngrep "function myFunction() { return true; }" output &&
+	test_i18ngrep "function myFunction() { return false; }" output &&
+	test_i18ngrep "var myVar = function() { return false; }" output &&
+	test_i18ngrep "var myVar = function() { return true; }" output
+'
+test_done
\ No newline at end of file
diff --git a/userdiff.c b/userdiff.c
index 2b1dab2649..bbe2bcb9a3 100644
--- a/userdiff.c
+++ b/userdiff.c
+PATTERNS("javascript",
+      /* Looks for lines that start with optional whitespace, followed
+      * by 'function'* and any characters (for function declarations),
+      * or valid JavaScript identifiers, equals sign '=', 'function' keyword
+      * and any characters (for function expressions).
+      * Also considers functions defined inside blocks with '{...}'.
+      */
+      "^[ \t]*(function[ \t]*.*|[a-zA-Z_$][0-9a-zA-Z_$]*[ \t]*=[ \t]*function[ \t]*.*|(\\{[ \t]*)?)\n",
+      /* This pattern matches JavaScript identifiers */
+      "[a-zA-Z_$][0-9a-zA-Z_$]*"
+      "|[-+0-9.eE]+|0[xX][0-9a-fA-F]+"
+      "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\|"),
--
2.43.2
Christian Couder· Mar 2, 2024, 10:28 UTC · re: Sergius Nyah · lore

Re: [GSOC][PATCH] userdiff: Add JavaScript function patterns

The subject should be "userdiff: add JavaScript function patterns" so with "add" instead of "Add". See the SubmittingPatches document which contains:

"The title sentence after the "area:" prefix omits the full stop at the end, and its first word is not capitalized (the omission of capitalization applies only to the word after the "area:" prefix of the title) unless there is a reason to capitalize it other than because it is the first word in the sentence."

On Fri, Mar 1, 2024 at 8:40 AM Sergius Nyah <sergiusnyah@gmail.com> wrote:
>
> This commit adds a patterns used to match JavaScript functions.
It should be either "add patterns" or "add a pattern".

Also instead of "This commit" please use the imperative mood or "Let's". See the SubmittingPatches document which contains:

"Describe your changes in imperative mood, e.g. "make xyzzy do frotz" instead of "[This patch] makes xyzzy do frotz" or "[I] changed xyzzy to do frotz", as if you are giving orders to the codebase to change its behavior."

Show 8 quoted lines
> It now correctly identifies function declarations, function expressions,
> and functions defined inside blocks. Add test for corresponding change in userdiff.
>
> Signed-off-by: Sergius Nyah <sergiusnyah@gmail.com>
> ---
>  t/t4018-diff-funcname.sh | 22 ++++++++++++++++++++++
>  userdiff.c               | 12 ++++++++++++
>  2 files changed, 34 insertions(+)
In t4034-diff-words.sh there is:

test_language_driver ada test_language_driver bibtex test_language_driver cpp test_language_driver csharp test_language_driver css test_language_driver dts test_language_driver fortran test_language_driver html test_language_driver java test_language_driver kotlin test_language_driver matlab test_language_driver objc test_language_driver pascal test_language_driver perl test_language_driver php test_language_driver python test_language_driver ruby test_language_driver scheme test_language_driver tex

So I would have thought that you would just add a `test_language_driver javascript` line in this file and associated material in the t/t4034/ directory.

Show 28 quoted lines
> diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
> index e026fac1f4..d35cce18a0 100755
> --- a/t/t4018-diff-funcname.sh
> +++ b/t/t4018-diff-funcname.sh
> @@ -120,3 +120,25 @@ do
>  done
>
>  test_done
> +
> +test_expect_success 'identify builtin patterns in JavaScript' '
> +       # setup
> +       echo "function myFunction() { return true; }" > test.js &&
> +       echo "var myVar = function() { return false; }" >> test.js &&
> +       git add test.js &&
> +       git commit -m "add test.js" &&
> +
> +       # modify the file
> +       echo "function myFunction() { return false; }" > test.js &&
> +       echo "var myVar = function() { return true; }" >> test.js &&
> +
> +       # command under test
> +       git diff >output &&
> +
> +       # check results
> +       test_i18ngrep "function myFunction() { return true; }" output &&
> +       test_i18ngrep "function myFunction() { return false; }" output &&
> +       test_i18ngrep "var myVar = function() { return false; }" output &&
> +       test_i18ngrep "var myVar = function() { return true; }" output
I think we try to use just test_grep instead of test_i18ngrep these days.
> +'
> +test_done
> \ No newline at end of file
Please add a new line at the end of this file if you still change it.
Thanks!
Christian Couder· Mar 2, 2024, 10:54 UTC · re: Christian Couder · lore

Re: [GSOC][PATCH] userdiff: Add JavaScript function patterns

On Sat, Mar 2, 2024 at 11:28 AM Christian Couder <christian.couder@gmail.com> wrote:

Show 10 quoted lines
>
> The subject should be "userdiff: add JavaScript function patterns" so
> with "add" instead of "Add". See the SubmittingPatches document which
> contains:
>
> "The title sentence after the "area:" prefix omits the full stop at the
> end, and its first word is not capitalized (the omission
> of capitalization applies only to the word after the "area:"
> prefix of the title) unless there is a reason to
> capitalize it other than because it is the first word in the sentence."

Also about the subject, please use v2, v3, v4 when you resend a patch or a patch series that you have already sent. `git format-patch` has a "-v <n>" or "--reroll-count=<n>" option for that purpose.

Junio C Hamano· Mar 2, 2024, 17:13 UTC · re: Christian Couder · lore

Re: [GSOC][PATCH] userdiff: Add JavaScript function patterns

Christian Couder <christian.couder@gmail.com> writes:
Show 7 quoted lines
>> +       # check results
>> +       test_i18ngrep "function myFunction() { return true; }" output &&
>> +       test_i18ngrep "function myFunction() { return false; }" output &&
>> +       test_i18ngrep "var myVar = function() { return false; }" output &&
>> +       test_i18ngrep "var myVar = function() { return true; }" output
>
> I think we try to use just test_grep instead of test_i18ngrep these days.
Thanks for reminding.  I am tempted to suggest doing this.
------ >8 ----------- >8 ----------- >8 ----------- >8 ------
Subject: test_i18ngrep: hard deprecate and forbid its use

Since v2.44.0-rc0~109 (Merge branch 'sp/test-i18ngrep', 2023-12-27) none of the tests we have, either in 'master' or in flight and collected in 'seen', use test_i18ngrep.

Perhaps it is good time to update test_i18ngrep to BUG to avoid people adding new calls to it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 t/test-lib-functions.sh | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git c/t/test-lib-functions.sh w/t/test-lib-functions.sh
index b5eaf7fdc1..6eaf116346 100644
--- c/t/test-lib-functions.sh
+++ w/t/test-lib-functions.sh
@@ -1263,9 +1263,8 @@ test_cmp_bin () {
 	cmp "$@"
 }
 
-# Deprecated - do not use this in new code
 test_i18ngrep () {
-	test_grep "$@"
+	BUG "do not use test_i18ngrep---use test_grep instead"
 }
 
 test_grep () {
Patrick Steinhardt· Mar 4, 2024, 09:04 UTC · re: Sergius Nyah · lore

Re: [GSOC][PATCH] userdiff: Add JavaScript function patterns

On Fri, Mar 01, 2024 at 08:40:48AM +0100, Sergius Nyah wrote:
Show 41 quoted lines
> This commit adds a patterns used to match JavaScript functions.
> It now correctly identifies function declarations, function expressions,
> and functions defined inside blocks. Add test for corresponding change in userdiff.
> 
> Signed-off-by: Sergius Nyah <sergiusnyah@gmail.com>
> ---
>  t/t4018-diff-funcname.sh | 22 ++++++++++++++++++++++
>  userdiff.c               | 12 ++++++++++++
>  2 files changed, 34 insertions(+)
> 
> diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
> index e026fac1f4..d35cce18a0 100755
> --- a/t/t4018-diff-funcname.sh
> +++ b/t/t4018-diff-funcname.sh
> @@ -120,3 +120,25 @@ do
>  done
> 
>  test_done
> +
> +test_expect_success 'identify builtin patterns in JavaScript' '
> +	# setup
> +	echo "function myFunction() { return true; }" > test.js &&
> +	echo "var myVar = function() { return false; }" >> test.js &&
> +	git add test.js &&
> +	git commit -m "add test.js" &&
> +
> +	# modify the file
> +	echo "function myFunction() { return false; }" > test.js &&
> +	echo "var myVar = function() { return true; }" >> test.js &&
> +
> +	# command under test
> +	git diff >output &&
> +
> +	# check results
> +	test_i18ngrep "function myFunction() { return true; }" output &&
> +	test_i18ngrep "function myFunction() { return false; }" output &&
> +	test_i18ngrep "var myVar = function() { return false; }" output &&
> +	test_i18ngrep "var myVar = function() { return true; }" output
> +'
> +test_done
> \ No newline at end of file

This `test_done` only needs to be added because you add the new test before the preceding `test_done`. Instead, you should move up this test so that it comes before it.

Show 6 quoted lines
> diff --git a/userdiff.c b/userdiff.c
> index 2b1dab2649..bbe2bcb9a3 100644
> --- a/userdiff.c
> +++ b/userdiff.c
> +PATTERNS("javascript",
> +      /* Looks for lines that start with optional whitespace, followed

Multi-line comments should start with their delimiters on separate lines. So the "/*" should be on its own line.

Also, the code should be indented with tabs and not spaces. It might help to read through Documentation/CodingGuidelines to get more familiar with Git's coding style.

Patrick
Show 13 quoted lines
> +      * by 'function'* and any characters (for function declarations),
> +      * or valid JavaScript identifiers, equals sign '=', 'function' keyword
> +      * and any characters (for function expressions).
> +      * Also considers functions defined inside blocks with '{...}'.
> +      */
> +      "^[ \t]*(function[ \t]*.*|[a-zA-Z_$][0-9a-zA-Z_$]*[ \t]*=[ \t]*function[ \t]*.*|(\\{[ \t]*)?)\n",
> +      /* This pattern matches JavaScript identifiers */
> +      "[a-zA-Z_$][0-9a-zA-Z_$]*"
> +      "|[-+0-9.eE]+|0[xX][0-9a-fA-F]+"
> +      "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\|"),
> --
> 2.43.2
> 
Sergius Nyah· Mar 12, 2024, 13:14 UTC · re: Patrick Steinhardt · lore

[GSOC][PATCH v2 1/3]t4018-diff-funcname: use test_grep instead of test_i18ngrep

Signed-off-by: Sergius Nyah <sergiusnyah@gmail.com>
---
 t/t4018-diff-funcname.sh | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index d35cce18a0..e6d2f1c215 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -119,8 +119,6 @@ do
 	"
 done

-test_done
-
 test_expect_success 'identify builtin patterns in JavaScript' '
 	# setup
 	echo "function myFunction() { return true; }" > test.js &&
@@ -136,9 +134,11 @@ test_expect_success 'identify builtin patterns in JavaScript' '
 	git diff >output &&

 	# check results
-	test_i18ngrep "function myFunction() { return true; }" output &&
-	test_i18ngrep "function myFunction() { return false; }" output &&
-	test_i18ngrep "var myVar = function() { return false; }" output &&
-	test_i18ngrep "var myVar = function() { return true; }" output
+	test_grep "function myFunction() { return true; }" output &&
+	test_grep "function myFunction() { return false; }" output &&
+	test_grep "var myVar = function() { return false; }" output &&
+	test_grep "var myVar = function() { return true; }" output
 '
-test_done
\ No newline at end of file
+
+test_done
+
--
2.43.2
Sergius Nyah· Mar 12, 2024, 13:14 UTC · re: Sergius Nyah · lore

[GSOC][PATCH v2 2/3]t4034-diff-words: add javascript language driver

---
 t/t4034-diff-words.sh | 1 +
 1 file changed, 1 insertion(+)
diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh
index 74586f3813..cf2374af2c 100755
--- a/t/t4034-diff-words.sh
+++ b/t/t4034-diff-words.sh
@@ -328,6 +328,7 @@ test_language_driver dts
 test_language_driver fortran
 test_language_driver html
 test_language_driver java
+test_language_driver javascript
 test_language_driver kotlin
 test_language_driver matlab
 test_language_driver objc
--
2.43.2
Sergius Nyah· Mar 12, 2024, 13:14 UTC · re: Sergius Nyah · lore

[GSOC][PATCH v2 3/3]userdiff: remove trailing whitespaces, fix multiline comments

This patch removes trailing whitespaces and fixes multiline comments in the `userdiff.c` file to match Gits coding standards as seen in [1].

Signed-off-by: Sergius Nyah <sergiusnyah@gmail.com>
---
 userdiff.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/userdiff.c b/userdiff.c
index bbe2bcb9a3..15342c8662 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -184,17 +184,18 @@ PATTERNS("java",
 	 "|[-+*/<>%&^|=!]="
 	 "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
 PATTERNS("javascript",
-      /* Looks for lines that start with optional whitespace, followed
-      * by 'function'* and any characters (for function declarations),
-      * or valid JavaScript identifiers, equals sign '=', 'function' keyword
-      * and any characters (for function expressions).
-      * Also considers functions defined inside blocks with '{...}'.
-      */
-      "^[ \t]*(function[ \t]*.*|[a-zA-Z_$][0-9a-zA-Z_$]*[ \t]*=[ \t]*function[ \t]*.*|(\\{[ \t]*)?)\n",
-      /* This pattern matches JavaScript identifiers */
-      "[a-zA-Z_$][0-9a-zA-Z_$]*"
-      "|[-+0-9.eE]+|0[xX][0-9a-fA-F]+"
-      "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\|"),
+	/*
+	 * Look for lines that start with optional whitespace, followed
+	 * by 'function' and any characters (for function declarations),
+	 * or valid JavaScript identifiers, equals sign '=', 'function' keyword
+	 * and any characters (for function expressions).
+	 * Also consider functions defined inside blocks with '{...}'.
+	 */
+	 "^[ \t]*(function[ \t]*.*|[a-zA-Z_$][0-9a-zA-Z_$]*[ \t]*=[ \t]*function[ \t]*.*|(\\{[ \t]*)?)\n",
+	 /* Match JavaScript identifiers with this pattern */
+	 "[a-zA-Z_$][0-9a-zA-Z_$]*"
+	 "|[-+0-9.eE]+|0[xX][0-9a-fA-F]+"
+	 "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\|"),
 PATTERNS("kotlin",
 	 "^[ \t]*(([a-z]+[ \t]+)*(fun|class|interface)[ \t]+.*)$",
 	 /* -- */
--
2.43.2

[1]:
https://github.com/git/git/blob/master/Documentation/CodingGuidelines
Sergius Nyah· Mar 19, 2024, 10:10 UTC · re: Patrick Steinhardt · lore

[GSOC][PATCH v2]userdiff: improve code quality and add JavaScript language driver.

This commit introduces several improvements to the codebase:
- replace the use of `test_i18ngrep` with `test_grep` in
`t/t4018-diff-funcname.sh` for better pattern matching and improved
performance.
- add a JavaScript language driver to enhance the functionality of the
application.
- clean up the code by removing trailing whitespaces and fix multiline
comments in `t/t4034-diff-words.sh` and `userdiff.c`.
Signed-off-by: Sergius Nyah <sergiusnyah@gmail.com>
---
 t/t4018-diff-funcname.sh | 14 +++++++-------
 t/t4034-diff-words.sh    |  1 +
 userdiff.c               | 23 ++++++++++++-----------
 3 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index d35cce18a0..e6d2f1c215 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -119,8 +119,6 @@ do
 	"
 done

-test_done
-
 test_expect_success 'identify builtin patterns in JavaScript' '
 	# setup
 	echo "function myFunction() { return true; }" > test.js &&
@@ -136,9 +134,11 @@ test_expect_success 'identify builtin patterns in JavaScript' '
 	git diff >output &&

 	# check results
-	test_i18ngrep "function myFunction() { return true; }" output &&
-	test_i18ngrep "function myFunction() { return false; }" output &&
-	test_i18ngrep "var myVar = function() { return false; }" output &&
-	test_i18ngrep "var myVar = function() { return true; }" output
+	test_grep "function myFunction() { return true; }" output &&
+	test_grep "function myFunction() { return false; }" output &&
+	test_grep "var myVar = function() { return false; }" output &&
+	test_grep "var myVar = function() { return true; }" output
 '
-test_done
\ No newline at end of file
+
+test_done
+
diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh
index 74586f3813..cf2374af2c 100755
--- a/t/t4034-diff-words.sh
+++ b/t/t4034-diff-words.sh
@@ -328,6 +328,7 @@ test_language_driver dts
 test_language_driver fortran
 test_language_driver html
 test_language_driver java
+test_language_driver javascript
 test_language_driver kotlin
 test_language_driver matlab
 test_language_driver objc
diff --git a/userdiff.c b/userdiff.c
index bbe2bcb9a3..15342c8662 100644
--- a/userdiff.c
+++ b/userdiff.c

 PATTERNS("javascript",
-      /* Looks for lines that start with optional whitespace, followed
-      * by 'function'* and any characters (for function declarations),
-      * or valid JavaScript identifiers, equals sign '=', 'function' keyword
-      * and any characters (for function expressions).
-      * Also considers functions defined inside blocks with '{...}'.
-      */
-      "^[ \t]*(function[ \t]*.*|[a-zA-Z_$][0-9a-zA-Z_$]*[ \t]*=[ \t]*function[ \t]*.*|(\\{[ \t]*)?)\n",
-      /* This pattern matches JavaScript identifiers */
-      "[a-zA-Z_$][0-9a-zA-Z_$]*"
-      "|[-+0-9.eE]+|0[xX][0-9a-fA-F]+"
-      "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\|"),
+	/*
+	 * Look for lines that start with optional whitespace, followed
+	 * by 'function' and any characters (for function declarations),
+	 * or valid JavaScript identifiers, equals sign '=', 'function' keyword
+	 * and any characters (for function expressions).
+	 * Also consider functions defined inside blocks with '{...}'.
+	 */
+	 "^[ \t]*(function[ \t]*.*|[a-zA-Z_$][0-9a-zA-Z_$]*[ \t]*=[ \t]*function[ \t]*.*|(\\{[ \t]*)?)\n",
+	 /* Match JavaScript identifiers with this pattern */
+	 "[a-zA-Z_$][0-9a-zA-Z_$]*"
+	 "|[-+0-9.eE]+|0[xX][0-9a-fA-F]+"
+	 "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\|"),

2.43.2
Junio C Hamano· Mar 19, 2024, 21:02 UTC · re: Sergius Nyah · lore

Re: [GSOC][PATCH v2]userdiff: improve code quality and add JavaScript language driver.

Sergius Nyah <sergiusnyah@gmail.com> writes:
Show 9 quoted lines
> This commit introduces several improvements to the codebase:
>
> - replace the use of `test_i18ngrep` with `test_grep` in
> `t/t4018-diff-funcname.sh` for better pattern matching and improved
> performance.
> - add a JavaScript language driver to enhance the functionality of the
> application.
> - clean up the code by removing trailing whitespaces and fix multiline
> comments in `t/t4034-diff-words.sh` and `userdiff.c`.

Doing too many unrelated things that may appear semi-related only because they are about the same files? Don't.

Show 39 quoted lines
>
> Signed-off-by: Sergius Nyah <sergiusnyah@gmail.com>
> ---
>  t/t4018-diff-funcname.sh | 14 +++++++-------
>  t/t4034-diff-words.sh    |  1 +
>  userdiff.c               | 23 ++++++++++++-----------
>  3 files changed, 20 insertions(+), 18 deletions(-)
>
> diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
> index d35cce18a0..e6d2f1c215 100755
> --- a/t/t4018-diff-funcname.sh
> +++ b/t/t4018-diff-funcname.sh
> @@ -119,8 +119,6 @@ do
>  	"
>  done
>
> -test_done
> -
>  test_expect_success 'identify builtin patterns in JavaScript' '
>  	# setup
>  	echo "function myFunction() { return true; }" > test.js &&
> @@ -136,9 +134,11 @@ test_expect_success 'identify builtin patterns in JavaScript' '
>  	git diff >output &&
>
>  	# check results
> -	test_i18ngrep "function myFunction() { return true; }" output &&
> -	test_i18ngrep "function myFunction() { return false; }" output &&
> -	test_i18ngrep "var myVar = function() { return false; }" output &&
> -	test_i18ngrep "var myVar = function() { return true; }" output
> +	test_grep "function myFunction() { return true; }" output &&
> +	test_grep "function myFunction() { return false; }" output &&
> +	test_grep "var myVar = function() { return false; }" output &&
> +	test_grep "var myVar = function() { return true; }" output
>  '
> -test_done
> \ No newline at end of file
> +
> +test_done
> +

To which version of Git source code are the above hunks meant to apply? Hopefully we do not have a test that says "test_done" followed by another "test_expect_success" in our tree.

Show 12 quoted lines
> diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh
> index 74586f3813..cf2374af2c 100755
> --- a/t/t4034-diff-words.sh
> +++ b/t/t4034-diff-words.sh
> @@ -328,6 +328,7 @@ test_language_driver dts
>  test_language_driver fortran
>  test_language_driver html
>  test_language_driver java
> +test_language_driver javascript
>  test_language_driver kotlin
>  test_language_driver matlab
>  test_language_driver objc

It is unclear what "clean-up" was done to this file, as claimed in the proposed log message. Puzzled...

Show 29 quoted lines
> diff --git a/userdiff.c b/userdiff.c
> index bbe2bcb9a3..15342c8662 100644
> --- a/userdiff.c
> +++ b/userdiff.c
>
>  PATTERNS("javascript",
> -      /* Looks for lines that start with optional whitespace, followed
> -      * by 'function'* and any characters (for function declarations),
> -      * or valid JavaScript identifiers, equals sign '=', 'function' keyword
> -      * and any characters (for function expressions).
> -      * Also considers functions defined inside blocks with '{...}'.
> -      */
> -      "^[ \t]*(function[ \t]*.*|[a-zA-Z_$][0-9a-zA-Z_$]*[ \t]*=[ \t]*function[ \t]*.*|(\\{[ \t]*)?)\n",
> -      /* This pattern matches JavaScript identifiers */
> -      "[a-zA-Z_$][0-9a-zA-Z_$]*"
> -      "|[-+0-9.eE]+|0[xX][0-9a-fA-F]+"
> -      "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\|"),
> +	/*
> +	 * Look for lines that start with optional whitespace, followed
> +	 * by 'function' and any characters (for function declarations),
> +	 * or valid JavaScript identifiers, equals sign '=', 'function' keyword
> +	 * and any characters (for function expressions).
> +	 * Also consider functions defined inside blocks with '{...}'.
> +	 */
> +	 "^[ \t]*(function[ \t]*.*|[a-zA-Z_$][0-9a-zA-Z_$]*[ \t]*=[ \t]*function[ \t]*.*|(\\{[ \t]*)?)\n",
> +	 /* Match JavaScript identifiers with this pattern */
> +	 "[a-zA-Z_$][0-9a-zA-Z_$]*"
> +	 "|[-+0-9.eE]+|0[xX][0-9a-fA-F]+"
> +	 "|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\|"),

I do not see trailing whitespaces getting fixed, as claimed in the proposed log message. Puzzled, again...

← back to recent threads