xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
Commit 3d5b7d5fcc11734f9623a3d6ff0aaa8a332b6bdb

Apply conditionals before replacing variables!
Author: Catalin(ux) M. BOIE
Author date (UTC): 2012-12-02 20:58
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2012-12-02 20:58
Parent(s): 831af837ca9e7fcf56bef81d1831c3150afa7de8
Signing key:
Tree: bde19c82c2092e78ad505c9ce7a0625fa19d3483
File Lines added Lines deleted
TODO 4 0
inc/dispatch/dispatch.php 1 0
inc/events.inc.php 8 5
inc/git.inc.php 119 112
inc/log.inc.php 12 1
inc/repo.inc.php 3 4
inc/ssh.inc.php 2 4
inc/user/repo-page.php 36 17
inc/util.inc.php 123 72
root/index.php 1 1
root/themes/default/index.html 1 1
scripts/events.php 0 1
tests/root/themes/util/t3/c6 1 1
tests/root/themes/util/t3/c7 1 1
tests/root/themes/util/t3/c8 1 0
tests/util.php 73 34
File TODO changed (mode: 100644) (index 5c44107..5c17875)
1 1 == BEFORE FIRST RELEASE! == == BEFORE FIRST RELEASE! ==
2 [ ] When we have a fatal/internal error, we must also record the log in the e-mail.
3 [ ] Where rocketgit repo disappeared on r1?!
4 [ ] Log in YYYY-MM-DD files and ask logrotate to only delete them.
5 Or, set a policy in config.php and do the cleaning by ourselves.
2 6 [ ] repo.php tests does not say "ok". [ ] repo.php tests does not say "ok".
3 7 [ ] Functions from util.inc.php set rg_util_error(). Use it. [ ] Functions from util.inc.php set rg_util_error(). Use it.
4 8 [ ] Rempove all "exit(?)" calls. [ ] Rempove all "exit(?)" calls.
File inc/dispatch/dispatch.php changed (mode: 100644) (index fb56ea9..62c7d12)
... ... case 'suggestion':
62 62 case 'repo-page': case 'repo-page':
63 63 include($INC . "/user/repo-page.php"); include($INC . "/user/repo-page.php");
64 64 $body .= $_repo_page; $body .= $_repo_page;
65 file_put_contents("/tmp/repo-page.tmp", $body);
65 66 break; break;
66 67
67 68 case 'home-page': case 'home-page':
File inc/events.inc.php changed (mode: 100644) (index f329079..5daecd1)
... ... function rg_event_process_queue($db)
199 199 break; break;
200 200 } }
201 201
202 $r = TRUE;
202 $all_good = TRUE;
203 203 while (($row = rg_sql_fetch_array($res))) { while (($row = rg_sql_fetch_array($res))) {
204 204 $ev = unserialize($row['data']); $ev = unserialize($row['data']);
205 205 if ($ev === FALSE) { if ($ev === FALSE) {
206 206 rg_internal_error("Cannot unserialize data"); rg_internal_error("Cannot unserialize data");
207 exit(1);
207 break;
208 208 } }
209 209 $r = rg_event_process($db, $ev); $r = rg_event_process($db, $ev);
210 if ($r !== TRUE)
210 if ($r !== TRUE) {
211 $all_good = FALSE;
211 212 break; break;
213 }
212 214
213 215 $sql = "DELETE FROM events WHERE id = " . $row['id']; $sql = "DELETE FROM events WHERE id = " . $row['id'];
214 216 $res2 = rg_sql_query($db, $sql); $res2 = rg_sql_query($db, $sql);
215 217 rg_sql_free_result($res2); rg_sql_free_result($res2);
216 218 } }
217 if ($r !== TRUE)
218 break;
219 219 rg_sql_free_result($res); rg_sql_free_result($res);
220 220
221 if ($all_good !== TRUE)
222 break;
223
221 224 $r = rg_sql_commit($db); $r = rg_sql_commit($db);
222 225 if ($r !== TRUE) if ($r !== TRUE)
223 226 break; break;
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/log.inc.php changed (mode: 100644) (index 08fa1d5..4005e9f)
... ... function rg_log_ml($str)
59 59
60 60 function rg_fatal($msg) function rg_fatal($msg)
61 61 { {
62 global $rg_admin_email;
63
62 64 rg_log("FATAL: $msg"); rg_log("FATAL: $msg");
63 65
64 66 $bt = debug_backtrace(); $bt = debug_backtrace();
65 67 rg_log_ml("Backtrace: " . print_r($bt, TRUE)); rg_log_ml("Backtrace: " . print_r($bt, TRUE));
68 mail("rg_fatal@embedromix.ro", "FATAL ERROR: $msg",
69 print_r($bt, TRUE), "", "-f $rg_admin_email");
66 70 exit(1); exit(1);
67 71 } }
68 72
69 73 function rg_internal_error($msg) function rg_internal_error($msg)
70 74 { {
75 global $rg_admin_email;
76
71 77 rg_log("Internal error: $msg"); rg_log("Internal error: $msg");
72 78
73 79 $bt = debug_backtrace(); $bt = debug_backtrace();
74 80 rg_log_ml("Backtrace: " . print_r($bt, TRUE)); rg_log_ml("Backtrace: " . print_r($bt, TRUE));
81 mail("rg_ie@embedromix.ro", "INTERNAL ERROR: $msg",
82 print_r($bt, TRUE), "", "-f $rg_admin_email");
75 83 } }
76 84
77 85 // TODO: send mail or store all data in database // TODO: send mail or store all data in database
78 86 function rg_security_violation($msg) function rg_security_violation($msg)
79 87 { {
88 global $rg_admin_email;
89
80 90 rg_log("Security violation: $msg"); rg_log("Security violation: $msg");
81 91
82 92 $bt = debug_backtrace(); $bt = debug_backtrace();
83 93 rg_log_ml("Backtrace: " . print_r($bt, TRUE)); rg_log_ml("Backtrace: " . print_r($bt, TRUE));
84
94 mail("rg_sec@embedromix.ro", "SECURITY VIOLATION: $msg",
95 print_r($bt, TRUE), "", "-f $rg_admin_email");
85 96 exit(1); exit(1);
86 97 } }
87 98
File inc/repo.inc.php changed (mode: 100644) (index da11ac3..9dfe13a)
... ... function rg_repo_info($db, $uid, $repo_id, $repo_name)
288 288 global $rg_repo_info_cache; global $rg_repo_info_cache;
289 289
290 290 rg_prof_start("repo_info"); rg_prof_start("repo_info");
291 rg_log("repo_info: uid=$uid repo_id=$repo_id repo_name=$repo_name");
291 rg_log("repo_info: uid=$uid repo_id=$repo_id repo_name=$repo_name.");
292 292
293 293 $key1 = $uid . "-" . $repo_id; $key1 = $uid . "-" . $repo_id;
294 294 if (isset($rg_repo_info_cache[$key1])) if (isset($rg_repo_info_cache[$key1]))
 
