Last active
December 11, 2015 17:58
-
-
Save paularmstrong/4638049 to your computer and use it in GitHub Desktop.
get the lines existing per user in a git repo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var child_process = require('child_process'), | |
users = {}, | |
c = 0, | |
modes = ['100644', '100664', '100755']; | |
function blameFile(file, i) { | |
setTimeout(function () { | |
child_process.exec('git blame ' + file, function (error, stdout, stderr) { | |
var lines = stdout.split('\n'), | |
j = lines.length, | |
user; | |
c -= 1; | |
while (j) { | |
j -= 1; | |
line = lines[j]; | |
user = line.replace(/^\^?[a-f0-9]{7,8}[^\(]*\(/, '').replace(/[0-9]{4}\-[0-9]{2}\-[0-9]{2}.*$/g, ''); | |
user = user.replace(/\s+?$/g, ''); | |
if (users.hasOwnProperty(user)) { | |
users[user] += 1; | |
} else { | |
users[user] = 1; | |
} | |
} | |
process.stdout.write('.'); | |
if (!c) { | |
console.log(''); | |
console.log(users); | |
} | |
}); | |
}, i * 150); | |
} | |
child_process.exec('git ls-tree --full-tree -r master', function (error, stdout, stderr) { | |
var files = stdout.split('\n'), | |
i = files.length; | |
c = files.length; | |
while (i) { | |
i -= 1; | |
if (modes.indexOf(files[i].substr(0, 6)) === -1 || (/\.(png|jpg|gif|ico|jar|pickle|json|pyc)$/).test(files[i])) { | |
c -= 1; | |
continue; | |
} | |
blameFile(files[i].substr(53), i); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment