Created
May 13, 2012 16:43
-
-
Save thomascube/2689234 to your computer and use it in GitHub Desktop.
Script to generate a revision mapping table from two SVN and GIT log files
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
<?php | |
/** | |
* This script builds a revision mapping table from two SVN and GIT log files. | |
* It uses a commit's date and comment to connect SVN revisions with a GIT commits. | |
* | |
* Execute it with php git-svn-create-rev-map.php svn.log git.log | |
* | |
* @author Thomas Bruederli <thomas(at)roundcube(dot)net> | |
**/ | |
// read svn log from first argument | |
$svnlog = file($_SERVER['argv'][1]); | |
if (!count($svnlog)) | |
die("Cannot read svnlog"); | |
$revmap = array(); | |
$svnrev = null; $comment = ''; | |
foreach ($svnlog as $line) { | |
$line = trim($line); | |
if (preg_match('/r(\d+)\s+\|[^|]+\|\s+(2[\d\s:+-]+)/', $line, $m)) { | |
if ($comment && $svnrev) { | |
$ckey = comment_hash($comment); | |
if (isset($revmap[$ckey])) | |
fputs(STDERR, "Duplicate entry for $ckey\n"); | |
else | |
$revmap[$ckey] = $svnrev; | |
} | |
$svnrev = $m[1]; | |
$comment = gmdate('Y-m-d H:i:s ', strtotime($m[2])); | |
} | |
else if (!empty($line) && strpos($line, '-----') === false) | |
$comment .= $line; | |
} | |
unset($svnlog); | |
// read git log from first argument | |
$gitlog = file($_SERVER['argv'][2]); | |
if (!count($gitlog)) | |
die("Cannot read gitlog"); | |
$gitrev = null; | |
foreach ($gitlog as $line) { | |
$line = trim($line); | |
if (preg_match('/^commit\s+([a-f0-9]+)/', $line, $m)) { | |
if ($comment && $gitrev) { | |
$ckey = comment_hash($comment); | |
if (!empty($revmap[$ckey])) | |
echo $revmap[$ckey] . "\t" . $gitrev . "\n"; | |
else | |
fputs(STDERR, "Could not find SVN revision for $gitrev; comment = $comment\n"); | |
} | |
$gitrev = $m[1]; | |
$comment = ''; | |
} | |
else if (preg_match('/^Date:\s+(\w.+)/', $line, $m)) { | |
$comment = gmdate('Y-m-d H:i:s ', strtotime($m[1])); | |
} | |
else if (!empty($line) && !preg_match('/^Author:\s+/', $line)) { | |
$comment .= $line; | |
} | |
} | |
// helper function to create a hash for the given comment | |
function comment_hash($comment) | |
{ | |
return preg_replace('/[^a-z0-9#_()\[\]-]/ims', '', strtolower(iconv('UTF-8', 'US-ASCII//TRANSLIT', $comment))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could you give an example of exactly what the svn and git log file formats should look like. Using straight git log and svn log to generate the files doesn't work with this script.