1

I was wondering whether it is possible (either with bare Git or GitLab/GitHub/other) to check how often a function was edited over previous commits or history since a certain date.

According to for example

Bosu, Amiangshu. (2014). Identifying the characteristics of vulnerable code changes: an empirical study. 10.1145/2635868.2635880.

code that changes more often has a higher chance of containing bugs (which is interesting but also makes sense). Therefore I'd be interested in whether it is easily possible to track.

Robin van Hoorn
  • 334
  • 1
  • 10
  • I think part of the difficulty here is that git has no concept of "functions", but only line changes, and files. FInding how often files change might be much easier. – PiRocks Apr 28 '20 at 13:20
  • Git doesn't have any knowledge of "functions". – evolutionxbox Apr 28 '20 at 13:21
  • You could maybe use git log -L:function_name:file_name – PiRocks Apr 28 '20 at 13:25
  • You may also find this question interesting: https://stackoverflow.com/questions/8435343/retrieve-the-commit-log-for-a-specific-line-in-a-file – PiRocks Apr 28 '20 at 13:44
  • Here https://stackoverflow.com/a/45536391/3691891 is the script that check which functions have changed since the last commit, it might be a good starting point. – Arkadiusz Drabczyk Apr 28 '20 at 14:20
  • Ah thanks a lot! Its interesting what workarounds were thought of, though after searching there is not a single tool doing this for say something like a github repo. I reckon for big companys that want secure code it could actually be interesting. – Robin van Hoorn Apr 28 '20 at 14:35
  • Note that the code in `git log` (and `git diff`) that extracts function names, for `git log -L` and diff hunk headers, uses regular expressions to find the "function name". This is easily fooled in some languages. Regular expressions in general can't parse function definitions correctly. As a fast heuristic, though, it mostly works, so if you are willing to accept wrong answers some percentage of the time, PiRocks' suggestion might help. – torek Apr 28 '20 at 20:26

0 Answers0