Back in the days when I worked for RedHat I remember having a neat autocomplete git hook that filled in my git commit message. I liked the way it was formatted and I remember it being something similar to this.
* /Path/To/Changed/File0 (Method0):
(Method1)
(Method2)
(Struct)
* /Path/To/Changed/File1 (Method0):
...
Here I try to reproduce this effect by having a very simple script that uses the git diff. Here is the script:
git diff HEAD | \ grep -e '^@@.*@@.*(.' -e '^@@.*@@.*.struct.*{' -e '^diff ..git' | \ sed 's/^@@.*@@ /@@ /' | \ sed 'sed 's/ \(int\|double\) / / sed 's/(./ /' | \ sed 's/^@@.*@@.*struct.*{/@@@ struct/' | uniq | \ awk -F " " '/^diff --git/{gsub(/^./,"",$3);print "#*"$3" :"} /^@@@ struct/{gsub(/{/,"", $3);print "#("$3") :"} /^@@ /{print "#("$2") :"}'
The `grep` line selects the relevant git diff lines. The `sed` lines remote the text that goes around the lines containing the “@@” string. And finally the awk line formats three types of lines: 1. the file change, 2. the method change, and 3. the struct change.
This script has some shortcomings:
- New methods, structs do not show up
- Sometimes the diff will have a method, struct name that is not actually changed.
Still I’ll make this post as a reminder to myself and a place where I can start next time I want to “give this a shot”