threads / patch / 24704

patchUserdiff patterns for C#

Subject: [PATCH] Userdiff patterns for C#

## tl;dr

5 messages between Aug 11, 2010 and Aug 22, 2010. Diffs are folded; open one to read it.

replies: 4people: 3as markdown or json

Petr Onderka· Aug 11, 2010, 01:09 UTC · lore

Add userdiff patterns for C#. This code is an improved version of code by Adam Petaccia from 21 June 2009 mail to the list.

Signed-off-by: Petr Onderka <gsvick@gmail.com>
---
I was looking how to properly set up hunk-headers for C# and found
a mail from Adam Petaccia to this list, that almost did what I wanted.
It was never included, so I improved it and I hope it can be added
to the official repository now.
 t/t4018-diff-funcname.sh |    2 +-
 userdiff.c               |   16 ++++++++++++++++
 2 files changed, 17 insertions(+), 1 deletions(-)
Show changes to 2 files +17 −1

t/t4018-diff-funcname.sh, userdiff.c

diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index 5b10e97..61de8a2 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -32,7 +32,7 @@ EOF
 
 sed 's/beer\\/beer,\\/' < Beer.java > Beer-correct.java
 
-builtin_patterns="bibtex cpp html java objc pascal php python ruby tex"
+builtin_patterns="bibtex cpp csharp html java objc pascal php python ruby tex"
 for p in $builtin_patterns
 do
 	test_expect_success "builtin $p pattern compiles" '
diff --git a/userdiff.c b/userdiff.c
index c49cc1b..e552215 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -82,6 +82,22 @@ PATTERNS("cpp",
 	 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
 	 "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"
 	 "|[^[:space:]]|[\x80-\xff]+"),
+PATTERNS("csharp",
+	 /* Keywords */
+	 "!^[ \t]*(do|while|for|if|else|instanceof|new|return|switch|case|throw|catch|using)\n"
+	 /* Methods and constructors */
+	 "^[ \t]*(((static|public|internal|private|protected|new|virtual|sealed|override|unsafe)[ \t]+)*[][<>@.~_[:alnum:]]+[ \t]+[<>@._[:alnum:]]+[ \t]*\\(.*\\))[ \t]*$\n"
+	 /* Properties */
+	 "^[ \t]*(((static|public|internal|private|protected|new|virtual|sealed|override|unsafe)[ \t]+)*[][<>@.~_[:alnum:]]+[ \t]+[@._[:alnum:]]+)[ \t]*$\n"
+	 /* Type definitions */
+	 "^[ \t]*(((static|public|internal|private|protected|new|unsafe|sealed|abstract|partial)[ \t]+)*(class|enum|interface|struct)[ \t]+.*)$\n"
+	 /* Namespace */
+	 "^[ \t]*(namespace[ \t]+.*)$",
+	 /* -- */
+	 "[a-zA-Z_][a-zA-Z0-9_]*"
+	 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
+	 "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"
+	 "|[^[:space:]]|[\x80-\xff]+"),
 { "default", NULL, -1, { NULL, 0 } },
 };
 #undef PATTERNS
-- 
1.7.1.msysgit.0.10.g9ffa0
Jeff King· Aug 11, 2010, 19:37 UTC · re: Petr Onderka · lore

Re: [PATCH] Userdiff patterns for C#

On Wed, Aug 11, 2010 at 01:09:21AM +0000, Petr Onderka wrote:
Show 6 quoted lines
> Add userdiff patterns for C#. This code is an improved version of
> code by Adam Petaccia from 21 June 2009 mail to the list.
> [...]
>  t/t4018-diff-funcname.sh |    2 +-
>  userdiff.c               |   16 ++++++++++++++++
>  2 files changed, 17 insertions(+), 1 deletions(-)

Can you also add a line in Documentation/gitattributes.txt so that people know your pattern is there? In the "custom hunk-header" section, there is already a list to add to.

-Peff
Petr Onderka· Aug 16, 2010, 17:01 UTC · re: Jeff King · lore

[PATCH v2] Userdiff patterns for C#

