cloc
enables one to count the number of lines of code stored in a directory per language per type (blank, comment, or code).
git blame
enables one to see which part of a file belong to whom.
I'm looking for a way to combine both so that one gets a (three dimensional) matrix that lists the lines of code per type per language per user.
Are there elegant builtin ways to do this or should one "scrap" the "blame" parts (by running grep
after git blame
) of each user and run cloc
on them to calculate the table for each user?
EDIT:
Naive approach (based on the comment of @Jubobs):
- First generate a blame file for each file in the directory (not necessary explicit).
- Run grep with something like
grep "^[^(]*([^)]*)"
to capture the list of all users and retrieve the uniques withsort
anduniq
. - For each user: generate a shadow copy of the folder and grep with
grep "^[^(]*($user)"
such that only the lines of that user remain. - Run cloc on the shadow copy.
- Do this for each user, store the results and output them together.
This is more or less how to generate the desired output. But as one can see, this approach does a lot of copying (or at least storing in memory) and one can actually compute the lines per user by running over the file once instead of multiple times.
Desired output:
something like:
+--------+--------------------------------+--------------------------------+
|User | C# | XML |
+--------+-------+-------+---------+------+-------+-------+---------+------+
| | files | blank | comment | code | files | blank | comment | code |
+--------+-------+-------+---------+------+-------+-------+---------+------+
| Foo | 12 | 75 | 148 | 2711 | 2 | 42 | 0 | 0 |
| Bar | 167 | 1795 | 1425 | 2 | 16 | 0 | 512 | 1678 |
+--------+-------+-------+---------+------+-------+-------+---------+------+
| Total | 179 | 1870 | 1573 | 2713 | 18 | 42 | 512 | 1678 |
+--------+-------+-------+---------+------+-------+-------+---------+------+
grep
should retrieve from the output ofgit blame
? – Selfreliancegit fame
does some statistics. – Sportscaststucked
? – Fabian