File inc/git.inc.php changed (mode: 100644) (index 0c99b89..e0261f2) |
... |
... |
function rg_git_diff2array($diff) |
484 |
484 |
// @@ from_file_range to_file_range @@ ... |
// @@ from_file_range to_file_range @@ ... |
485 |
485 |
if (strncmp($line, "@@ ", 3) == 0) { |
if (strncmp($line, "@@ ", 3) == 0) { |
486 |
486 |
$_t = explode(" ", $line, 5); |
$_t = explode(" ", $line, 5); |
|
487 |
|
if (count($_t) < 4) { |
|
488 |
|
rg_internal_error("invalid line [$line]: count != 5"); |
|
489 |
|
return FALSE; |
|
490 |
|
} |
487 |
491 |
$chunk = $_t[1] . " " . $_t[2]; |
$chunk = $_t[1] . " " . $_t[2]; |
488 |
492 |
$ret[$file]['chunks'][$chunk] = array(); |
$ret[$file]['chunks'][$chunk] = array(); |
489 |
|
$ret[$file]['chunks'][$chunk]['section'] = @trim($_t[4]); |
|
|
493 |
|
$ret[$file]['chunks'][$chunk]['section'] = isset($_t[4]) ? trim($_t[4]) : ""; |
490 |
494 |
$from = explode(",", substr($_t[1], 1)); |
$from = explode(",", substr($_t[1], 1)); |
491 |
495 |
$ret[$file]['chunks'][$chunk]['from'] = intval($from[0]); |
$ret[$file]['chunks'][$chunk]['from'] = intval($from[0]); |
492 |
496 |
$to = explode(",", substr($_t[2], 1)); |
$to = explode(",", substr($_t[2], 1)); |
|
... |
... |
function rg_git_diff2array($diff) |
495 |
499 |
} |
} |
496 |
500 |
|
|
497 |
501 |
if (!isset($file_name_tmp[$file_name_sel])) { |
if (!isset($file_name_tmp[$file_name_sel])) { |
498 |
|
echo "bad!"; |
|
499 |
|
echo $diff; |
|
500 |
|
exit(0); |
|
|
502 |
|
rg_internal_error("file_name_tmp[$file_name_sel] does not exists" |
|
503 |
|
. "; file_name_tmp: " . print_r($file_name_tmp, TRUE)); |
|
504 |
|
return FALSE; |
501 |
505 |
} |
} |
502 |
506 |
|
|
503 |
507 |
if (!isset($ret[$file]['file'])) |
if (!isset($ret[$file]['file'])) |
|
... |
... |
function rg_git_diff2array($diff) |
524 |
528 |
continue; |
continue; |
525 |
529 |
} |
} |
526 |
530 |
|
|
527 |
|
rg_log("\tERROR: I do not know how to parse [" . trim($line) . "]!"); |
|
528 |
|
exit(0); |
|
|
531 |
|
rg_internal_error("I do not know how to parse [" . trim($line) . "]!"); |
|
532 |
|
$ret = FALSE; |
529 |
533 |
} |
} |
530 |
534 |
|
|
531 |
535 |
rg_prof_end("git_diff2array"); |
rg_prof_end("git_diff2array"); |
532 |
|
|
|
533 |
536 |
return $ret; |
return $ret; |
534 |
537 |
} |
} |
535 |
538 |
|
|
|
... |
... |
function rg_git_diff2array($diff) |
537 |
540 |
* Show last @max commits, no merges, sort by topo |
* Show last @max commits, no merges, sort by topo |
538 |
541 |
* @also_patch = TRUE if caller needs also the patch |
* @also_patch = TRUE if caller needs also the patch |
539 |
542 |
*/ |
*/ |
540 |
|
function rg_git_log($max, $from, $to, $also_patch) |
|
|
543 |
|
function rg_git_log($path, $max, $from, $to, $also_patch) |
541 |
544 |
{ |
{ |
542 |
545 |
rg_prof_start("git_log"); |
rg_prof_start("git_log"); |
|
546 |
|
rg_log("git_log: path=$path from=$from to=$to max=$max"); |
543 |
547 |
|
|
544 |
|
rg_log("git_log: from=$from to=$to max=$max"); |
|
545 |
|
|
|
546 |
|
// Test if we have an empty dir |
|
547 |
|
$_dir = getenv("GIT_DIR"); |
|
548 |
|
if (empty($_dir)) { |
|
549 |
|
rg_log("\tGIT_DIR is not defined!"); |
|
550 |
|
return FALSE; |
|
551 |
|
} |
|
|
548 |
|
$ret = FALSE; |
|
549 |
|
do { |
|
550 |
|
if (!file_exists($path . "/refs/heads/master")) { |
|
551 |
|
rg_log("\tRepo is empty."); |
|
552 |
|
return ""; |
|
553 |
|
} |
552 |
554 |
|
|
553 |
|
if (!file_exists($_dir . "/refs/heads/master")) { |
|
554 |
|
rg_log("\tRepo is empty."); |
|
555 |
|
return ""; |
|
556 |
|
} |
|
|
555 |
|
$max_count = ($max == 0) ? "" : " --max-count=$max"; |
|
556 |
|
$patches = $also_patch ? " --patch" : ""; |
557 |
557 |
|
|
558 |
|
$max_count = ($max == 0) ? "" : " --max-count=$max"; |
|
559 |
|
$patches = $also_patch ? " --patch" : ""; |
|
|
558 |
|
if (empty($from) && empty($to)) { |
|
559 |
|
$from_to = ""; |
|
560 |
|
} else { |
|
561 |
|
if (empty($from)) |
|
562 |
|
$from_to = " " . $to; |
|
563 |
|
else |
|
564 |
|
$from_to = " " . $from . ".." . $to; |
|
565 |
|
} |
560 |
566 |
|
|
561 |
|
if (empty($from) && empty($to)) { |
|
562 |
|
$from_to = ""; |
|
563 |
|
} else { |
|
564 |
|
if (empty($from)) |
|
565 |
|
$from_to = " " . $to; |
|
566 |
|
else |
|
567 |
|
$from_to = " " . $from . ".." . $to; |
|
568 |
|
} |
|
|
567 |
|
$cmd = "git --no-pager" |
|
568 |
|
. " --git-dir=" . escapeshellarg($path) |
|
569 |
|
. " log" |
|
570 |
|
. " --no-merges" |
|
571 |
|
. " -z" |
|
572 |
|
. $max_count |
|
573 |
|
. $patches |
|
574 |
|
. " --pretty=\"format:" |
|
575 |
|
. "%x00-=ROCKETGIT=-%x00" |
|
576 |
|
. "sha1_short:%h%x00\"\"" |
|
577 |
|
. "sha1_long:%H%x00\"\"" |
|
578 |
|
. "tree:%t%x00\"\"" |
|
579 |
|
. "parents_short:%p%x00\"\"" |
|
580 |
|
. "parents_long:%P%x00\"\"" |
|
581 |
|
. "author name:%aN%x00\"\"" |
|
582 |
|
. "author email:%aE%x00\"\"" |
|
583 |
|
. "author date:%at%x00\"\"" |
|
584 |
|
. "committer name:%cN%x00\"\"" |
|
585 |
|
. "committer email:%ce%x00\"\"" |
|
586 |
|
. "committer date:%ct%x00\"\"" |
|
587 |
|
. "encoding:%e%x00\"\"" |
|
588 |
|
. "subject:%s%x00\"\"" |
|
589 |
|
. "body:%b%x00\"\"" |
|
590 |
|
. "notes:%N%x00\"\"" |
|
591 |
|
. "%x00ROCKETGIT_END_OF_VARS%x00\"" |
|
592 |
|
. " --numstat" |
|
593 |
|
. $from_to; |
|
594 |
|
$a = rg_exec($cmd); |
|
595 |
|
if ($a['ok'] != 1) { |
|
596 |
|
rg_git_set_error("error on log (" . $a['errmsg'] . ")"); |
|
597 |
|
rg_internal_error("Could not generate log."); |
|
598 |
|
break; |
|
599 |
|
} |
569 |
600 |
|
|
570 |
|
$cmd = "git --no-pager log" |
|
571 |
|
. " --no-merges" |
|
572 |
|
. " -z" |
|
573 |
|
. $max_count |
|
574 |
|
. $patches |
|
575 |
|
. " --pretty=\"format:" |
|
576 |
|
. "%x00-=ROCKETGIT=-%x00" |
|
577 |
|
. "sha1_short:%h%x00\"\"" |
|
578 |
|
. "sha1_long:%H%x00\"\"" |
|
579 |
|
. "tree:%t%x00\"\"" |
|
580 |
|
. "parents_short:%p%x00\"\"" |
|
581 |
|
. "parents_long:%P%x00\"\"" |
|
582 |
|
. "author name:%aN%x00\"\"" |
|
583 |
|
. "author email:%aE%x00\"\"" |
|
584 |
|
. "author date:%at%x00\"\"" |
|
585 |
|
. "committer name:%cN%x00\"\"" |
|
586 |
|
. "committer email:%ce%x00\"\"" |
|
587 |
|
. "committer date:%ct%x00\"\"" |
|
588 |
|
. "encoding:%e%x00\"\"" |
|
589 |
|
. "subject:%s%x00\"\"" |
|
590 |
|
. "body:%b%x00\"\"" |
|
591 |
|
. "notes:%N%x00\"\"" |
|
592 |
|
. "%x00ROCKETGIT_END_OF_VARS%x00\"" |
|
593 |
|
. " --numstat" |
|
594 |
|
. $from_to; |
|
595 |
|
$a = rg_exec($cmd); |
|
596 |
|
if ($a['ok'] != 1) { |
|
597 |
|
rg_git_set_error("error on log (" . $a['errmsg'] . ")"); |
|
598 |
|
return FALSE; |
|
599 |
|
} |
|
|
601 |
|
// we prepend a \0 because data starts with -=ROCK... |
|
602 |
|
$blocks = explode("\0-=ROCKETGIT=-\0", "\0" . $a['data']); |
|
603 |
|
// ignore first entry because is empty |
|
604 |
|
unset($blocks[0]); |
600 |
605 |
|
|
601 |
|
$blocks = explode("\0-=ROCKETGIT=-\0", $a['data']); |
|
602 |
|
// ignore first entry because of separator |
|
603 |
|
unset($blocks[0]); |
|
|
606 |
|
$ret = array(); |
|
607 |
|
foreach ($blocks as $junk => $block) { |
|
608 |
|
$y = array("vars" => array(), "files" => array(), "patches" => array()); |
|
609 |
|
|
|
610 |
|
// split block in two: vars and stats + patches |
|
611 |
|
$parts = explode("\0ROCKETGIT_END_OF_VARS\0", $block, 2); |
|
612 |
|
|
|
613 |
|
// vars |
|
614 |
|
$x = explode ("\0", trim($parts[0])); |
|
615 |
|
$count = count($x); |
|
616 |
|
for ($i = 0; $i < $count - 1; $i++) { |
|
617 |
|
$_t = explode(":", $x[$i], 2); |
|
618 |
|
if (isset($_t[1])) |
|
619 |
|
$y['vars'][$_t[0]] = trim($_t[1]); |
|
620 |
|
else |
|
621 |
|
echo "Var " . $_t[0] . " has no value!\n"; |
|
622 |
|
} |
604 |
623 |
|
|
605 |
|
$ret = array(); |
|
606 |
|
foreach ($blocks as $junk => $block) { |
|
607 |
|
$y = array("vars" => array(), "files" => array(), "patches" => array()); |
|
608 |
|
|
|
609 |
|
// split block in two: vars and stats + patches |
|
610 |
|
$parts = explode("\0ROCKETGIT_END_OF_VARS\0", $block, 2); |
|
611 |
|
|
|
612 |
|
// vars |
|
613 |
|
$x = explode ("\0", trim($parts[0])); |
|
614 |
|
$count = count($x); |
|
615 |
|
for ($i = 0; $i < $count - 1; $i++) { |
|
616 |
|
$_t = explode(":", $x[$i], 2); |
|
617 |
|
if (isset($_t[1])) |
|
618 |
|
$y['vars'][$_t[0]] = trim($_t[1]); |
|
619 |
|
else |
|
620 |
|
echo "Var " . $_t[0] . " has no value!\n"; |
|
621 |
|
} |
|
|
624 |
|
// stats & patches |
|
625 |
|
$stats_and_patches = trim($parts[1]); |
|
626 |
|
$_sp = explode("\0\0", $stats_and_patches, 2); |
|
627 |
|
$stats = $_sp[0]; |
|
628 |
|
if (isset($_sp[1])) { |
|
629 |
|
$y['patches'] = rg_git_diff2array($_sp[1]); |
|
630 |
|
if ($y['patches'] === FALSE) |
|
631 |
|
break; |
|
632 |
|
} |
622 |
633 |
|
|
623 |
|
// stats & patches |
|
624 |
|
$stats_and_patches = trim($parts[1]); |
|
625 |
|
$_sp = explode("\0\0", $stats_and_patches, 2); |
|
626 |
|
$stats = $_sp[0]; |
|
627 |
|
if (isset($_sp[1])) |
|
628 |
|
$y['patches'] = rg_git_diff2array($_sp[1]); |
|
629 |
|
|
|
630 |
|
// stats |
|
631 |
|
$_t = explode("\0", $stats); |
|
632 |
|
$y['vars']['files_changed'] = count($_t); |
|
633 |
|
$total_add = 0; |
|
634 |
|
$total_del = 0; |
|
635 |
|
foreach ($_t as $junk => $fi) { |
|
636 |
|
$__t = explode("\t", $fi); |
|
637 |
|
$y['files'][$__t[2]] = array( |
|
638 |
|
"add" => $__t[0], |
|
639 |
|
"del" => $__t[1]); |
|
640 |
|
$total_add += intval($__t[0]); |
|
641 |
|
$total_del += intval($__t[1]); |
|
642 |
|
} |
|
643 |
|
$y['vars']['lines_add'] = $total_add; |
|
644 |
|
$y['vars']['lines_del'] = $total_del; |
|
|
634 |
|
// stats |
|
635 |
|
$_t = explode("\0", $stats); |
|
636 |
|
$y['vars']['files_changed'] = count($_t); |
|
637 |
|
$total_add = 0; |
|
638 |
|
$total_del = 0; |
|
639 |
|
foreach ($_t as $junk => $fi) { |
|
640 |
|
$__t = explode("\t", $fi); |
|
641 |
|
$y['files'][$__t[2]] = array( |
|
642 |
|
"add" => $__t[0], |
|
643 |
|
"del" => $__t[1]); |
|
644 |
|
$total_add += intval($__t[0]); |
|
645 |
|
$total_del += intval($__t[1]); |
|
646 |
|
} |
|
647 |
|
$y['vars']['lines_add'] = $total_add; |
|
648 |
|
$y['vars']['lines_del'] = $total_del; |
645 |
649 |
|
|
646 |
|
// final additions |
|
647 |
|
$y['vars']['author date UTC'] = gmdate("Y-m-d H:i:s", $y['vars']['author date']); |
|
648 |
|
$y['vars']['committer date UTC'] = gmdate("Y-m-d H:i:s", $y['vars']['committer date']); |
|
|
650 |
|
// final additions |
|
651 |
|
$y['vars']['author date UTC'] = gmdate("Y-m-d H:i:s", $y['vars']['author date']); |
|
652 |
|
$y['vars']['committer date UTC'] = gmdate("Y-m-d H:i:s", $y['vars']['committer date']); |
649 |
653 |
|
|
650 |
|
$ret[] = $y; |
|
651 |
|
} |
|
|
654 |
|
$ret[] = $y; |
|
655 |
|
} |
|
656 |
|
} while (0); |
652 |
657 |
|
|
653 |
658 |
rg_prof_end("git_log"); |
rg_prof_end("git_log"); |
654 |
|
|
|
655 |
659 |
return $ret; |
return $ret; |
656 |
660 |
} |
} |
657 |
661 |
|
|
|
... |
... |
function rg_git_stats($log) |
733 |
737 |
*/ |
*/ |
734 |
738 |
function rg_git_diff($a, $template_file) |
function rg_git_diff($a, $template_file) |
735 |
739 |
{ |
{ |
736 |
|
rg_log("git_diff: a: " . rg_array2string($a)); |
|
|
740 |
|
//rg_log("DEBUG: git_diff: a: " . rg_array2string($a)); |
737 |
741 |
|
|
738 |
742 |
$ret = "<div class=\"diff\">\n"; |
$ret = "<div class=\"diff\">\n"; |
739 |
743 |
|
|
740 |
|
$template = rg_template($template_file, array()); |
|
|
744 |
|
$x = array(); |
|
745 |
|
$template = rg_template($template_file, $x); |
741 |
746 |
|
|
742 |
747 |
// for each file changed |
// for each file changed |
743 |
748 |
foreach ($a as $fileindex => $finfo) { |
foreach ($a as $fileindex => $finfo) { |
|
... |
... |
function rg_git_update_branch($a) |
953 |
958 |
if (rg_rights_allow($a['rights'], "P") !== TRUE) { |
if (rg_rights_allow($a['rights'], "P") !== TRUE) { |
954 |
959 |
rg_log("\tPush is not allowed, let's see the anon one"); |
rg_log("\tPush is not allowed, let's see the anon one"); |
955 |
960 |
if (rg_rights_allow($a['rights'], "H") === FALSE) { |
if (rg_rights_allow($a['rights'], "H") === FALSE) { |
956 |
|
$msg = rg_template("msg/push_not_allowed.txt", array()); |
|
|
961 |
|
$_x = array(); |
|
962 |
|
$msg = rg_template("msg/push_not_allowed.txt", $_x); |
957 |
963 |
rg_git_fatal($a['refname']. "\n" . $msg); |
rg_git_fatal($a['refname']. "\n" . $msg); |
958 |
964 |
} |
} |
959 |
965 |
|
|
|
... |
... |
function rg_git_update_branch($a) |
973 |
979 |
$a['old_rev'], $a['new_rev'], $a['refname'], $a['ip']); |
$a['old_rev'], $a['new_rev'], $a['refname'], $a['ip']); |
974 |
980 |
if ($r !== TRUE) |
if ($r !== TRUE) |
975 |
981 |
rg_git_fatal($a['refname'] . ": " . rg_mr_error()); |
rg_git_fatal($a['refname'] . ": " . rg_mr_error()); |
976 |
|
$msg = rg_template("msg/push_merge_request.txt", array()); |
|
|
982 |
|
$_x = array(); |
|
983 |
|
$msg = rg_template("msg/push_merge_request.txt", $_x); |
977 |
984 |
rg_git_info($a['refname'] . "\n" . $msg); |
rg_git_info($a['refname'] . "\n" . $msg); |
978 |
985 |
} else { |
} else { |
979 |
986 |
rg_log("We are allowed to push."); |
rg_log("We are allowed to push."); |
File inc/user/repo-page.php changed (mode: 100644) (index af6d253..05f94ed) |
... |
... |
if (rg_repo_ok($rr['repo']) !== TRUE) { |
16 |
16 |
|
|
17 |
17 |
// Git dir is done asynchronous, loop till is OK |
// Git dir is done asynchronous, loop till is OK |
18 |
18 |
while (1) { |
while (1) { |
19 |
|
$ri = rg_repo_info($db, $rr); |
|
|
19 |
|
$ri = rg_repo_info($db, $rg_ui['uid'], 0, $rr['repo']); |
20 |
20 |
if ($ri === FALSE) { |
if ($ri === FALSE) { |
21 |
21 |
$_repo_page .= "Internal error!"; |
$_repo_page .= "Internal error!"; |
22 |
22 |
return; |
return; |
|
... |
... |
$repo_more['max_commit_size'] = $ri['max_commit_size'] == 0 ? "unlimited" : rg_1 |
63 |
63 |
$repo_more['max_users'] = $ri['max_users'] == 0 ? "unlimited" : rg_1000($ri['max_users']); |
$repo_more['max_users'] = $ri['max_users'] == 0 ? "unlimited" : rg_1000($ri['max_users']); |
64 |
64 |
$repo_more['hints'] = ""; |
$repo_more['hints'] = ""; |
65 |
65 |
|
|
66 |
|
$repo_path = rg_repo_path_by_id($ri['uid'], $ri['name']); |
|
|
66 |
|
$repo_path = rg_repo_path_by_id($ri['uid'], $ri['repo_id']); |
67 |
67 |
rg_log("repo_path=$repo_path"); |
rg_log("repo_path=$repo_path"); |
68 |
|
putenv("GIT_DIR=$repo_path"); |
|
|
68 |
|
putenv("GIT_DIR=$repo_path"); // TODO: this will be removed after all functios will got a path para |
69 |
69 |
|
|
70 |
70 |
$repo_more['repo_body'] = ""; |
$repo_more['repo_body'] = ""; |
71 |
71 |
$repo_more['repo_right'] = ""; |
$repo_more['repo_right'] = ""; |
|
... |
... |
if (strcmp($subop, "history") == 0) { |
113 |
113 |
$hints[]['HTML:hint'] = rg_template("hints/repo/clone_git.html", $repo_more); |
$hints[]['HTML:hint'] = rg_template("hints/repo/clone_git.html", $repo_more); |
114 |
114 |
if (rg_rights_allow($ri['default_rights'], "H")) // anonymous push? |
if (rg_rights_allow($ri['default_rights'], "H")) // anonymous push? |
115 |
115 |
$hints[]['HTML:hint'] = rg_template("hints/repo/anon_push.html", $repo_more); |
$hints[]['HTML:hint'] = rg_template("hints/repo/anon_push.html", $repo_more); |
116 |
|
//rg_log("DEBUG: hints1: " . rg_array2string($hints)); |
|
117 |
116 |
$repo_more['HTML:hints'] = rg_template_table("hints/list", $hints, $repo_more); |
$repo_more['HTML:hints'] = rg_template_table("hints/list", $hints, $repo_more); |
118 |
117 |
//rg_log("DEBUG: hints: " . $repo_more['HTML:hints']); |
//rg_log("DEBUG: hints: " . $repo_more['HTML:hints']); |
119 |
118 |
|
|
|
... |
... |
if (strcmp($subop, "history") == 0) { |
161 |
160 |
} |
} |
162 |
161 |
} else { // log is default |
} else { // log is default |
163 |
162 |
// show the log |
// show the log |
164 |
|
$log = rg_git_log(10, "", $ref, FALSE); |
|
|
163 |
|
$log = rg_git_log($repo_path, 10, "", $ref, FALSE); |
165 |
164 |
if ($log === FALSE) { |
if ($log === FALSE) { |
166 |
165 |
rg_log("Error generating log (" . rg_git_error() . ")!"); |
rg_log("Error generating log (" . rg_git_error() . ")!"); |
167 |
|
$_repo_body .= "Error generating log!"; |
|
|
166 |
|
$_repo_body .= rg_warning("Error generating log!"); |
168 |
167 |
// TODO: rg_internal_error? |
// TODO: rg_internal_error? |
169 |
168 |
} else if (empty($log)) { |
} else if (empty($log)) { |
170 |
169 |
$_repo_body .= rg_template("repo/not_init.html", $repo_more); |
$_repo_body .= rg_template("repo/not_init.html", $repo_more); |
|
... |
... |
if (strcmp($subop, "history") == 0) { |
175 |
174 |
} |
} |
176 |
175 |
|
|
177 |
176 |
$type = array_shift($paras); |
$type = array_shift($paras); |
178 |
|
rg_log("DEBUG: log: type=$type"); |
|
|
177 |
|
//rg_log("DEBUG: log: type=$type"); |
179 |
178 |
if (strcmp($type, "commit") == 0) { |
if (strcmp($type, "commit") == 0) { |
180 |
179 |
$commit = rg_git_reference($paras[0]); |
$commit = rg_git_reference($paras[0]); |
|
180 |
|
// TODO: check error code |
181 |
181 |
rg_log("Show diff for commit [$commit]"); |
rg_log("Show diff for commit [$commit]"); |
182 |
182 |
|
|
183 |
183 |
if (strstr($commit, "..")) { |
if (strstr($commit, "..")) { |
|
... |
... |
if (strcmp($subop, "history") == 0) { |
189 |
189 |
$second = $commit; |
$second = $commit; |
190 |
190 |
} |
} |
191 |
191 |
|
|
192 |
|
$log = rg_git_log(1, $first, $second, TRUE); |
|
193 |
|
rg_log("log: " . rg_array2string($log)); |
|
194 |
|
|
|
195 |
|
// stats |
|
196 |
|
$_repo_body .= rg_git_files_stats($log[0]['files'], "repo/fstat"); |
|
|
192 |
|
$log = rg_git_log($repo_path, 1, $first, $second, TRUE); |
|
193 |
|
if ($log === FALSE) { |
|
194 |
|
$_repo_body .= rg_warning("Could not generate log."); |
|
195 |
|
rg_internal_error("Could not generate log!"); |
|
196 |
|
} else { |
|
197 |
|
// stats |
|
198 |
|
//rg_log("DEBUG: log[0]['files']: " . rg_array2string($log[0]['files'])); |
|
199 |
|
$_r = rg_git_files_stats($log[0]['files'], "repo/fstat"); |
|
200 |
|
//rg_log("DEBUG: files_stats: " . $_r); |
|
201 |
|
if ($_r === FALSE) |
|
202 |
|
rg_internal_error("Could not generate file stats" |
|
203 |
|
. " (" . rg_git_error() . ")!"); |
|
204 |
|
else |
|
205 |
|
$_repo_body .= $_r; |
197 |
206 |
|
|
198 |
|
// diff |
|
199 |
|
//rg_log("patch: " . print_r($log[0]['patches'], TRUE)); |
|
200 |
|
$_repo_body .= rg_git_diff($log[0]['patches'], "repo/diff.html"); |
|
|
207 |
|
// diff |
|
208 |
|
//rg_log("DEBUG: log[0]['patches']: " . rg_array2string($log[0]['patches'])); |
|
209 |
|
$_r = rg_git_diff($log[0]['patches'], "repo/diff.html"); |
|
210 |
|
//rg_log("DEBUG: git_diff: " . $_r); |
|
211 |
|
if ($_r === FALSE) |
|
212 |
|
rg_internal_error("Could not generate patches" |
|
213 |
|
. " (" . rg_git_error() . ")."); |
|
214 |
|
else |
|
215 |
|
$_repo_body .= $_r; |
|
216 |
|
} |
201 |
217 |
} |
} |
202 |
218 |
} |
} |
203 |
219 |
$_repo_right = rg_template("repo/source_r.html", $repo_more); |
$_repo_right = rg_template("repo/source_r.html", $repo_more); |
|
... |
... |
if (strcmp($subop, "history") == 0) { |
226 |
242 |
break; |
break; |
227 |
243 |
} |
} |
228 |
244 |
|
|
229 |
|
$_log = rg_git_log(0, $mri['old_rev'], $mri['new_rev'], TRUE); |
|
|
245 |
|
$_log = rg_git_log($repo_path, 0, $mri['old_rev'], $mri['new_rev'], TRUE); |
230 |
246 |
if ($_log === FALSE) { |
if ($_log === FALSE) { |
231 |
|
$_repo_body .= "Error generating patch (" . rg_git_error() . ")."; |
|
|
247 |
|
$_repo_body .= rg_warning("Error generating patch."); |
232 |
248 |
break; |
break; |
233 |
249 |
} |
} |
234 |
250 |
|
|
|
... |
... |
if (strcmp($subop, "history") == 0) { |
240 |
256 |
|
|
241 |
257 |
$repo_more['HTML:repo_body'] = $_repo_body; |
$repo_more['HTML:repo_body'] = $_repo_body; |
242 |
258 |
$repo_more['HTML:repo_right'] = $_repo_right; |
$repo_more['HTML:repo_right'] = $_repo_right; |
|
259 |
|
file_put_contents("/tmp/repo-body.txt", print_r($_repo_body, TRUE)); |
|
260 |
|
file_put_contents("/tmp/repo-more.txt", print_r($repo_more, TRUE)); |
243 |
261 |
$_repo_page = rg_template("repo/main.html", $repo_more); |
$_repo_page = rg_template("repo/main.html", $repo_more); |
|
262 |
|
file_put_contents("/tmp/repo-page.txt", $_repo_page); |
244 |
263 |
?> |
?> |
File inc/util.inc.php changed (mode: 100644) (index 675c187..c3f3e6a) |
... |
... |
function rg_id($len) |
63 |
63 |
return substr($id, 0, $len); |
return substr($id, 0, $len); |
64 |
64 |
} |
} |
65 |
65 |
|
|
|
66 |
|
/* |
|
67 |
|
* Locks a file |
|
68 |
|
*/ |
66 |
69 |
$_lock = array(); |
$_lock = array(); |
67 |
70 |
function rg_lock($file) |
function rg_lock($file) |
68 |
71 |
{ |
{ |
|
... |
... |
function rg_lock($file) |
73 |
76 |
$rg_lock_dir = "/var/lib/rocketgit/locks"; |
$rg_lock_dir = "/var/lib/rocketgit/locks"; |
74 |
77 |
|
|
75 |
78 |
// Double locking? |
// Double locking? |
76 |
|
if (isset($_lock[$file])) |
|
|
79 |
|
if (isset($_lock[$file])) { |
|
80 |
|
rg_internal_error("Double locking [$file]: " |
|
81 |
|
. rg_array2string($_lock)); |
77 |
82 |
return FALSE; |
return FALSE; |
|
83 |
|
} |
78 |
84 |
|
|
79 |
85 |
$f = @fopen($rg_lock_dir . "/" . $file, "w"); |
$f = @fopen($rg_lock_dir . "/" . $file, "w"); |
80 |
|
if ($f === FALSE) |
|
|
86 |
|
if ($f === FALSE) { |
|
87 |
|
rg_internal_error("Cannot open lock $file ($php_errormsg)."); |
81 |
88 |
return FALSE; |
return FALSE; |
|
89 |
|
} |
82 |
90 |
|
|
83 |
91 |
if (!flock($f, LOCK_EX | LOCK_NB)) { |
if (!flock($f, LOCK_EX | LOCK_NB)) { |
84 |
92 |
fclose($f); |
fclose($f); |
|
... |
... |
function rg_prepare_image($line) |
399 |
407 |
return preg_replace_callback('/@@IMG:(.*)@@/uU', "rg_image_callback", $line); |
return preg_replace_callback('/@@IMG:(.*)@@/uU', "rg_image_callback", $line); |
400 |
408 |
} |
} |
401 |
409 |
|
|
|
410 |
|
function rg_prepare_replace(&$data, &$what, &$values) |
|
411 |
|
{ |
|
412 |
|
if (!empty($data)) { |
|
413 |
|
if (!is_array($data)) |
|
414 |
|
rg_internal_error("invalid type passed"); |
|
415 |
|
foreach ($data as $k => $v) { |
|
416 |
|
if (strncmp($k, "HTML:", 5) == 0) { |
|
417 |
|
$k = substr($k, 5); |
|
418 |
|
} else { |
|
419 |
|
$v = htmlspecialchars($v); |
|
420 |
|
} |
|
421 |
|
$what[$k] = "/@@" . $k . "@@/uU"; |
|
422 |
|
$values[$k] = $v; |
|
423 |
|
} |
|
424 |
|
} |
|
425 |
|
|
|
426 |
|
$what['DUMP'] = "/@@DUMP@@/uU"; |
|
427 |
|
$values['DUMP'] = htmlspecialchars(print_r($data, TRUE)); |
|
428 |
|
|
|
429 |
|
// we replace @@unknown@@ with empty |
|
430 |
|
//$what['FINAL'] = "/@@.*@@/U"; |
|
431 |
|
//$values['FINAL'] = ""; |
|
432 |
|
|
|
433 |
|
//rg_log_ml("DEBUG: what: " . print_r($what, TRUE)); |
|
434 |
|
//rg_log_ml("DEBUG: values: " . print_r($values, TRUE)); |
|
435 |
|
} |
|
436 |
|
|
|
437 |
|
/* |
|
438 |
|
* Lookup a var into data array, if needed |
|
439 |
|
*/ |
|
440 |
|
function rg_replace_lookup(&$data, $var) |
|
441 |
|
{ |
|
442 |
|
rg_prepare_replace($data, $what, $values); |
|
443 |
|
return preg_replace($what, $values, $var); |
|
444 |
|
} |
|
445 |
|
|
402 |
446 |
/* |
/* |
403 |
447 |
* Helper for rg_replace_conditionals. |
* Helper for rg_replace_conditionals. |
404 |
448 |
* It works at line level. |
* It works at line level. |
405 |
449 |
* @master_block (TRUE / FALSE) is the condition for parent block. |
* @master_block (TRUE / FALSE) is the condition for parent block. |
406 |
450 |
*/ |
*/ |
407 |
|
function rg_replace_conditionals_block($block, &$stack) |
|
|
451 |
|
function rg_replace_conditionals_block($block, &$data, &$stack) |
408 |
452 |
{ |
{ |
409 |
|
//rg_log("rg_replace_conditionals_block: block=[$block]" |
|
410 |
|
// . " stack=" . rg_array2string($stack)); |
|
|
453 |
|
rg_log("rg_replace_conditionals_block: block=[$block]" |
|
454 |
|
. " stack=" . rg_array2string($stack)); |
411 |
455 |
|
|
412 |
456 |
if (!is_string($block)) { |
if (!is_string($block)) { |
413 |
457 |
rg_internal_error("Block is not a string!"); |
rg_internal_error("Block is not a string!"); |
|
... |
... |
function rg_replace_conditionals_block($block, &$stack) |
415 |
459 |
} |
} |
416 |
460 |
|
|
417 |
461 |
// Nesting error |
// Nesting error |
418 |
|
// TODO: rg_internal_error? |
|
419 |
|
if (empty($stack)) |
|
|
462 |
|
if (empty($stack)) { |
|
463 |
|
rg_internal_error("Nesting error!"); |
420 |
464 |
return FALSE; |
return FALSE; |
|
465 |
|
} |
421 |
466 |
|
|
422 |
467 |
$cond = array_pop($stack); |
$cond = array_pop($stack); |
423 |
468 |
$stack[] = $cond; |
$stack[] = $cond; |
|
... |
... |
function rg_replace_conditionals_block($block, &$stack) |
433 |
478 |
if ($r === FALSE) |
if ($r === FALSE) |
434 |
479 |
return FALSE; |
return FALSE; |
435 |
480 |
if ($r === 1) { |
if ($r === 1) { |
436 |
|
//rg_log("matches: " . rg_array2string($matches)); |
|
|
481 |
|
//rg_log("DEBUG: matches: " . rg_array2string($matches)); |
437 |
482 |
|
|
438 |
483 |
$ret = ""; |
$ret = ""; |
439 |
|
if ($cond) |
|
|
484 |
|
if ($cond === TRUE) |
440 |
485 |
$ret = $matches[1]; |
$ret = $matches[1]; |
441 |
486 |
|
|
442 |
487 |
$rest = $matches[4]; |
$rest = $matches[4]; |
|
... |
... |
function rg_replace_conditionals_block($block, &$stack) |
447 |
492 |
} else if (strcmp($matches[2], "{{") == 0) { |
} else if (strcmp($matches[2], "{{") == 0) { |
448 |
493 |
//rg_log("{{"); |
//rg_log("{{"); |
449 |
494 |
} else { |
} else { |
450 |
|
//rg_log("cond=" . $matches[3]); |
|
|
495 |
|
//rg_log("DEBUG: cond=" . $matches[3]); |
451 |
496 |
if (empty($matches[3])) { |
if (empty($matches[3])) { |
452 |
497 |
$new_cond = FALSE; |
$new_cond = FALSE; |
453 |
498 |
} else { |
} else { |
454 |
|
$r = preg_match('/^(.+?)(\s*(==|!=)?\s*(.*?))?$/su', |
|
|
499 |
|
$r = preg_match('/^\s*(.*?)\s*(==|!=)\s*(.*?)\s*$/su', |
455 |
500 |
$matches[3], $matches2); |
$matches[3], $matches2); |
456 |
501 |
if ($r === FALSE) { |
if ($r === FALSE) { |
457 |
502 |
rg_internal_error("Invalid condition!"); |
rg_internal_error("Invalid condition!"); |
458 |
503 |
return FALSE; |
return FALSE; |
459 |
504 |
} |
} |
460 |
|
//rg_log("matches2: " . rg_array2string($matches2)); |
|
461 |
|
$left = trim($matches2[1]); |
|
462 |
|
$op = trim($matches2[3]); |
|
463 |
|
$right = trim($matches2[4]); |
|
464 |
|
//rg_log("if left=[$left] op=[$op] right=[$right]"); |
|
|
505 |
|
//rg_log("DEBUG: matches2: " . rg_array2string($matches2)); |
|
506 |
|
$left = rg_replace_lookup($data, trim($matches2[1])); |
|
507 |
|
$op = trim($matches2[2]); |
|
508 |
|
$right = rg_replace_lookup($data, trim($matches2[3])); |
|
509 |
|
//rg_log("DEBUG: if left=[$left] op=[$op] right=[$right]"); |
465 |
510 |
if (empty($op)) { |
if (empty($op)) { |
466 |
511 |
$new_cond = empty($left) ? FALSE : TRUE; |
$new_cond = empty($left) ? FALSE : TRUE; |
467 |
512 |
} else if (strcmp($op, "==") == 0) { |
} else if (strcmp($op, "==") == 0) { |
|
... |
... |
function rg_replace_conditionals_block($block, &$stack) |
481 |
526 |
$stack[] = $new_cond && $cond; |
$stack[] = $new_cond && $cond; |
482 |
527 |
} |
} |
483 |
528 |
|
|
484 |
|
$tmp = rg_replace_conditionals_block($rest, $stack); |
|
|
529 |
|
$tmp = rg_replace_conditionals_block($rest, $data, $stack); |
485 |
530 |
if ($tmp === FALSE) |
if ($tmp === FALSE) |
486 |
531 |
return FALSE; |
return FALSE; |
487 |
532 |
|
|
488 |
|
//rg_log("returning [" . $ret . $tmp . "]"); |
|
|
533 |
|
//rg_log("DEBUG: returning [" . $ret . $tmp . "]"); |
489 |
534 |
return $ret . $tmp; |
return $ret . $tmp; |
490 |
535 |
} |
} |
491 |
536 |
|
|
492 |
537 |
if ($cond === FALSE) |
if ($cond === FALSE) |
493 |
538 |
$block = ""; |
$block = ""; |
494 |
539 |
|
|
495 |
|
//rg_log("returning [$block]"); |
|
|
540 |
|
//rg_log("DEBUG: returning [$block]"); |
496 |
541 |
return $block; |
return $block; |
497 |
542 |
} |
} |
498 |
543 |
|
|
|
... |
... |
function rg_replace_conditionals_block($block, &$stack) |
505 |
550 |
* TODO: Also, we must have both branches (both true and false), for now. |
* TODO: Also, we must have both branches (both true and false), for now. |
506 |
551 |
* We support nested ifs. |
* We support nested ifs. |
507 |
552 |
*/ |
*/ |
508 |
|
function rg_replace_conditionals($block) |
|
|
553 |
|
function rg_replace_conditionals($block, &$data) |
509 |
554 |
{ |
{ |
|
555 |
|
rg_prof_start("replace_conditionals"); |
510 |
556 |
$ret = array(); |
$ret = array(); |
511 |
557 |
|
|
512 |
|
$stack = array(); |
|
513 |
|
$stack[] = TRUE; |
|
514 |
|
$ret = rg_replace_conditionals_block($block, $stack); |
|
515 |
|
|
|
516 |
|
if (empty($stack) || ($stack[0] !== TRUE)) { |
|
517 |
|
rg_internal_error("Template nesting error!"); |
|
518 |
|
return FALSE; |
|
519 |
|
} |
|
520 |
|
|
|
521 |
|
return $ret; |
|
522 |
|
} |
|
|
558 |
|
do { |
|
559 |
|
$stack = array(); |
|
560 |
|
$stack[] = TRUE; |
|
561 |
|
$ret = rg_replace_conditionals_block($block, $data, $stack); |
|
562 |
|
if ($ret === FALSE) |
|
563 |
|
break; |
523 |
564 |
|
|
524 |
|
function rg_prepare_replace(&$data, &$what, &$values) |
|
525 |
|
{ |
|
526 |
|
if (!empty($data)) { |
|
527 |
|
if (!is_array($data)) |
|
528 |
|
rg_internal_error("invalid type passed"); |
|
529 |
|
foreach ($data as $k => $v) { |
|
530 |
|
if (strncmp($k, "HTML:", 5) == 0) { |
|
531 |
|
$k = substr($k, 5); |
|
532 |
|
} else { |
|
533 |
|
$v = htmlspecialchars($v); |
|
534 |
|
} |
|
535 |
|
$what[$k] = "/@@" . $k . "@@/uU"; |
|
536 |
|
$values[$k] = $v; |
|
|
565 |
|
if (empty($stack) || ($stack[0] !== TRUE)) { |
|
566 |
|
rg_internal_error("Template nesting error!"); |
|
567 |
|
$ret = FALSE; |
|
568 |
|
break; |
537 |
569 |
} |
} |
538 |
|
} |
|
539 |
|
|
|
540 |
|
$what['DUMP'] = "/@@DUMP@@/uU"; |
|
541 |
|
$values['DUMP'] = htmlspecialchars(print_r($data, TRUE)); |
|
542 |
|
|
|
543 |
|
// we replace @@unknown@@ with empty |
|
544 |
|
//$what['FINAL'] = "/@@.*@@/U"; |
|
545 |
|
//$values['FINAL'] = ""; |
|
|
570 |
|
} while (0); |
546 |
571 |
|
|
547 |
|
//rg_log_ml("DEBUG: what: " . print_r($what, TRUE)); |
|
548 |
|
//rg_log_ml("DEBUG: values: " . print_r($values, TRUE)); |
|
|
572 |
|
rg_prof_end("replace_conditionals"); |
|
573 |
|
return $ret; |
549 |
574 |
} |
} |
550 |
575 |
|
|
551 |
576 |
/* |
/* |
|
... |
... |
function rg_prepare_replace(&$data, &$what, &$values) |
553 |
578 |
*/ |
*/ |
554 |
579 |
function rg_file_get_contents($f) |
function rg_file_get_contents($f) |
555 |
580 |
{ |
{ |
556 |
|
if (!file_exists($f)) { |
|
557 |
|
rg_log("File $f does not exists."); |
|
|
581 |
|
if (!file_exists($f)) |
|
582 |
|
return ""; |
|
583 |
|
|
|
584 |
|
$c = file_get_contents($f); |
|
585 |
|
if ($c === FALSE) { |
|
586 |
|
rg_internal_error("Could not load file [$f] ($php_errormsg)."); |
558 |
587 |
return ""; |
return ""; |
559 |
588 |
} |
} |
560 |
589 |
|
|
561 |
|
return @file_get_contents($f); |
|
|
590 |
|
return $c; |
562 |
591 |
} |
} |
563 |
592 |
|
|
564 |
593 |
/* |
/* |
565 |
594 |
* Builds a html output based on a template with header, footer and line |
* Builds a html output based on a template with header, footer and line |
566 |
595 |
*/ |
*/ |
567 |
|
function rg_template_table($dir, $data, $more) |
|
|
596 |
|
function rg_template_table($dir, &$data, $more) |
568 |
597 |
{ |
{ |
569 |
598 |
global $rg_theme; |
global $rg_theme; |
570 |
599 |
global $rg_scripts; |
global $rg_scripts; |
|
... |
... |
function rg_template_table($dir, $data, $more) |
579 |
608 |
$m_what = array(); $m_values = array(); |
$m_what = array(); $m_values = array(); |
580 |
609 |
rg_prepare_replace($more, $m_what, $m_values); |
rg_prepare_replace($more, $m_what, $m_values); |
581 |
610 |
|
|
582 |
|
if (!is_array($data) || (count($data) == 0)) { |
|
|
611 |
|
if (!is_array($data) || empty($data)) { |
583 |
612 |
$no_data = rg_file_get_contents($xdir . "/nodata.html"); |
$no_data = rg_file_get_contents($xdir . "/nodata.html"); |
584 |
|
$_tmp = preg_replace($m_what, $m_values, $no_data); |
|
585 |
|
return rg_replace_conditionals($_tmp); |
|
|
613 |
|
$r = rg_replace_conditionals($no_data, $data); |
|
614 |
|
return preg_replace($m_what, $m_values, $r); |
586 |
615 |
} |
} |
587 |
616 |
|
|
588 |
617 |
$head = rg_file_get_contents($xdir . "/header.html"); |
$head = rg_file_get_contents($xdir . "/header.html"); |
|
... |
... |
function rg_template_table($dir, $data, $more) |
590 |
619 |
$foot = rg_file_get_contents($xdir . "/footer.html"); |
$foot = rg_file_get_contents($xdir . "/footer.html"); |
591 |
620 |
$between = rg_file_get_contents($xdir . "/between.html"); |
$between = rg_file_get_contents($xdir . "/between.html"); |
592 |
621 |
|
|
|
622 |
|
$head = rg_replace_conditionals($head, $data); |
|
623 |
|
$foot = rg_replace_conditionals($foot, $data); |
|
624 |
|
$between = rg_replace_conditionals($between, $data); |
|
625 |
|
|
593 |
626 |
$head = preg_replace($m_what, $m_values, $head); |
$head = preg_replace($m_what, $m_values, $head); |
594 |
627 |
$foot = preg_replace($m_what, $m_values, $foot); |
$foot = preg_replace($m_what, $m_values, $foot); |
595 |
628 |
$between = preg_replace($m_what, $m_values, $between); |
$between = preg_replace($m_what, $m_values, $between); |
|
... |
... |
function rg_template_table($dir, $data, $more) |
609 |
642 |
$body .= $between; |
$body .= $between; |
610 |
643 |
} |
} |
611 |
644 |
|
|
612 |
|
$body .= preg_replace($what, $values, $line); |
|
|
645 |
|
$r = rg_replace_conditionals($line, $data); |
|
646 |
|
$body .= preg_replace($what, $values, $r); |
613 |
647 |
} |
} |
614 |
648 |
|
|
615 |
|
return rg_replace_conditionals($head . $body . $foot); |
|
|
649 |
|
return $head . $body . $foot; |
616 |
650 |
} |
} |
617 |
651 |
|
|
618 |
|
function rg_template($file, $data) |
|
|
652 |
|
function rg_template($file, &$data) |
619 |
653 |
{ |
{ |
620 |
654 |
global $rg_scripts; |
global $rg_scripts; |
621 |
655 |
global $rg_theme; |
global $rg_theme; |
622 |
656 |
|
|
|
657 |
|
rg_log("Loading template from $file..."); |
|
658 |
|
|
623 |
659 |
$xfile = $rg_scripts . "/root/themes/" . $rg_theme . "/" . $file; |
$xfile = $rg_scripts . "/root/themes/" . $rg_theme . "/" . $file; |
624 |
660 |
if (!is_file($xfile)) |
if (!is_file($xfile)) |
625 |
661 |
$xfile = $rg_scripts . "/root/themes/default/" . $file; |
$xfile = $rg_scripts . "/root/themes/default/" . $file; |
626 |
662 |
|
|
627 |
663 |
$body = rg_file_get_contents($xfile); |
$body = rg_file_get_contents($xfile); |
628 |
|
if (empty($body)) |
|
|
664 |
|
if (empty($body)) { |
|
665 |
|
rg_log("File [$xfile] is empty. Return ''."); |
629 |
666 |
return ""; |
return ""; |
|
667 |
|
} |
630 |
668 |
|
|
631 |
669 |
$what = array(); |
$what = array(); |
632 |
670 |
$values = array(); |
$values = array(); |
|
... |
... |
function rg_template($file, $data) |
635 |
673 |
|
|
636 |
674 |
$body = rg_prepare_image($body); |
$body = rg_prepare_image($body); |
637 |
675 |
|
|
638 |
|
$ret = preg_replace($what, $values, $body); |
|
|
676 |
|
$r = rg_replace_conditionals($body, $data); |
|
677 |
|
// TODO: check error code! |
|
678 |
|
rg_log_ml("r=" . print_r($r, TRUE)); |
|
679 |
|
|
|
680 |
|
$ret = preg_replace($what, $values, $r); |
|
681 |
|
// TODO: check error code! |
639 |
682 |
|
|
640 |
|
return rg_replace_conditionals($ret); |
|
|
683 |
|
return $ret; |
641 |
684 |
} |
} |
642 |
685 |
|
|
643 |
686 |
/* |
/* |
|
... |
... |
function rg_template_errmsg($a) |
680 |
723 |
*/ |
*/ |
681 |
724 |
function rg_warning($msg) |
function rg_warning($msg) |
682 |
725 |
{ |
{ |
683 |
|
return rg_template("warning.html", array("msg" => $msg)); |
|
|
726 |
|
$x = array("msg" => $msg); |
|
727 |
|
return rg_template("warning.html", $x); |
684 |
728 |
} |
} |
685 |
729 |
|
|
686 |
730 |
/* |
/* |
|
... |
... |
function rg_warning($msg) |
688 |
732 |
*/ |
*/ |
689 |
733 |
function rg_ok($msg) |
function rg_ok($msg) |
690 |
734 |
{ |
{ |
691 |
|
return rg_template("ok.html", array("msg" => $msg)); |
|
|
735 |
|
$x = array("msg" => $msg); |
|
736 |
|
return rg_template("ok.html", $x); |
692 |
737 |
} |
} |
693 |
738 |
|
|
694 |
739 |
/* |
/* |
|
... |
... |
function rg_ok($msg) |
696 |
741 |
*/ |
*/ |
697 |
742 |
function rg_exec($cmd) |
function rg_exec($cmd) |
698 |
743 |
{ |
{ |
699 |
|
rg_prof_start("exec($cmd)"); |
|
|
744 |
|
rg_prof_start("exec"); |
700 |
745 |
rg_log("Executing [$cmd]..."); |
rg_log("Executing [$cmd]..."); |
701 |
746 |
|
|
702 |
747 |
$ret = array(); |
$ret = array(); |
|
... |
... |
function rg_exec($cmd) |
778 |
823 |
} |
} |
779 |
824 |
} while (0); |
} while (0); |
780 |
825 |
|
|
781 |
|
rg_prof_end("exec($cmd)"); |
|
|
826 |
|
rg_prof_end("exec"); |
782 |
827 |
return $ret; |
return $ret; |
783 |
828 |
} |
} |
784 |
829 |
|
|
|
... |
... |
function rg_copy_tree($src, $dst, $mask) |
924 |
969 |
*/ |
*/ |
925 |
970 |
function rg_error_handler($no, $str, $file, $line) |
function rg_error_handler($no, $str, $file, $line) |
926 |
971 |
{ |
{ |
|
972 |
|
global $rg_admin_email; |
|
973 |
|
|
927 |
974 |
if ($no == 0) |
if ($no == 0) |
928 |
975 |
return; |
return; |
929 |
976 |
|
|
930 |
977 |
$str = str_replace("\n", "\\n", $str); |
$str = str_replace("\n", "\\n", $str); |
931 |
978 |
|
|
932 |
|
rg_log("PHP ERROR: $file:$line: $str (errno=$no)"); |
|
|
979 |
|
$msg = "PHP ERROR: $file:$line: $str (errno=$no)"; |
|
980 |
|
rg_log($msg); |
|
981 |
|
|
|
982 |
|
mail("rg_error@embedromix.ro", $msg, |
|
983 |
|
"", "", "-f $rg_admin_email"); |
933 |
984 |
|
|
934 |
985 |
if ($no == E_ERROR) |
if ($no == E_ERROR) |
935 |
986 |
die(); |
die(); |
File tests/util.php changed (mode: 100644) (index 972ec87..2a3ed7e) |
... |
... |
rg_log_set_file("util.log"); |
11 |
11 |
|
|
12 |
12 |
$rg_scripts = "."; |
$rg_scripts = "."; |
13 |
13 |
$rg_theme = "util"; |
$rg_theme = "util"; |
|
14 |
|
$rg_admin_email = "rg@embedromix.ro"; |
14 |
15 |
|
|
15 |
16 |
$id = rg_id(16); |
$id = rg_id(16); |
16 |
17 |
if (strlen($id) != 16) { |
if (strlen($id) != 16) { |
|
... |
... |
if ($r['code'] != 5) { |
48 |
49 |
exit(1); |
exit(1); |
49 |
50 |
} |
} |
50 |
51 |
|
|
51 |
|
// test rg_template_table($dir, $data, $more) with no data |
|
52 |
|
$r = rg_template_table("t1", array(), array("a" => "A")); |
|
|
52 |
|
$t = "test rg_template_table(dir, data, more) with no data"; |
|
53 |
|
rg_log($t); |
|
54 |
|
$data = array(); |
|
55 |
|
$r = rg_template_table("t1", $data, array("a" => "A")); |
53 |
56 |
$e = "XAX"; |
$e = "XAX"; |
54 |
57 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
55 |
|
echo "util.php: nodata.html is not working (r=$r e=$e)!\n"; |
|
|
58 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
56 |
59 |
exit(1); |
exit(1); |
57 |
60 |
} |
} |
58 |
61 |
|
|
59 |
|
// test rg_template_table($dir, $data, $more) with data |
|
|
62 |
|
$t = "test rg_template_table(dir, data, more) with data"; |
|
63 |
|
rg_log($t); |
60 |
64 |
$data = array(array("a" => "A", "b" => "B"), array("a" => "A2", "b" => "B2")); |
$data = array(array("a" => "A", "b" => "B"), array("a" => "A2", "b" => "B2")); |
61 |
65 |
$r = rg_template_table("t2", $data, array("c" => "C")); |
$r = rg_template_table("t2", $data, array("c" => "C")); |
62 |
66 |
$e = "HEADCABCA2B2CFOOTC"; |
$e = "HEADCABCA2B2CFOOTC"; |
63 |
67 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
64 |
|
echo "util.php: rg_template_table is not working (r=$r e=$e)!\n"; |
|
|
68 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
65 |
69 |
exit(1); |
exit(1); |
66 |
70 |
} |
} |
67 |
71 |
|
|
68 |
|
// test rg_template with conditional formating (false) |
|
|
72 |
|
$t = "test rg_template with conditional formating (false)"; |
|
73 |
|
rg_log($t); |
69 |
74 |
$data = array("X" => "0", "A" => "Avalue", "B" => "Bvalue"); |
$data = array("X" => "0", "A" => "Avalue", "B" => "Bvalue"); |
70 |
75 |
$r = rg_template("t3/c1", $data); |
$r = rg_template("t3/c1", $data); |
71 |
76 |
$e = "XXBvalueYY"; |
$e = "XXBvalueYY"; |
72 |
77 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
73 |
|
echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; |
|
|
78 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
74 |
79 |
exit(1); |
exit(1); |
75 |
80 |
} |
} |
76 |
81 |
|
|
77 |
|
// test rg_template with conditional formating (true) |
|
|
82 |
|
$t = "test rg_template with conditional formating (true)"; |
|
83 |
|
rg_log($t); |
78 |
84 |
$data = array("X" => "1", "A" => "Avalue", "B" => "Bvalue"); |
$data = array("X" => "1", "A" => "Avalue", "B" => "Bvalue"); |
79 |
85 |
$r = rg_template("t3/c1", $data); |
$r = rg_template("t3/c1", $data); |
80 |
86 |
$e = "XXAvalueYY"; |
$e = "XXAvalueYY"; |
81 |
87 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
82 |
|
echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; |
|
|
88 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
83 |
89 |
exit(1); |
exit(1); |
84 |
90 |
} |
} |
85 |
91 |
|
|
86 |
|
// test rg_template with conditional formating (multiline) |
|
|
92 |
|
$t = "test rg_template with conditional formating (multiline)"; |
|
93 |
|
rg_log($t); |
87 |
94 |
$data = array("X" => "1", "A" => "Avalue", "B" => "Bvalue"); |
$data = array("X" => "1", "A" => "Avalue", "B" => "Bvalue"); |
88 |
95 |
$r = rg_template("t3/c1", $data); |
$r = rg_template("t3/c1", $data); |
89 |
96 |
$e = "XXAvalueYY"; |
$e = "XXAvalueYY"; |
90 |
97 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
91 |
|
echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; |
|
|
98 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
92 |
99 |
exit(1); |
exit(1); |
93 |
100 |
} |
} |
94 |
101 |
|
|
95 |
|
// test rg_template with conditional formating (nested 1) |
|
|
102 |
|
$t = "test rg_template with conditional formating (nested 1)"; |
|
103 |
|
rg_log($t); |
96 |
104 |
$data = array("X" => "1", "Y" => "1", "A" => "Avalue", "B" => "Bvalue", |
$data = array("X" => "1", "Y" => "1", "A" => "Avalue", "B" => "Bvalue", |
97 |
105 |
"R" => "Rvalue", "T" => "Tvalue"); |
"R" => "Rvalue", "T" => "Tvalue"); |
98 |
106 |
$r = rg_template("t3/c3", $data); |
$r = rg_template("t3/c3", $data); |
99 |
107 |
$e = "XXRvalueZZYY"; |
$e = "XXRvalueZZYY"; |
100 |
108 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
101 |
|
echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; |
|
|
109 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
102 |
110 |
exit(1); |
exit(1); |
103 |
111 |
} |
} |
104 |
112 |
|
|
105 |
|
// test rg_template with conditional formating (nested 2) |
|
|
113 |
|
$t = "test rg_template with conditional formating (nested 2)"; |
|
114 |
|
rg_log($t); |
106 |
115 |
$data = array("X" => "1", "Y" => "0", "A" => "Avalue", "B" => "Bvalue", |
$data = array("X" => "1", "Y" => "0", "A" => "Avalue", "B" => "Bvalue", |
107 |
116 |
"R" => "Rvalue", "T" => "Tvalue"); |
"R" => "Rvalue", "T" => "Tvalue"); |
108 |
117 |
$r = rg_template("t3/c3", $data); |
$r = rg_template("t3/c3", $data); |
109 |
118 |
$e = "XXTvalueZZYY"; |
$e = "XXTvalueZZYY"; |
110 |
119 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
111 |
|
echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; |
|
|
120 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
112 |
121 |
exit(1); |
exit(1); |
113 |
122 |
} |
} |
114 |
123 |
|
|
115 |
|
rg_log("test rg_template with conditional formating (nested 3)"); |
|
|
124 |
|
$t = "test rg_template with conditional formating (nested 3)"; |
|
125 |
|
rg_log($t); |
116 |
126 |
$data = array("X" => "0", "Y" => "1", "A" => "Avalue", "B" => "Bvalue", |
$data = array("X" => "0", "Y" => "1", "A" => "Avalue", "B" => "Bvalue", |
117 |
127 |
"R" => "Rvalue", "T" => "Tvalue"); |
"R" => "Rvalue", "T" => "Tvalue"); |
118 |
128 |
$r = rg_template("t3/c3", $data); |
$r = rg_template("t3/c3", $data); |
119 |
129 |
$e = "XXBvalueYY"; |
$e = "XXBvalueYY"; |
120 |
130 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
121 |
|
echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; |
|
|
131 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
122 |
132 |
exit(1); |
exit(1); |
123 |
133 |
} |
} |
124 |
134 |
|
|
125 |
|
rg_log("test rg_template with conditional formating (nested nested 1)"); |
|
|
135 |
|
$t = "test rg_template with conditional formating (nested nested 1)"; |
|
136 |
|
rg_log($t); |
126 |
137 |
$data = array("X" => "1", "Y" => "1", "Z" => "1"); |
$data = array("X" => "1", "Y" => "1", "Z" => "1"); |
127 |
138 |
$r = rg_template("t3/c4", $data); |
$r = rg_template("t3/c4", $data); |
128 |
139 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
129 |
140 |
$e = "XXTRUE_LEVEL_2YY"; |
$e = "XXTRUE_LEVEL_2YY"; |
130 |
141 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
131 |
|
echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; |
|
|
142 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
132 |
143 |
exit(1); |
exit(1); |
133 |
144 |
} |
} |
134 |
145 |
|
|
135 |
|
rg_log("test rg_template with conditional formating (nested nested 2)"); |
|
|
146 |
|
$t = "test rg_template with conditional formating (nested nested 2)"; |
|
147 |
|
rg_log($t); |
136 |
148 |
$data = array("X" => "1", "Y" => "0", "Z" => "1"); |
$data = array("X" => "1", "Y" => "0", "Z" => "1"); |
137 |
149 |
$r = rg_template("t3/c4", $data); |
$r = rg_template("t3/c4", $data); |
138 |
150 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
139 |
151 |
$e = "XXFALSE_LEVEL_1YY"; |
$e = "XXFALSE_LEVEL_1YY"; |
140 |
152 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
141 |
|
echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; |
|
|
153 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
142 |
154 |
exit(1); |
exit(1); |
143 |
155 |
} |
} |
144 |
156 |
|
|
145 |
|
rg_log("test rg_template with conditional formating (nested nested 2)"); |
|
|
157 |
|
$t = "test rg_template with conditional formating (nested nested 2)"; |
|
158 |
|
rg_log($t); |
146 |
159 |
$data = array("X" => "0", "Y" => "1", "Z" => "1"); |
$data = array("X" => "0", "Y" => "1", "Z" => "1"); |
147 |
160 |
$r = rg_template("t3/c4", $data); |
$r = rg_template("t3/c4", $data); |
148 |
161 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
149 |
162 |
$e = "XXFALSE_LEVEL_0YY"; |
$e = "XXFALSE_LEVEL_0YY"; |
150 |
163 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
151 |
|
echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; |
|
|
164 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
152 |
165 |
exit(1); |
exit(1); |
153 |
166 |
} |
} |
154 |
167 |
|
|
155 |
|
rg_log("test rg_template with conditional formating (nested nested 3)"); |
|
|
168 |
|
$t = "test rg_template with conditional formating (nested nested 3)"; |
|
169 |
|
rg_log($t); |
156 |
170 |
$data = array("X" => "0", "Y" => "0", "Z" => "0"); |
$data = array("X" => "0", "Y" => "0", "Z" => "0"); |
157 |
171 |
$r = rg_template("t3/c5", $data); |
$r = rg_template("t3/c5", $data); |
158 |
172 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
159 |
173 |
$e = "XX-X0Y0Z0-YY"; |
$e = "XX-X0Y0Z0-YY"; |
160 |
174 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
161 |
|
echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; |
|
|
175 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
162 |
176 |
exit(1); |
exit(1); |
163 |
177 |
} |
} |
164 |
178 |
|
|
165 |
|
rg_log("test rg_template with conditional formating (nested nested 4)"); |
|
|
179 |
|
$t = "test rg_template with conditional formating (nested nested 4)"; |
|
180 |
|
rg_log($t); |
166 |
181 |
$data = array("X" => "0", "Y" => "1", "Z" => "0"); |
$data = array("X" => "0", "Y" => "1", "Z" => "0"); |
167 |
182 |
$r = rg_template("t3/c5", $data); |
$r = rg_template("t3/c5", $data); |
168 |
183 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
169 |
184 |
$e = "XX-X0Y1Z0-YY"; |
$e = "XX-X0Y1Z0-YY"; |
170 |
185 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
171 |
|
echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; |
|
|
186 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
172 |
187 |
exit(1); |
exit(1); |
173 |
188 |
} |
} |
174 |
189 |
|
|
175 |
|
rg_log("test rg_template with conditional formating (empty)"); |
|
|
190 |
|
$t = "test rg_template with conditional formating (empty)"; |
|
191 |
|
rg_log($t); |
176 |
192 |
$data = array(); |
$data = array(); |
177 |
193 |
$r = rg_template("t3/c6", $data); |
$r = rg_template("t3/c6", $data); |
178 |
194 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
179 |
195 |
$e = "A"; |
$e = "A"; |
180 |
196 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
181 |
|
echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; |
|
|
197 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
182 |
198 |
exit(1); |
exit(1); |
183 |
199 |
} |
} |
184 |
200 |
|
|
185 |
|
rg_log("test rg_template with conditional formating (!empty)"); |
|
|
201 |
|
$t = "test rg_template with conditional formating (!empty)"; |
|
202 |
|
rg_log($t); |
186 |
203 |
$data = array("AAA" => ""); |
$data = array("AAA" => ""); |
187 |
204 |
$r = rg_template("t3/c7", $data); |
$r = rg_template("t3/c7", $data); |
188 |
205 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
189 |
206 |
$e = "B"; |
$e = "B"; |
190 |
207 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
191 |
|
echo "util.php: rg_template with conditionals is not working (r=$r e=$e)!\n"; |
|
|
208 |
|
echo "util.php: $t: not working (r=$r e=$e)!\n"; |
|
209 |
|
exit(1); |
|
210 |
|
} |
|
211 |
|
|
|
212 |
|
$t = "test rg_replace_lookup"; |
|
213 |
|
rg_log($t); |
|
214 |
|
$data = array("AAA" => "1", "BBB" => "2", "CCC" => "1"); |
|
215 |
|
$r = rg_replace_lookup($data, "@@AAA@@@@BBB@@@@CCC@@"); |
|
216 |
|
$e = "121"; |
|
217 |
|
if (strcmp($r, $e) != 0) { |
|
218 |
|
echo "util.php: $t: not working (r=[$r] e=[$e])!\n"; |
|
219 |
|
exit(1); |
|
220 |
|
} |
|
221 |
|
|
|
222 |
|
$t = "test rg_template with conditional formating (a vriable contains '{{')"; |
|
223 |
|
rg_log($t); |
|
224 |
|
$data = array("AAA" => "1", "BBB" => "}}", "CCC" => "{{"); |
|
225 |
|
$r = rg_template("t3/c8", $data); |
|
226 |
|
$r = preg_replace('/\s/', '', $r); |
|
227 |
|
$e = "}}"; |
|
228 |
|
if (strcmp($r, $e) != 0) { |
|
229 |
|
echo "util.php: $t: not working (r=[$r] e=[$e])!\n"; |
192 |
230 |
exit(1); |
exit(1); |
193 |
231 |
} |
} |
194 |
232 |
|
|
195 |
|
// test rg_copy_tree |
|
|
233 |
|
$t = "test rg_copy_tree"; |
|
234 |
|
rg_log($t); |
196 |
235 |
$r = rg_copy_tree("tree1", "tree1.copy", 0755); |
$r = rg_copy_tree("tree1", "tree1.copy", 0755); |
197 |
236 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
198 |
|
echo "rg_copy_tree malfunction!\n"; |
|
|
237 |
|
echo "util.php: $t: not working!\n"; |
199 |
238 |
exit(1); |
exit(1); |
200 |
239 |
} |
} |
201 |
240 |
if (!file_exists("tree1.copy/a/f2")) { |
if (!file_exists("tree1.copy/a/f2")) { |
202 |
|
echo "rg_copy_tree malfunction (f2)!\n"; |
|
|
241 |
|
echo "util.php: $t(2): not working!\n"; |
203 |
242 |
exit(1); |
exit(1); |
204 |
243 |
} |
} |
205 |
244 |
|
|