All of lore.kernel.org
 help / color / mirror / Atom feed
* [GSOC][RFC] Add more builtin patterns for userdiff, as Mircroproject.
@ 2024-01-09 19:55 Sergius Nyah
  2024-01-10 11:33 ` Christian Couder
  0 siblings, 1 reply; 33+ messages in thread
From: Sergius Nyah @ 2024-01-09 19:55 UTC (permalink / raw)
  To: git, gitster

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`:

> #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.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [GSOC][RFC] Add more builtin patterns for userdiff, as Mircroproject.
  2024-01-09 19:55 [GSOC][RFC] Add more builtin patterns for userdiff, as Mircroproject Sergius Nyah
@ 2024-01-10 11:33 ` Christian Couder
       [not found]   ` <CANAnif90Bqp2pWCn_71t-Fss6wspo+==vMdYsX+Wt5m=4Ocpng@mail.gmail.com>
  0 siblings, 1 reply; 33+ messages in thread
From: Christian Couder @ 2024-01-10 11:33 UTC (permalink / raw)
  To: Sergius Nyah; +Cc: git, gitster

Hi Sergius,

On Tue, Jan 9, 2024 at 8:59 PM Sergius Nyah <sergiusnyah@gmail.com> wrote:
>
> 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.

> 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.

> 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.

> 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.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Fwd: [GSOC][RFC] Add more builtin patterns for userdiff, as Mircroproject.
       [not found]       ` <CAP8UFD3e=Zv2wkx5tswCz05Vwn3vD68Vw-TD6SoENWK+norYsw@mail.gmail.com>
@ 2024-01-11 14:23         ` Sergius Nyah
  2024-01-11 15:11           ` Christian Couder
  0 siblings, 1 reply; 33+ messages in thread
From: Sergius Nyah @ 2024-01-11 14:23 UTC (permalink / raw)
  To: Christian Couder; +Cc: git, gitster, newren, l.s.r

---------- 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.
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.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [GSOC][RFC] Add more builtin patterns for userdiff, as Mircroproject.
  2024-01-11 14:23         ` Fwd: " Sergius Nyah
@ 2024-01-11 15:11           ` Christian Couder
  2024-01-11 15:42             ` Sergius Nyah
  0 siblings, 1 reply; 33+ messages in thread
From: Christian Couder @ 2024-01-11 15:11 UTC (permalink / raw)
  To: Sergius Nyah; +Cc: git, gitster, newren, l.s.r

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
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

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [GSOC][RFC] Add more builtin patterns for userdiff, as Mircroproject.
  2024-01-11 15:11           ` Christian Couder
@ 2024-01-11 15:42             ` Sergius Nyah
  2024-02-27 14:19               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
                                 ` (4 more replies)
  0 siblings, 5 replies; 33+ messages in thread
From: Sergius Nyah @ 2024-01-11 15:42 UTC (permalink / raw)
  To: Christian Couder; +Cc: git, gitster, newren, l.s.r

On Thu, Jan 11, 2024 at 4:11 PM Christian Couder
<christian.couder@gmail.com> wrote:
>
> 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.

> 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!

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject.
  2024-01-11 15:42             ` Sergius Nyah
@ 2024-02-27 14:19               ` Sergius Nyah
  2024-02-27 14:19                 ` [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff Sergius Nyah
  2024-02-27 14:19                 ` [PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs Sergius Nyah
  2024-02-27 14:21               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
                                 ` (3 subsequent siblings)
  4 siblings, 2 replies; 33+ messages in thread
From: Sergius Nyah @ 2024-02-27 14:19 UTC (permalink / raw)
  To: christian.couder, pk; +Cc: git, Sergius Nyah

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.


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff.
  2024-02-27 14:19               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
@ 2024-02-27 14:19                 ` Sergius Nyah
  2024-02-27 14:19                 ` [PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs Sergius Nyah
  1 sibling, 0 replies; 33+ messages in thread
From: Sergius Nyah @ 2024-02-27 14:19 UTC (permalink / raw)
  To: christian.couder, pk; +Cc: git, Sergius Justus Chesami Nyah

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


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs
  2024-02-27 14:19               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
  2024-02-27 14:19                 ` [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff Sergius Nyah
@ 2024-02-27 14:19                 ` Sergius Nyah
  1 sibling, 0 replies; 33+ messages in thread
From: Sergius Nyah @ 2024-02-27 14:19 UTC (permalink / raw)
  To: christian.couder, pk; +Cc: git, Sergius Justus Chesami Nyah

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


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject.
  2024-01-11 15:42             ` Sergius Nyah
  2024-02-27 14:19               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
@ 2024-02-27 14:21               ` Sergius Nyah
  2024-02-27 14:21                 ` [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff Sergius Nyah
  2024-02-27 14:21                 ` [PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs Sergius Nyah
  2024-02-27 14:25               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
                                 ` (2 subsequent siblings)
  4 siblings, 2 replies; 33+ messages in thread
From: Sergius Nyah @ 2024-02-27 14:21 UTC (permalink / raw)
  To: christian.couder, pk; +Cc: git, Sergius Nyah

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.


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff.
  2024-02-27 14:21               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
@ 2024-02-27 14:21                 ` Sergius Nyah
  2024-02-27 14:21                 ` [PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs Sergius Nyah
  1 sibling, 0 replies; 33+ messages in thread
From: Sergius Nyah @ 2024-02-27 14:21 UTC (permalink / raw)
  To: christian.couder, pk; +Cc: git, Sergius Justus Chesami Nyah

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


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs
  2024-02-27 14:21               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
  2024-02-27 14:21                 ` [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff Sergius Nyah
@ 2024-02-27 14:21                 ` Sergius Nyah
  1 sibling, 0 replies; 33+ messages in thread
From: Sergius Nyah @ 2024-02-27 14:21 UTC (permalink / raw)
  To: christian.couder, pk; +Cc: git, Sergius Justus Chesami Nyah

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


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject.
  2024-01-11 15:42             ` Sergius Nyah
  2024-02-27 14:19               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
  2024-02-27 14:21               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
@ 2024-02-27 14:25               ` Sergius Nyah
  2024-02-27 14:25                 ` [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff Sergius Nyah
  2024-02-27 14:25                 ` [PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs Sergius Nyah
  2024-02-27 16:02               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
  2024-02-28 15:00               ` [GSOC][PATCH] Userdiff: add builtin patterns for JavaScript Sergius Nyah
  4 siblings, 2 replies; 33+ messages in thread
From: Sergius Nyah @ 2024-02-27 14:25 UTC (permalink / raw)
  To: christian.couder, pk; +Cc: git, Sergius Nyah

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.


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff.
  2024-02-27 14:25               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
@ 2024-02-27 14:25                 ` Sergius Nyah
  2024-02-27 14:25                 ` [PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs Sergius Nyah
  1 sibling, 0 replies; 33+ messages in thread
From: Sergius Nyah @ 2024-02-27 14:25 UTC (permalink / raw)
  To: christian.couder, pk; +Cc: git, Sergius Justus Chesami Nyah

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


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs
  2024-02-27 14:25               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
  2024-02-27 14:25                 ` [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff Sergius Nyah
@ 2024-02-27 14:25                 ` Sergius Nyah
  1 sibling, 0 replies; 33+ messages in thread
From: Sergius Nyah @ 2024-02-27 14:25 UTC (permalink / raw)
  To: christian.couder, pk; +Cc: git, Sergius Justus Chesami Nyah

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


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject.
  2024-01-11 15:42             ` Sergius Nyah
                                 ` (2 preceding siblings ...)
  2024-02-27 14:25               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
@ 2024-02-27 16:02               ` Sergius Nyah
  2024-02-27 16:02                 ` [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff Sergius Nyah
  2024-02-27 16:02                 ` [PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs Sergius Nyah
  2024-02-28 15:00               ` [GSOC][PATCH] Userdiff: add builtin patterns for JavaScript Sergius Nyah
  4 siblings, 2 replies; 33+ messages in thread
From: Sergius Nyah @ 2024-02-27 16:02 UTC (permalink / raw)
  To: christian.couder, pk; +Cc: git, Sergius Nyah

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.


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff.
  2024-02-27 16:02               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
@ 2024-02-27 16:02                 ` Sergius Nyah
  2024-02-27 19:06                   ` Ghanshyam Thakkar
  2024-02-27 16:02                 ` [PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs Sergius Nyah
  1 sibling, 1 reply; 33+ messages in thread
From: Sergius Nyah @ 2024-02-27 16:02 UTC (permalink / raw)
  To: christian.couder, pk; +Cc: git, Sergius Nyah

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



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs
  2024-02-27 16:02               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
  2024-02-27 16:02                 ` [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff Sergius Nyah
@ 2024-02-27 16:02                 ` Sergius Nyah
  1 sibling, 0 replies; 33+ messages in thread
From: Sergius Nyah @ 2024-02-27 16:02 UTC (permalink / raw)
  To: christian.couder, pk; +Cc: git, Sergius Justus Chesami Nyah

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



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* Re: [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff.
  2024-02-27 16:02                 ` [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff Sergius Nyah
@ 2024-02-27 19:06                   ` Ghanshyam Thakkar
  2024-02-27 21:05                     ` Sergius Nyah
  0 siblings, 1 reply; 33+ messages in thread
From: Ghanshyam Thakkar @ 2024-02-27 19:06 UTC (permalink / raw)
  To: Sergius Nyah, christian.couder, pk; +Cc: git

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.
> ---
>  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.

>  #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)

>  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.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff.
  2024-02-27 19:06                   ` Ghanshyam Thakkar
@ 2024-02-27 21:05                     ` Sergius Nyah
  0 siblings, 0 replies; 33+ messages in thread
From: Sergius Nyah @ 2024-02-27 21:05 UTC (permalink / raw)
  To: Ghanshyam Thakkar; +Cc: christian.couder, pk, git

On Tue, Feb 27, 2024 at 8:06 PM Ghanshyam Thakkar
<shyamthakkar001@gmail.com> wrote:
>
> 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.

> >  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.
> >  #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!
>
> >  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.
>
> 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.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [GSOC][PATCH] Userdiff: add builtin patterns for JavaScript.
  2024-01-11 15:42             ` Sergius Nyah
                                 ` (3 preceding siblings ...)
  2024-02-27 16:02               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
@ 2024-02-28 15:00               ` Sergius Nyah
  2024-02-28 18:19                 ` Junio C Hamano
  4 siblings, 1 reply; 33+ messages in thread
From: Sergius Nyah @ 2024-02-28 15:00 UTC (permalink / raw)
  To: git, christian.couder; +Cc: pk, shyamthakkar001, Sergius Nyah

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

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [GSOC][PATCH] Userdiff: add builtin patterns for JavaScript.
  2024-02-28 15:00               ` [GSOC][PATCH] Userdiff: add builtin patterns for JavaScript Sergius Nyah
@ 2024-02-28 18:19                 ` Junio C Hamano
  2024-02-29 10:11                   ` [GSOC][PATCH] userdiff: " Sergius Nyah
  2024-03-01  7:40                   ` [GSOC][PATCH] userdiff: Add JavaScript function patterns Sergius Nyah
  0 siblings, 2 replies; 33+ messages in thread
From: Junio C Hamano @ 2024-02-28 18:19 UTC (permalink / raw)
  To: Sergius Nyah; +Cc: git, christian.couder, pk, shyamthakkar001

Sergius Nyah <sergiusnyah@gmail.com> writes:

> 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.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [GSOC][PATCH] userdiff: add builtin patterns for JavaScript.
  2024-02-28 18:19                 ` Junio C Hamano
@ 2024-02-29 10:11                   ` Sergius Nyah
  2024-02-29 12:01                     ` Ghanshyam Thakkar
  2024-03-01  7:40                   ` [GSOC][PATCH] userdiff: Add JavaScript function patterns Sergius Nyah
  1 sibling, 1 reply; 33+ messages in thread
From: Sergius Nyah @ 2024-02-29 10:11 UTC (permalink / raw)
  To: git, christian.couder, gitster; +Cc: pk, shyamthakkar001, Sergius Nyah

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

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* Re: [GSOC][PATCH] userdiff: add builtin patterns for JavaScript.
  2024-02-29 10:11                   ` [GSOC][PATCH] userdiff: " Sergius Nyah
@ 2024-02-29 12:01                     ` Ghanshyam Thakkar
  0 siblings, 0 replies; 33+ messages in thread
From: Ghanshyam Thakkar @ 2024-02-29 12:01 UTC (permalink / raw)
  To: Sergius Nyah, git, christian.couder, gitster; +Cc: pk

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 ..."

> 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.
> 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


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [GSOC][PATCH] userdiff: Add JavaScript function patterns
  2024-02-28 18:19                 ` Junio C Hamano
  2024-02-29 10:11                   ` [GSOC][PATCH] userdiff: " Sergius Nyah
@ 2024-03-01  7:40                   ` Sergius Nyah
  2024-03-02 10:28                     ` Christian Couder
  2024-03-04  9:04                     ` Patrick Steinhardt
  1 sibling, 2 replies; 33+ messages in thread
From: Sergius Nyah @ 2024-03-01  7:40 UTC (permalink / raw)
  To: git, christian.couder, gitster; +Cc: pk, shyamthakkar001, Sergius Nyah

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


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* Re: [GSOC][PATCH] userdiff: Add JavaScript function patterns
  2024-03-01  7:40                   ` [GSOC][PATCH] userdiff: Add JavaScript function patterns Sergius Nyah
@ 2024-03-02 10:28                     ` Christian Couder
  2024-03-02 10:54                       ` Christian Couder
  2024-03-02 17:13                       ` Junio C Hamano
  2024-03-04  9:04                     ` Patrick Steinhardt
  1 sibling, 2 replies; 33+ messages in thread
From: Christian Couder @ 2024-03-02 10:28 UTC (permalink / raw)
  To: Sergius Nyah; +Cc: git, gitster, pk, shyamthakkar001

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."

> 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.

> 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!

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [GSOC][PATCH] userdiff: Add JavaScript function patterns
  2024-03-02 10:28                     ` Christian Couder
@ 2024-03-02 10:54                       ` Christian Couder
  2024-03-02 17:13                       ` Junio C Hamano
  1 sibling, 0 replies; 33+ messages in thread
From: Christian Couder @ 2024-03-02 10:54 UTC (permalink / raw)
  To: Sergius Nyah; +Cc: git, gitster, pk, shyamthakkar001

On Sat, Mar 2, 2024 at 11:28 AM Christian Couder
<christian.couder@gmail.com> wrote:
>
> 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.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [GSOC][PATCH] userdiff: Add JavaScript function patterns
  2024-03-02 10:28                     ` Christian Couder
  2024-03-02 10:54                       ` Christian Couder
@ 2024-03-02 17:13                       ` Junio C Hamano
  1 sibling, 0 replies; 33+ messages in thread
From: Junio C Hamano @ 2024-03-02 17:13 UTC (permalink / raw)
  To: Christian Couder; +Cc: Sergius Nyah, git, pk, shyamthakkar001

Christian Couder <christian.couder@gmail.com> writes:

>> +       # 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 () {

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* Re: [GSOC][PATCH] userdiff: Add JavaScript function patterns
  2024-03-01  7:40                   ` [GSOC][PATCH] userdiff: Add JavaScript function patterns Sergius Nyah
  2024-03-02 10:28                     ` Christian Couder
@ 2024-03-04  9:04                     ` Patrick Steinhardt
  2024-03-12 13:14                       ` [GSOC][PATCH v2 1/3]t4018-diff-funcname: use test_grep instead of test_i18ngrep Sergius Nyah
  2024-03-19 10:10                       ` [GSOC][PATCH v2]userdiff: improve code quality and add JavaScript language driver Sergius Nyah
  1 sibling, 2 replies; 33+ messages in thread
From: Patrick Steinhardt @ 2024-03-04  9:04 UTC (permalink / raw)
  To: Sergius Nyah; +Cc: git, christian.couder, gitster, pk, shyamthakkar001

[-- Attachment #1: Type: text/plain, Size: 2914 bytes --]

On Fri, Mar 01, 2024 at 08:40:48AM +0100, Sergius Nyah wrote:
> 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.

> 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

> +      * 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
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [GSOC][PATCH v2 1/3]t4018-diff-funcname: use test_grep instead of test_i18ngrep
  2024-03-04  9:04                     ` Patrick Steinhardt
@ 2024-03-12 13:14                       ` Sergius Nyah
  2024-03-12 13:14                         ` [GSOC][PATCH v2 2/3]t4034-diff-words: add javascript language driver Sergius Nyah
  2024-03-12 13:14                         ` [GSOC][PATCH v2 3/3]userdiff: remove trailing whitespaces, fix multiline comments Sergius Nyah
  2024-03-19 10:10                       ` [GSOC][PATCH v2]userdiff: improve code quality and add JavaScript language driver Sergius Nyah
  1 sibling, 2 replies; 33+ messages in thread
From: Sergius Nyah @ 2024-03-12 13:14 UTC (permalink / raw)
  To: git; +Cc: gitster, christian.couder, pk, Sergius Nyah

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


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [GSOC][PATCH v2 2/3]t4034-diff-words: add javascript language driver
  2024-03-12 13:14                       ` [GSOC][PATCH v2 1/3]t4018-diff-funcname: use test_grep instead of test_i18ngrep Sergius Nyah
@ 2024-03-12 13:14                         ` Sergius Nyah
  2024-03-12 13:14                         ` [GSOC][PATCH v2 3/3]userdiff: remove trailing whitespaces, fix multiline comments Sergius Nyah
  1 sibling, 0 replies; 33+ messages in thread
From: Sergius Nyah @ 2024-03-12 13:14 UTC (permalink / raw)
  To: git; +Cc: gitster, christian.couder, pk, Sergius Nyah

---
 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


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [GSOC][PATCH v2 3/3]userdiff: remove trailing whitespaces, fix multiline comments
  2024-03-12 13:14                       ` [GSOC][PATCH v2 1/3]t4018-diff-funcname: use test_grep instead of test_i18ngrep Sergius Nyah
  2024-03-12 13:14                         ` [GSOC][PATCH v2 2/3]t4034-diff-words: add javascript language driver Sergius Nyah
@ 2024-03-12 13:14                         ` Sergius Nyah
  1 sibling, 0 replies; 33+ messages in thread
From: Sergius Nyah @ 2024-03-12 13:14 UTC (permalink / raw)
  To: git; +Cc: gitster, christian.couder, pk, Sergius Nyah

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

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [GSOC][PATCH v2]userdiff: improve code quality and add JavaScript language driver.
  2024-03-04  9:04                     ` Patrick Steinhardt
  2024-03-12 13:14                       ` [GSOC][PATCH v2 1/3]t4018-diff-funcname: use test_grep instead of test_i18ngrep Sergius Nyah
@ 2024-03-19 10:10                       ` Sergius Nyah
  2024-03-19 21:02                         ` Junio C Hamano
  1 sibling, 1 reply; 33+ messages in thread
From: Sergius Nyah @ 2024-03-19 10:10 UTC (permalink / raw)
  To: git; +Cc: gitster, christian.couder, pk, Sergius Nyah

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


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* Re: [GSOC][PATCH v2]userdiff: improve code quality and add JavaScript language driver.
  2024-03-19 10:10                       ` [GSOC][PATCH v2]userdiff: improve code quality and add JavaScript language driver Sergius Nyah
@ 2024-03-19 21:02                         ` Junio C Hamano
  0 siblings, 0 replies; 33+ messages in thread
From: Junio C Hamano @ 2024-03-19 21:02 UTC (permalink / raw)
  To: Sergius Nyah; +Cc: git, christian.couder, pk

Sergius Nyah <sergiusnyah@gmail.com> writes:

> 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.

>
> 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.

> 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...

> 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...



^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2024-03-19 21:02 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-09 19:55 [GSOC][RFC] Add more builtin patterns for userdiff, as Mircroproject Sergius Nyah
2024-01-10 11:33 ` Christian Couder
     [not found]   ` <CANAnif90Bqp2pWCn_71t-Fss6wspo+==vMdYsX+Wt5m=4Ocpng@mail.gmail.com>
     [not found]     ` <CAP8UFD0ELy2WegVYdxi_O5UpHS4MyOPp4tuAQK+XvvNmABc2ZA@mail.gmail.com>
     [not found]       ` <CAP8UFD3e=Zv2wkx5tswCz05Vwn3vD68Vw-TD6SoENWK+norYsw@mail.gmail.com>
2024-01-11 14:23         ` Fwd: " Sergius Nyah
2024-01-11 15:11           ` Christian Couder
2024-01-11 15:42             ` Sergius Nyah
2024-02-27 14:19               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
2024-02-27 14:19                 ` [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff Sergius Nyah
2024-02-27 14:19                 ` [PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs Sergius Nyah
2024-02-27 14:21               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
2024-02-27 14:21                 ` [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff Sergius Nyah
2024-02-27 14:21                 ` [PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs Sergius Nyah
2024-02-27 14:25               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
2024-02-27 14:25                 ` [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff Sergius Nyah
2024-02-27 14:25                 ` [PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs Sergius Nyah
2024-02-27 16:02               ` [GSOC][PATCH 0/2] Add builtin patterns for userdiff in JavaScript, as Microproject Sergius Nyah
2024-02-27 16:02                 ` [PATCH 1/2] Subject: [GSOC][RFC PATCH 1/2] Add builtin patterns for JavaScript function detection in userdiff Sergius Nyah
2024-02-27 19:06                   ` Ghanshyam Thakkar
2024-02-27 21:05                     ` Sergius Nyah
2024-02-27 16:02                 ` [PATCH 2/2] Subject:[GSOC] [RFC PATCH 2/2] Add test for JavaScript function detection in Git diffs Sergius Nyah
2024-02-28 15:00               ` [GSOC][PATCH] Userdiff: add builtin patterns for JavaScript Sergius Nyah
2024-02-28 18:19                 ` Junio C Hamano
2024-02-29 10:11                   ` [GSOC][PATCH] userdiff: " Sergius Nyah
2024-02-29 12:01                     ` Ghanshyam Thakkar
2024-03-01  7:40                   ` [GSOC][PATCH] userdiff: Add JavaScript function patterns Sergius Nyah
2024-03-02 10:28                     ` Christian Couder
2024-03-02 10:54                       ` Christian Couder
2024-03-02 17:13                       ` Junio C Hamano
2024-03-04  9:04                     ` Patrick Steinhardt
2024-03-12 13:14                       ` [GSOC][PATCH v2 1/3]t4018-diff-funcname: use test_grep instead of test_i18ngrep Sergius Nyah
2024-03-12 13:14                         ` [GSOC][PATCH v2 2/3]t4034-diff-words: add javascript language driver Sergius Nyah
2024-03-12 13:14                         ` [GSOC][PATCH v2 3/3]userdiff: remove trailing whitespaces, fix multiline comments Sergius Nyah
2024-03-19 10:10                       ` [GSOC][PATCH v2]userdiff: improve code quality and add JavaScript language driver Sergius Nyah
2024-03-19 21:02                         ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.