#!/usr/bin/env php $columns[0], 'name' => $columns[1], 'date' => $columns[2], 'time' => strtotime($columns[2]), ]; $shas[$columns[0]] = []; } foreach(array_keys($shas) as $sha) { $log = trim(shell_exec('git log --oneline ' . $ref . '..' . $sha)); if($log) { $shas[$sha] = count(explode(PHP_EOL, $log)); continue; } $log = trim(shell_exec('git log --oneline ' . $sha . '..' . $ref)); if($log) { $shas[$sha] = -count(explode(PHP_EOL, $log)); continue; } $shas[$sha] = 0; } foreach(array_keys($branches) as $branch) { $branches[$branch]['commits'] = $shas[$branches[$branch]['sha']]; } if(empty($branches[$ref])) { $branches[$ref] = [ 'sha' => $ref, 'name' => $ref, 'date' => null, 'time' => 0, 'commits' => 0, ]; } usort($branches, function($a, $b) { if($a['commits'] < 1 && $b['commits'] > 0) { return 1; } if($a['commits'] > 0 && $b['commits'] < 1) { return -1; } if($a['time'] !== $b['time']) { return $b['time'] - $a['time']; } if($a['commits'] !== $b['commits']) { return $b['commits'] - $a['commits']; } return strcmp($a['name'], $b['name']); }); $timelimit = time() - 12*3600; foreach($branches as $branch) { if($branch['commits']) { printf( "%5d %10s %s\n", $branch['commits'], date($branch['time'] < $timelimit ? 'Y-m-d' : ' H:i:s ', $branch['time']), $branch['name'] ); } else { echo ' -- ', $branch['name'], ' --', PHP_EOL; } }