Add userdiff patterns for C#. This code is an improved version of code by Adam Petaccia from 21 June 2009 mail to the list.

Signed-off-by: Petr Onderka <gsvick@gmail.com>
---
Added the documentation.
 Documentation/gitattributes.txt |    2 ++
 t/t4018-diff-funcname.sh        |    2 +-
 userdiff.c                      |   16 ++++++++++++++++
 3 files changed, 19 insertions(+), 1 deletions(-)
Show changes to 3 files +19 −1

Documentation/gitattributes.txt, t/t4018-diff-funcname.sh, userdiff.c

diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index 564586b..2e2370c 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -441,6 +441,8 @@ patterns are available:
 
 - `cpp` suitable for source code in the C and C++ languages.
 
+- `csharp` suitable for source code in the C# language.
+
 - `html` suitable for HTML/XHTML documents.
 
 - `java` suitable for source code in the Java language.
diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index 5b10e97..61de8a2 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -32,7 +32,7 @@ EOF
 
 sed 's/beer\\/beer,\\/' < Beer.java > Beer-correct.java
 
-builtin_patterns="bibtex cpp html java objc pascal php python ruby tex"
+builtin_patterns="bibtex cpp csharp html java objc pascal php python ruby tex"
 for p in $builtin_patterns
 do
 	test_expect_success "builtin $p pattern compiles" '
diff --git a/userdiff.c b/userdiff.c
index c49cc1b..e552215 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -82,6 +82,22 @@ PATTERNS("cpp",
 	 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
 	 "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"
 	 "|[^[:space:]]|[\x80-\xff]+"),
+PATTERNS("csharp",
+	 /* Keywords */
+	 "!^[ \t]*(do|while|for|if|else|instanceof|new|return|switch|case|throw|catch|using)\n"
+	 /* Methods and constructors */
+	 "^[ \t]*(((static|public|internal|private|protected|new|virtual|sealed|override|unsafe)[ \t]+)*[][<>@.~_[:alnum:]]+[ \t]+[<>@._[:alnum:]]+[ \t]*\\(.*\\))[ \t]*$\n"
+	 /* Properties */
+	 "^[ \t]*(((static|public|internal|private|protected|new|virtual|sealed|override|unsafe)[ \t]+)*[][<>@.~_[:alnum:]]+[ \t]+[@._[:alnum:]]+)[ \t]*$\n"
+	 /* Type definitions */
+	 "^[ \t]*(((static|public|internal|private|protected|new|unsafe|sealed|abstract|partial)[ \t]+)*(class|enum|interface|struct)[ \t]+.*)$\n"
+	 /* Namespace */
+	 "^[ \t]*(namespace[ \t]+.*)$",
+	 /* -- */
+	 "[a-zA-Z_][a-zA-Z0-9_]*"
+	 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
+	 "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"
+	 "|[^[:space:]]|[\x80-\xff]+"),
 { "default", NULL, -1, { NULL, 0 } },
 };
 #undef PATTERNS
-- 
1.7.2.1.2358.g07fa
Jeff King· Aug 16, 2010, 17:14 UTC · re: Petr Onderka · lore

Re: [PATCH v2] Userdiff patterns for C#

On Mon, Aug 16, 2010 at 05:01:02PM +0000, Petr Onderka wrote:
Show 6 quoted lines
> Add userdiff patterns for C#. This code is an improved version of
> code by Adam Petaccia from 21 June 2009 mail to the list.
> 
> Signed-off-by: Petr Onderka <gsvick@gmail.com>
> ---
> Added the documentation.

Thanks. I ran a few diffs on what little C# code I have, and it did seem to be an improvement. So:

Acked-by: Jeff King <peff@peff.net>
-Peff
Junio C Hamano· Aug 22, 2010, 07:23 UTC · re: Jeff King · lore

Re: [PATCH v2] Userdiff patterns for C#

Jeff King <peff@peff.net> writes:
> Thanks. I ran a few diffs on what little C# code I have, and it did seem
> to be an improvement. So:
>
> Acked-by: Jeff King <peff@peff.net>
Thanks, both.

← back to recent threads