File inc/git.inc.php changed (mode: 100644) (index 18a253d..aa164be) |
... |
... |
function rg_git_set_error($str) |
18 |
18 |
{ |
{ |
19 |
19 |
global $rg_git_error; |
global $rg_git_error; |
20 |
20 |
$rg_git_error = $str; |
$rg_git_error = $str; |
21 |
|
rg_log($str); |
|
|
21 |
|
rg_log('git_set_error: ' . $str); |
22 |
22 |
} |
} |
23 |
23 |
|
|
24 |
24 |
function rg_git_error() |
function rg_git_error() |
|
... |
... |
function rg_git_diff2array($diff, &$out) |
683 |
683 |
global $rg_git_debug; |
global $rg_git_debug; |
684 |
684 |
|
|
685 |
685 |
rg_prof_start("git_diff2array"); |
rg_prof_start("git_diff2array"); |
686 |
|
//rg_log_ml("DEBUG: git_diff2array: diff: " . $diff); |
|
|
686 |
|
rg_log_enter('git_diff2array'); |
|
687 |
|
if ($rg_git_debug > 90) { |
|
688 |
|
rg_log_ml("DEBUG: git_diff2array: diff: " . $diff); |
|
689 |
|
rg_log_ml("DEBUG: git_diff2array: out: " . print_r($out, TRUE)); |
|
690 |
|
} |
687 |
691 |
|
|
688 |
692 |
$ret = TRUE; |
$ret = TRUE; |
689 |
693 |
$lines = explode("\n", $diff); |
$lines = explode("\n", $diff); |
690 |
|
unset($diff); // manually free data |
|
691 |
|
//rg_log_ml("DEBUG: lines: " . print_r($lines, TRUE)); |
|
|
694 |
|
//if ($rg_git_debug > 90) { |
|
695 |
|
// rg_log_ml("DEBUG: lines: " . print_r($lines, TRUE)); |
692 |
696 |
foreach ($lines as $line) { |
foreach ($lines as $line) { |
693 |
697 |
if ($rg_git_debug > 90) |
if ($rg_git_debug > 90) |
694 |
698 |
rg_log("DEBUG: line=$line"); |
rg_log("DEBUG: line=$line"); |
|
... |
... |
function rg_git_diff2array($diff, &$out) |
721 |
725 |
|
|
722 |
726 |
$file = $a['file']; |
$file = $a['file']; |
723 |
727 |
if (!isset($out[$file])) { |
if (!isset($out[$file])) { |
|
728 |
|
rg_log_ml('DEBUG: out: ' . print_r($out, TRUE)); |
|
729 |
|
rg_log('DEBUG: line=' . $line); |
724 |
730 |
rg_git_set_error('internal error'); |
rg_git_set_error('internal error'); |
725 |
731 |
rg_internal_error('we have a diff for a' |
rg_internal_error('we have a diff for a' |
726 |
732 |
. ' non-existing file (' . $file . ')'); |
. ' non-existing file (' . $file . ')'); |
|
... |
... |
function rg_git_diff2array($diff, &$out) |
808 |
814 |
|
|
809 |
815 |
$_t = explode(" ", $line, 5); |
$_t = explode(" ", $line, 5); |
810 |
816 |
if (count($_t) < 4) { |
if (count($_t) < 4) { |
|
817 |
|
rg_log_ml('DEBUG: diff: ' . print_r($diff, TRUE)); |
811 |
818 |
rg_internal_error("invalid line [$line]: count < 4"); |
rg_internal_error("invalid line [$line]: count < 4"); |
812 |
819 |
$ret = FALSE; |
$ret = FALSE; |
813 |
820 |
break; |
break; |
|
... |
... |
function rg_git_diff2array($diff, &$out) |
862 |
869 |
break; |
break; |
863 |
870 |
} |
} |
864 |
871 |
|
|
|
872 |
|
rg_log_exit(); |
865 |
873 |
rg_prof_end("git_diff2array"); |
rg_prof_end("git_diff2array"); |
866 |
874 |
return $ret; |
return $ret; |
867 |
875 |
} |
} |
|
... |
... |
function rg_git_log_simple($repo_path, $max, $from, $to, $also_patch, $files, |
950 |
958 |
break; |
break; |
951 |
959 |
} |
} |
952 |
960 |
|
|
953 |
|
if ($rg_git_debug > 70) |
|
954 |
|
rg_log_ml("DEBUG: OUTPUT OF GIT LOG: " . $a['data']); |
|
|
961 |
|
if ($rg_git_debug > 95) { |
|
962 |
|
rg_log_enter('DEBUG: OUTPUT OF GIT LOG START'); |
|
963 |
|
rg_log_ml($a['data']); |
|
964 |
|
rg_log_exit(); |
|
965 |
|
} |
955 |
966 |
|
|
956 |
967 |
$blocks = explode($sep_start, $a['data']); |
$blocks = explode($sep_start, $a['data']); |
957 |
968 |
unset($a['data']); // manually free memory |
unset($a['data']); // manually free memory |
958 |
969 |
// because data starts with the separator, we remove it |
// because data starts with the separator, we remove it |
959 |
970 |
unset($blocks[0]); |
unset($blocks[0]); |
960 |
971 |
|
|
961 |
|
//rg_log_ml('DEBUG: blocks: ' . print_r($blocks, TRUE)); |
|
|
972 |
|
if ($rg_git_debug > 94) { |
|
973 |
|
rg_log_enter('DEBUG: blocks:'); |
|
974 |
|
rg_log_ml(print_r($blocks, TRUE)); |
|
975 |
|
rg_log_exit(); |
|
976 |
|
} |
962 |
977 |
|
|
963 |
978 |
$ret = array(); |
$ret = array(); |
964 |
979 |
foreach ($blocks as $junk => $block) { |
foreach ($blocks as $junk => $block) { |
|
980 |
|
if ($rg_git_debug > 90) |
|
981 |
|
rg_log_ml('DEBUG: block: ' . print_r($block, TRUE)); |
|
982 |
|
|
965 |
983 |
$y = array("vars" => array(), "files" => array()); |
$y = array("vars" => array(), "files" => array()); |
966 |
984 |
|
|
967 |
985 |
// some defaults |
// some defaults |
|
... |
... |
function rg_git_log_simple($repo_path, $max, $from, $to, $also_patch, $files, |
970 |
988 |
// split block in two: vars and patches |
// split block in two: vars and patches |
971 |
989 |
$parts = explode($sep_end, $block, 2); |
$parts = explode($sep_end, $block, 2); |
972 |
990 |
unset($block); // manually free memory |
unset($block); // manually free memory |
973 |
|
//rg_log_ml('DEBUG: parts: ' . print_r($parts, TRUE)); |
|
|
991 |
|
if ($rg_git_debug > 90) |
|
992 |
|
rg_log_ml('DEBUG: parts: ' . print_r($parts, TRUE)); |
974 |
993 |
|
|
975 |
994 |
// vars |
// vars |
976 |
995 |
$y['vars']['lines_add'] = 0; |
$y['vars']['lines_add'] = 0; |
|
... |
... |
function rg_git_log_simple($repo_path, $max, $from, $to, $also_patch, $files, |
989 |
1008 |
} |
} |
990 |
1009 |
} |
} |
991 |
1010 |
// Some additions |
// Some additions |
992 |
|
$y['vars']['author date UTC'] = gmdate("Y-m-d H:i:s", $y['vars']['author date']); |
|
993 |
|
$y['vars']['committer date UTC'] = gmdate("Y-m-d H:i:s", $y['vars']['committer date']); |
|
|
1011 |
|
if (isset($y['vars']['author date'])) |
|
1012 |
|
$y['vars']['author date UTC'] = gmdate("Y-m-d H:i:s", $y['vars']['author date']); |
|
1013 |
|
if (isset($y['vars']['committer date'])) |
|
1014 |
|
$y['vars']['committer date UTC'] = gmdate("Y-m-d H:i:s", $y['vars']['committer date']); |
994 |
1015 |
|
|
995 |
1016 |
if (!isset($parts[1])) { |
if (!isset($parts[1])) { |
996 |
1017 |
// we do nothing |
// we do nothing |
|
... |
... |
function rg_git_log_simple($repo_path, $max, $from, $to, $also_patch, $files, |
998 |
1019 |
continue; |
continue; |
999 |
1020 |
} |
} |
1000 |
1021 |
|
|
1001 |
|
//rg_log_ml('DEBUG parts[1]: ' . print_r($parts[1], TRUE)); |
|
|
1022 |
|
if ($rg_git_debug > 90) |
|
1023 |
|
rg_log_ml('DEBUG parts[1]: ' . print_r($parts[1], TRUE)); |
1002 |
1024 |
// numstat [+ diff separated by \0\0] |
// numstat [+ diff separated by \0\0] |
1003 |
1025 |
$n_d = explode("\0\0", $parts[1]); |
$n_d = explode("\0\0", $parts[1]); |
1004 |
1026 |
unset($parts[1]); // manually free data |
unset($parts[1]); // manually free data |
|
... |
... |
function rg_git_log_simple($repo_path, $max, $from, $to, $also_patch, $files, |
1044 |
1066 |
'lines_add' => intval($a[0]), |
'lines_add' => intval($a[0]), |
1045 |
1067 |
'lines_del' => intval($a[1]) |
'lines_del' => intval($a[1]) |
1046 |
1068 |
); |
); |
1047 |
|
$y['files'][$f]['changes'] = |
|
1048 |
|
$y['files'][$f]['lines_add'] |
|
|
1069 |
|
$changes = $y['files'][$f]['lines_add'] |
1049 |
1070 |
+ $y['files'][$f]['lines_del']; |
+ $y['files'][$f]['lines_del']; |
|
1071 |
|
$y['files'][$f]['changes'] = $changes; |
1050 |
1072 |
|
|
1051 |
1073 |
// We will mark over sized diffs for later use |
// We will mark over sized diffs for later use |
1052 |
|
$changes = $y['files'][$f]['lines_add'] |
|
1053 |
|
+ $y['files'][$f]['lines_del']; |
|
1054 |
1074 |
//rg_log('DEBUG: File [' . $f . '] ' |
//rg_log('DEBUG: File [' . $f . '] ' |
1055 |
1075 |
// . $changes . ' changes'); |
// . $changes . ' changes'); |
1056 |
1076 |
$y['files'][$f]['oversize_diff'] = |
$y['files'][$f]['oversize_diff'] = |
|
... |
... |
function rg_git_log_simple($repo_path, $max, $from, $to, $also_patch, $files, |
1069 |
1089 |
|
|
1070 |
1090 |
if (!isset($n_d[1])) { |
if (!isset($n_d[1])) { |
1071 |
1091 |
// TODO: can happen if the diff is empty? |
// TODO: can happen if the diff is empty? |
|
1092 |
|
rg_log_ml('DEBUG: block: ' . print_r($block, TRUE)); |
1072 |
1093 |
rg_internal_error('patch, but diff missing!'); |
rg_internal_error('patch, but diff missing!'); |
1073 |
1094 |
rg_git_set_error('internal error'); |
rg_git_set_error('internal error'); |
1074 |
1095 |
$ret = FALSE; |
$ret = FALSE; |
|
... |
... |
function rg_git_log_simple($repo_path, $max, $from, $to, $also_patch, $files, |
1076 |
1097 |
} |
} |
1077 |
1098 |
|
|
1078 |
1099 |
// now, patch, if present |
// now, patch, if present |
1079 |
|
if ($rg_git_debug > 80) |
|
1080 |
|
rg_log_ml('DEBUG: n_d[1]:' . "\n" |
|
1081 |
|
. print_r($n_d[1], TRUE)); |
|
1082 |
|
|
|
1083 |
1100 |
$r = rg_git_diff2array($n_d[1], $y['files']); |
$r = rg_git_diff2array($n_d[1], $y['files']); |
1084 |
|
if ($r === FALSE) |
|
|
1101 |
|
if ($r === FALSE) { |
|
1102 |
|
$ret = FALSE; |
1085 |
1103 |
break; |
break; |
|
1104 |
|
} |
1086 |
1105 |
|
|
1087 |
1106 |
//rg_log_ml('DEBUG: diff2array: ' . print_r($y['files'], TRUE)); |
//rg_log_ml('DEBUG: diff2array: ' . print_r($y['files'], TRUE)); |
1088 |
|
|
|
1089 |
1107 |
//rg_log_ml('DEBUG: y: ' . print_r($y, TRUE)); |
//rg_log_ml('DEBUG: y: ' . print_r($y, TRUE)); |
1090 |
1108 |
$ret[] = $y; |
$ret[] = $y; |
1091 |
1109 |
} |
} |
1092 |
1110 |
break; |
break; |
1093 |
1111 |
} |
} |
1094 |
1112 |
|
|
1095 |
|
//rg_log_ml('DEBUG: simple: ' . print_r($ret, TRUE)); |
|
|
1113 |
|
if ($rg_git_debug > 90) |
|
1114 |
|
rg_log_ml('DEBUG: simple: ret: ' . print_r($ret, TRUE)); |
1096 |
1115 |
|
|
1097 |
1116 |
rg_log_exit(); |
rg_log_exit(); |
1098 |
1117 |
rg_prof_end('git_log_simple'); |
rg_prof_end('git_log_simple'); |
|
... |
... |
function rg_git_log_simple($repo_path, $max, $from, $to, $also_patch, $files, |
1100 |
1119 |
} |
} |
1101 |
1120 |
|
|
1102 |
1121 |
/* |
/* |
1103 |
|
* Works on git_log (without patch) output and detect big diffs. |
|
1104 |
|
* Returns an array with all the info needed to prepage a 'git log'. |
|
|
1122 |
|
* Works on git_log (without patch) output to detect big diffs. |
|
1123 |
|
* Returns an array with all the info needed to prepare a 'git log'. |
1105 |
1124 |
* Will return an empty array if normal log should be called. |
* Will return an empty array if normal log should be called. |
1106 |
1125 |
*/ |
*/ |
1107 |
1126 |
function rg_git_log_detect_big_diff($stat, $from) |
function rg_git_log_detect_big_diff($stat, $from) |
|
... |
... |
function rg_git_log_detect_big_diff($stat, $from) |
1195 |
1214 |
} |
} |
1196 |
1215 |
|
|
1197 |
1216 |
/* |
/* |
1198 |
|
* Show last @max commits, no merges, sort by topo |
|
1199 |
|
* @also_patch = TRUE if caller needs also the diff |
|
1200 |
|
* TODO: $also_merges: remove --no-merges |
|
1201 |
|
* '@from' - it will be excluded from the list of commits |
|
|
1217 |
|
* Show last @max commits, no merges, sort by topo. |
|
1218 |
|
* @also_patch = TRUE if caller needs also the diff. |
|
1219 |
|
* TODO: $also_merges: remove --no-merges. |
|
1220 |
|
* '@from' - it will be excluded from the list of commits. |
1202 |
1221 |
*/ |
*/ |
1203 |
1222 |
function rg_git_log($repo_path, $max, $from, $to, $also_patch, $patch_limit) |
function rg_git_log($repo_path, $max, $from, $to, $also_patch, $patch_limit) |
1204 |
1223 |
{ |
{ |
|
1224 |
|
global $rg_git_debug; |
|
1225 |
|
|
1205 |
1226 |
rg_prof_start('git_log'); |
rg_prof_start('git_log'); |
1206 |
1227 |
rg_log_enter('git_log: repo_path=' . $repo_path . ' from=' . $from |
rg_log_enter('git_log: repo_path=' . $repo_path . ' from=' . $from |
1207 |
1228 |
. ' to=' . $to .' max=' . $max); |
. ' to=' . $to .' max=' . $max); |
|
... |
... |
function rg_git_log($repo_path, $max, $from, $to, $also_patch, $patch_limit) |
1221 |
1242 |
break; |
break; |
1222 |
1243 |
} |
} |
1223 |
1244 |
|
|
1224 |
|
rg_log_ml('DEBUG: stat: ' . print_r($stat, TRUE)); |
|
|
1245 |
|
//if ($rg_git_debug > 90) |
|
1246 |
|
// rg_log_ml('DEBUG: stat: ' . print_r($stat, TRUE)); |
|
1247 |
|
if (empty($from)) { |
|
1248 |
|
$from = $stat[0]['vars']['sha1']; |
|
1249 |
|
if ($rg_git_debug > 50) |
|
1250 |
|
rg_log('DEBUG: overwriting from with ' . $from); |
|
1251 |
|
} |
1225 |
1252 |
|
|
1226 |
1253 |
$r = rg_git_log_detect_big_diff($stat, $from); |
$r = rg_git_log_detect_big_diff($stat, $from); |
1227 |
1254 |
if (empty($r)) { // = no big diff |
if (empty($r)) { // = no big diff |
|
... |
... |
function rg_git_log($repo_path, $max, $from, $to, $also_patch, $patch_limit) |
1244 |
1271 |
$x = rg_git_log_simple($repo_path, $max, |
$x = rg_git_log_simple($repo_path, $max, |
1245 |
1272 |
$i['from'], $i['to'], $also_patch, $_files, |
$i['from'], $i['to'], $also_patch, $_files, |
1246 |
1273 |
$patch_limit); |
$patch_limit); |
1247 |
|
if ($x === FALSE) |
|
|
1274 |
|
if ($x === FALSE) { |
|
1275 |
|
$stat = FALSE; |
1248 |
1276 |
break; |
break; |
|
1277 |
|
} |
1249 |
1278 |
//rg_log_ml('DEBUG: x: ' . print_r($x, TRUE)); |
//rg_log_ml('DEBUG: x: ' . print_r($x, TRUE)); |
1250 |
1279 |
|
|
1251 |
1280 |
// Overwrite $stat with the latest info |
// Overwrite $stat with the latest info |
|
... |
... |
function rg_git_log($repo_path, $max, $from, $to, $also_patch, $patch_limit) |
1268 |
1297 |
break; |
break; |
1269 |
1298 |
} |
} |
1270 |
1299 |
|
|
1271 |
|
//rg_log_ml('DEBUG FINAL: ' . print_r($ret, TRUE)); |
|
|
1300 |
|
//if ($rg_git_debug > 90) |
|
1301 |
|
// rg_log_ml('DEBUG FINAL: ' . print_r($ret, TRUE)); |
1272 |
1302 |
|
|
1273 |
1303 |
rg_log_exit(); |
rg_log_exit(); |
1274 |
1304 |
rg_prof_end('git_log'); |
rg_prof_end('git_log'); |
|
... |
... |
function rg_git_files($old, $new) |
1393 |
1423 |
*/ |
*/ |
1394 |
1424 |
function rg_git_diff($id, $a, $template_file) |
function rg_git_diff($id, $a, $template_file) |
1395 |
1425 |
{ |
{ |
|
1426 |
|
global $rg_git_debug; |
|
1427 |
|
|
1396 |
1428 |
rg_prof_start("git_diff"); |
rg_prof_start("git_diff"); |
1397 |
|
//rg_log_enter("DEBUG: git_diff: a: " . rg_array2string($a)); |
|
|
1429 |
|
rg_log("DEBUG: git_diff: id=$id a: " . rg_array2string($a)); |
1398 |
1430 |
|
|
1399 |
1431 |
$id = rg_xss_safe($id); |
$id = rg_xss_safe($id); |
1400 |
1432 |
|
|
1401 |
1433 |
$ret = "<div class=\"diff\">\n"; |
$ret = "<div class=\"diff\">\n"; |
1402 |
1434 |
|
|
1403 |
1435 |
$x = array(); |
$x = array(); |
1404 |
|
$template = rg_template($template_file, $x, TRUE /* xss */); |
|
|
1436 |
|
$template = rg_template($template_file, $x, TRUE /*xss*/); |
1405 |
1437 |
|
|
1406 |
1438 |
// for each file changed |
// for each file changed |
1407 |
1439 |
foreach ($a as $fileindex => $finfo) { |
foreach ($a as $fileindex => $finfo) { |
1408 |
|
//rg_log_ml("DEBUG: finfo: " . print_r($finfo, TRUE)); |
|
|
1440 |
|
if ($rg_git_debug > 90) |
|
1441 |
|
rg_log_ml("DEBUG: finfo: " . print_r($finfo, TRUE)); |
1409 |
1442 |
|
|
1410 |
1443 |
$ret .= "<br />\n"; |
$ret .= "<br />\n"; |
1411 |
1444 |
|
|