Skip to content

Instantly share code, notes, and snippets.

@PeterZhukov
Created May 29, 2019 12:43
Show Gist options
  • Select an option

  • Save PeterZhukov/3e1cae2c1f81abe524fc725da2af4ffe to your computer and use it in GitHub Desktop.

Select an option

Save PeterZhukov/3e1cae2c1f81abe524fc725da2af4ffe to your computer and use it in GitHub Desktop.
Git lines by author
<?php
//git log --stat --since="2018-08-02" | grep -v vendor | grep "( \| )|(Author: )" > programmers.log 2>&1
//php main_script.php
$data = file_get_contents(__DIR__.'/programmers.log');
$data = explode("\n", $data);
$authors = [];
$currentAuthor = '';
$lines = 0;
foreach($data as $line){
if (preg_match("/Author: (.*?) </", $line, $matches)){
if ($currentAuthor !== $matches[1]) {
if (!isset($authors[$currentAuthor])){
$authors[$currentAuthor] = 0;
}
$authors[$currentAuthor] += $lines;
$currentAuthor = $matches[1];
$lines = 0;
}
} elseif (preg_match("/.*? \| (.*?) [\+-]/", $line, $matches)){
$lines += $matches[1];
}
}
if (!isset($authors[$currentAuthor])){
$authors[$currentAuthor] = 0;
}
$authors[$currentAuthor] += $lines;
uasort($authors, function($a, $b){
return $b <=> $a;
});
echo json_encode($authors, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment