Created
March 20, 2016 12:20
-
-
Save jankal/70abaf5eb3df903e2ec6 to your computer and use it in GitHub Desktop.
Parse outputs of `git log`
This file contains 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
<?php | |
function parseLog($log) { | |
$lines = explode("\n", $log); | |
$history = array(); | |
foreach($lines as $key => $line) { | |
if(strpos($line, 'commit') === 0 || $key + 1 == count($lines)){ | |
if(!empty($commit)){ | |
$commit['message'] = substr($commit['message'], 4); | |
array_push($history, $commit); | |
unset($commit); | |
} | |
$commit['hash'] = substr($line, strlen('commit') + 1); | |
} else if(strpos($line, 'Author') === 0){ | |
$commit['author'] = substr($line, strlen('Author:') + 1); | |
} else if(strpos($line, 'Date') === 0){ | |
$commit['date'] = substr($line, strlen('Date:') + 3); | |
} elseif (strpos($line, 'Merge') === 0) { | |
$commit['merge'] = substr($line, strlen('Merge:') + 1); | |
$commit['merge'] = explode(' ', $commit['merge']); | |
} else { | |
if(isset($commit['message'])) { | |
$commit['message'] .= $line; | |
} else { | |
$commit['message'] = $line; | |
} | |
} | |
} | |
return $history; | |
} |
@chaziz94 I'm happy to assist even if it's kinda old.
I just tried this function in 3v4l, see here: https://3v4l.org/7eGFF
It still seems to work for me.
Can you show me how you are using it?
Works a treat for me too
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does not work.