How to get the signature of changed methods in a commit

3

So folks, I need to sign all of the methods that have been changed in a commit, be it 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 do you know of a lib I already have? The code to access the commits and get the blob I already have. I'm developing in Java, but lib can be in any language.

Thank you in advance.

    
asked by anonymous 23.03.2015 / 13:19

2 answers

1

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

  • With a git blame between the desired commit and its parent I can extract which lines have been modified and get their line numbers;
  • I have implemented a JDT Parser (using AST.JLS8) which parses the modified files by storing the initial and final line of each declared method;
  • Then just pass the number of the modified line obtained in step 1 and look within the range of methods obtained in step 2.

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

    
27.04.2015 / 20:28
0

GIT already identifies, where 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 range of lines.

On windows, you can do the first part with FINDSTR.

I'm using git v2.4.0.

    
25.04.2015 / 12:06