... ... function rg_repo_list_query($db, $url, $sql)
777 777 $master_repo = "-"; $master_repo = "-";
778 778 if ($row['master'] > 0) { if ($row['master'] > 0) {
779 779 $master_repo = "?"; $master_repo = "?";
780 $rr = array("repo_id" => $row['master']);
781 $_mi = rg_repo_info($db, $rr);
780 $_mi = rg_repo_info($db, $_ui['uid'], $row['master'], "");
782 781 if ($_mi['exists'] = 1) if ($_mi['exists'] = 1)
783 782 $master_repo = $_mi['name']; $master_repo = $_mi['name'];
784 783 } }
 
... ... function rg_repo_storage_create($db, $ri)
1043 1042 break; break;
1044 1043 } }
1045 1044 } else { } else {
1046 $mi = rg_repo_info($db, $ri['master'], "");
1045 $mi = rg_repo_info($db, $ri['uid'], $ri['master'], "");
1047 1046 if ($mi['exists'] != 1) { if ($mi['exists'] != 1) {
1048 1047 rg_repo_set_error("cannot find master (" . rg_repo_error() . ")"); rg_repo_set_error("cannot find master (" . rg_repo_error() . ")");
1049 1048 break; break;
File inc/ssh.inc.php changed (mode: 100644) (index fff3b05..f7269c6)
... ... function rg_ssh_repo($db, $uid, $paras)
51 51
52 52 $repo_name = trim($paras[0]); $repo_name = trim($paras[0]);
53 53
54 $rr = array("uid" => $uid, "repo" => $repo_name);
55 $ri = rg_repo_info($db, $rr);
54 $ri = rg_repo_info($db, $uid, 0, $repo_name);
56 55 if ($ri === FALSE) { if ($ri === FALSE) {
57 56 echo "Unknown repo!\n"; echo "Unknown repo!\n";
58 57 exit(0); exit(0);
 
... ... function rg_ssh_repo($db, $uid, $paras)
72 71 echo "Default rights: " . $rights . "\n"; echo "Default rights: " . $rights . "\n";
73 72
74 73 if ($ri['master'] > 0) { if ($ri['master'] > 0) {
75 $rr = array("repo_id" => $ri['master']);
76 $mri = rg_repo_info($db, $rr);
74 $mri = rg_repo_info($db, $uid, $ri['master'], "");
77 75 if ($mri !== FALSE) { if ($mri !== FALSE) {
78 76 echo "Master: " . $mri['name'] . "\n"; echo "Master: " . $mri['name'] . "\n";
79 77 } }
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 root/index.php changed (mode: 100644) (index 3acb327..4b7768a)
... ... if ($r > 0) {
162 162
163 163 rg_prof_end("MAIN"); rg_prof_end("MAIN");
164 164
165 // TODO: Do something with the profiling, here
165 // TODO: Do something with the profiling, here: log it in database etc.
166 166
167 167 $more['HTML:rg_theme_url'] = $THEME_URL; $more['HTML:rg_theme_url'] = $THEME_URL;
168 168 $more['HTML:rg_body'] = $body; $more['HTML:rg_body'] = $body;
File root/themes/default/index.html changed (mode: 100644) (index e6108d0..d25643e)
18 18 <div class="logo"><a href="/">RocketGit</a></div> <div class="logo"><a href="/">RocketGit</a></div>
19 19 </td> </td>
20 20
21 @@if(@@rg_username@@){{
21 @@if("@@rg_username@@" != ""){{
22 22 <td> <td>
23 23 <div class="user"><a href="/">@@rg_username@@</a></div> <div class="user"><a href="/">@@rg_username@@</a></div>
24 24 </td> </td>
File scripts/events.php changed (mode: 100644) (index 3c8e0db..ef1f324)
... ... rg_log("Start...");
36 36 $db = rg_sql_open($rg_sql); $db = rg_sql_open($rg_sql);
37 37 if ($db === FALSE) { if ($db === FALSE) {
38 38 rg_internal_error("Cannot connect to database!"); rg_internal_error("Cannot connect to database!");
39 // TODO: inform admin - already by e-mail?
40 39 exit(1); exit(1);
41 40 } }
42 41
File tests/root/themes/util/t3/c6 changed (mode: 100644) (index 6f9972a..29f3a8b)
1 @@if(a){{A}}{{B}}
1 @@if("a" != ""){{A}}{{B}}
File tests/root/themes/util/t3/c7 changed (mode: 100644) (index 9c9083f..05943bd)
1 @@if(@@AAA@@){{A}}{{B}}
1 @@if(@@AAA@@ == 1){{A}}{{B}}
File tests/root/themes/util/t3/c8 added (mode: 100644) (index 0000000..a7d921b)
1 @@if(@@AAA@@ == 1){{@@BBB@@}}{{@@CCC@@}}
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
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master