I maintain some c source code files. I get a task to find out what function is unstable. Unstable means functions be modified frequently. Actually I want get the statistic data to point out which function was modified how much times and each time by who. First I try to use git blame to get the information, but i am failed. Then I read many answer here, still can not find the best way. So i want ask you is there any tool or method can help me to do the job? Thanks very much!
Asked
Active
Viewed 75 times
0
-
https://stackoverflow.com/a/4456846/13126651 – Jatin Mehrotra Apr 01 '21 at 08:50
-
Does [this](https://stackoverflow.com/a/35225120/2915738) help? [This method](https://stackoverflow.com/a/7310999/2915738) shows possible solution with `log` command. Hope that helps a bit. – Asif Kamran Malick Apr 01 '21 at 08:52
-
Thanks to @AsifKamranMalick `s information, I done the job. – Pope B.Lei Apr 06 '21 at 08:55
-
Glad that helped. – Asif Kamran Malick Apr 06 '21 at 16:44
-
What do you want to achieve with this statistic? – Rudi Apr 08 '21 at 10:08
-
@Rudi move stable code into ROM, and unstable code into RAM. – Pope B.Lei Apr 09 '21 at 09:48
2 Answers
0
I done the job with following script.
#!/bin/bash
cat [function_list_file] | while read line
do
echo $line
git log -L :$line:path/subpath/file.c | grep commit -c # Get numbers of commit
git log -L :$line:path/subpath/file.c | grep commit -2 # Get commit information
done
[function_list_file] is a file contain function name list, as:
funciton_1
funciton_2
funciton_3
funciton_4
funciton_5
funciton_6
funciton_7
funciton_8

Pope B.Lei
- 1
- 4
0
If a function be moved from file a.c to file b.c at commit_x, we can use
git log -L :function:path/subpath/b.c
to get commits at HEAD of the latest commit. But we can not use
git log -L :function:path/subpath/a.c
to get commit at HEAD of the latest commit.
After resetting HEAD before commit_x,
git log -L :function:path/subpath/a.c
works.
Now I solved this problem by the following steps. I can find commits related to a function in all files.
git log -p | grep function -3 > run.log
cat run.log | grep "void function(" > run2.log
cat run2.log | grep @@ -c

Pope B.Lei
- 1
- 4