2

I am trying to update three regular expressions to identify patterns in git logs. Basically, they are expressions for identifying code line additions, modifications, and deletions from git annotations when running the git diff ---word-diff --unified=0 command.

The expressions are:

MODIFICATION: .+(\[-|\{\+).*$

ADD: \{\+.*\+\}$

REMOVE: \[-.*-\]$

Originally, these expressions were presented in this question: Is there a way of having git show lines added, lines changed and lines removed?. But today, apparently, they are no longer working as they should, because when testing here, I found different numbers than they really should have

For the following code, it introduced different numbers of removals and modifications:

@@ -11 +11 @@ delta dAddressBook {
                        private String [-addressA;-]{+address;+}
@@ -13 +13 @@ delta dAddressBook {
                        public [-AddressBookEntryB()-]{+AddressBookEntry()+} {
@@ -39,0 +40,4 @@ delta dAddressBook {

                        {+public void setAddress(String address) {+}
{+                              this.address = address;+}
{+                      }+}
@@ -45,2 +48,0 @@ delta dAddressBook {
[-              import br.unb.cic.iris.core.exception.EmailException;-]
[-              import br.unb.cic.iris.core.model.AddressBookEntry;-]

On https://regex101.com/r/Soeey3/1/

For some reason, it is matching line 7 in this example ({+public void setAddress(String address) {+}), where this line should be accounted for addition and not modification. Similarly, the expression for addition does not match line 7.

Leomar de Souza
  • 677
  • 10
  • 23
  • 1
    Something is disconnected here. The target patterns changed, You're showing the old patterns with the new target, I can't gleen from your old regexes what it is supposed to match in the new target ... –  Aug 06 '19 at 00:37
  • @leomar-de-souza I'm thinking that your interpretation might be wrong here and not the regex. If you consider that line 7 includes white-space changes then it is a change and not an addition, depends on what is considered a change. – Dean Taylor Aug 06 '19 at 01:02
  • I just tested ADD with your example, and it's matching lines 2, 7, 8 and 9 for addition for me, whereas you said it didn't match 7 for you. I think you need to assess if you need `^` and `$` at the beginning or not, depending on whether you consider addition of a word inside a line an addition or a modification - the modification regex you should considers that a modification, in any case. – joanis Aug 06 '19 at 01:18

0 Answers0