So I have a bit of an issue. I work for a small startup (about 8 developers) and my boss recently decided that we need to put the owner of each file in the documentation. So I have been try to write something using svn blame and file to loop through every php file and see which files have my username on more that 15 lines, but I haven’t been able to get it quite right.
What I would really like is a one-liner (or simple bash script) that will list every file in a subversion repository and the username that last edited the majority of the lines. Any ideas?
Alright, this is what I came up with:
It uses
svn lsto determine each file in the repository, then for each file,svn blameoutput is examined:tr -s " " " "squeezes multiple spaces into one spacecut -d" " -f3gets the third space-delimited field, which is the usernamesortsorts the output so all lines last edited by one user are togetheruniq -cgets all unique lines and outputs the count of how many times each line appearedsort -nrsorts numerically, in reverse order (so that the username that appeared most is sorted first)head -1returns the first linetr -s " " " " | cut -d" " -f3same as before, squeezes spaces and returns the third fieldname which is user.It’ll take a while to run but at the end you’ll have a list of
<filename> <most prevalent author>Caveats: