How to take the signature of changed methods in a commit

Asked

Viewed 92 times

3

So guys, I need to subscribe to all the methods that were changed in a commit, whether updated, removed or added.

Example: In this commit

The changed methods were:

 - br.ufrn.ase.Classe1.metodoB(int b)U
 - br.ufrn.ase.Classe1.getV()D
 - br.ufrn.ase.Classe1.metodoadicionado()A
 - br.ufrn.ase.Classe2.metodoQualquer(int i)A
 - br.ufrn.ase.Classe2.outro(int j)A

Does anyone have any idea how to do this or know of any lib they already do? The code access the commits and get the blob I already have. I am developing in Java, but lib can be in any language.

Thanks in advance.

2 answers

1

I was able to solve this problem using the following combination:

  • With a git Blame between the desired commit and your Parent I can extract which lines have been modified and take the respective line numbers;
  • I implemented a JDT Parser (using AST.JLS8) that parses the modified files by storing the start and end line of each declared method;
  • Hence just pass the modified line number obtained in step 1 and search within the range of the methods obtained in step 2.

I did not get a good result with this example of Pedro, some returned the class package in place of the method signature.

0

GIT already identifies, when possible, the method that has been modified.

Just launch the command:

git show $COMMIT

To better filter the result can be by command line (via linux)

git show $COMMIT | grep @@ | sed 's/@@.*@@//g'

This command looks for the arrobas, indicating the change, then removes the beginning of the line that contains the modified line range.

In windows, Voce can do the first part with FINDSTR.

I’m using git v2.4.0.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.