2 ms·
You've asked for it ;) This prints the years - you can the group and plot them as you wish (it should be fairly easy, but I wrestled enough with git). It's a n
by pizza234 5y ago
You've asked for it ;)
This prints the years - you can the group and plot them as you wish (it should be fairly easy, but I wrestled enough with git). It's a non-rigorous script (eg. it assumes nobody's email/name includes an `YYYY-MM-DD`-like string, and that filenames don't include the colon character):
grep -P '\bTODO\b' -n -R -- * | awk -F: '{ system("git blame "$1" -L "$2","$2) }' | perl -lne 'print /(\d{4})-\d\d-\d\d/'
The working is actually fairly simple:
- grep prints filenames and lines
- awk captures the filename and line, and executes a git blame on it
- perl matches the year and prints it
In the Perl matching expression, month and day are not strictly necessary, but disambiguate potential 4-digit numbers in the email/name.
I'm very underwhelmed by the lack of customization of the `git blame` command - `--porcelain` is also uncustomizable, which makes things even uglier.
Note that `git blame` also mishandles some edges (printing "fatal: file [...] has only 1 line").
- peff 5y agoWhat do you want `blame --porcelain` to do that it doesn't? Using: git blame --line-porcelain "$1" -L "$2,"$2" | perl -MPOSIX=strftime -lne '/^author-time (\d+)/ and print strftime("%Y", localtime($1))' I suppose it would be a little more convenient if you could ask `git blame` to format the whole line itself, but that wouldn't be part of the `--porcelain` output. All that said, that pipeline is quite slow on something like linux.git, as it runs a series of blames which will walk over the same history many times. I think: git log -STODO --format=%ad --date=short would be much faster (it's not _quite_ the same thing, as it counts TODOs which went away, but is a reasonable variant).
- pizza234 5y ago> What do you want `blame --porcelain` to do that it doesn't? Using: It increases the complexity, due to time conversion. One can certainly solve the general problem by throwing enough awk/perl/sed at it, but an option to customize the blame output would make it significantly more ergonomic (and the oneliner much simpler).