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 b25e97c24a24f00d3e6e36652ffc0b9c9bf0e241

rg_exec has new parameters: two callbacks for stdout and stderr
Author: Catalin(ux) M. BOIE
Author date (UTC): 2016-09-05 16:47
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2016-09-05 16:47
Parent(s): f580e2b006e60369265f3a2e660cb8af0701312d
Signing key:
Tree: 301ac5c2601dd14a885765c3c0773d87a678411a
File Lines added Lines deleted
inc/builder.inc.php 1 1
inc/git.inc.php 29 29
inc/totp.inc.php 2 2
inc/util.inc.php 20 8
scripts/worker.php 27 24
tests/export.php 1 1
tests/git2.php 2 2
tests/pr_anon.php 7 7
tests/repo.php 1 1
tests/user.php 1 1
tests/util.php 3 3
tests/wh_cloud.php 1 1
File inc/builder.inc.php changed (mode: 100644) (index f55d480..3abee73)
... ... function rg_builder_add($db, $repo_id, $d)
84 84 function rg_builder_vm_list() function rg_builder_vm_list()
85 85 { {
86 86 $cmd = 'virsh list --name'; $cmd = 'virsh list --name';
87 $r = rg_exec($cmd, '', FALSE);
87 $r = rg_exec($cmd, '', FALSE, FALSE);
88 88 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
89 89 rg_log('Cannot find out virtual machines: ' . $r['errmsg']); rg_log('Cannot find out virtual machines: ' . $r['errmsg']);
90 90 return FALSE; return FALSE;
File inc/git.inc.php changed (mode: 100644) (index 421394a..45f72f6)
... ... function rg_git_init($dst)
134 134 if (!is_dir($dst . "/rocketgit")) { if (!is_dir($dst . "/rocketgit")) {
135 135 $dst2 = $dst . '.tmp'; $dst2 = $dst . '.tmp';
136 136 $cmd = 'git init --bare ' . escapeshellarg($dst2); $cmd = 'git init --bare ' . escapeshellarg($dst2);
137 $a = rg_exec($cmd, '', FALSE);
137 $a = rg_exec($cmd, '', FALSE, FALSE);
138 138 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
139 139 rg_git_set_error("error on init " . $a['errmsg'] . ")"); rg_git_set_error("error on init " . $a['errmsg'] . ")");
140 140 break; break;
 
... ... function rg_git_clone($src, $dst)
185 185 if (!file_exists($dst . "/rocketgit")) { if (!file_exists($dst . "/rocketgit")) {
186 186 $cmd = "git clone --bare " . escapeshellarg($src) $cmd = "git clone --bare " . escapeshellarg($src)
187 187 . " " . escapeshellarg($dst); . " " . escapeshellarg($dst);
188 $a = rg_exec($cmd, '', FALSE);
188 $a = rg_exec($cmd, '', FALSE, FALSE);
189 189 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
190 190 rg_git_set_error("error on clone (" . $a['errmsg'] . ")"); rg_git_set_error("error on clone (" . $a['errmsg'] . ")");
191 191 break; break;
 
... ... function rg_git_type($obj)
216 216 { {
217 217 global $rg_git_zero; global $rg_git_zero;
218 218
219 rg_prof_start("git_type");
220 rg_log_enter("git_type: obj=$obj");
219 rg_prof_start('git_type');
220 rg_log_enter('git_type: obj=' . $obj);
221 221
222 222 $ret = FALSE; $ret = FALSE;
223 223 while (1) { while (1) {
224 224 if (strcmp($obj, $rg_git_zero) == 0) { if (strcmp($obj, $rg_git_zero) == 0) {
225 $ret = "zero";
225 $ret = 'zero';
226 226 break; break;
227 227 } }
228 228
229 $cmd = "git cat-file -t '" . escapeshellarg($obj) . "'";
230 $a = rg_exec($cmd, '', FALSE);
229 $cmd = 'git cat-file -t ' . escapeshellarg($obj);
230 $a = rg_exec($cmd, '', FALSE, FALSE);
231 231 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
232 rg_git_set_error("error on cat-file (" . $a['errmsg'] . ")");
232 rg_git_set_error('error on cat-file (' . $a['errmsg'] . ')');
233 233 break; break;
234 234 } }
235 235
 
... ... function rg_git_type($obj)
238 238 } }
239 239
240 240 rg_log_exit(); rg_log_exit();
241 rg_prof_end("git_type");
241 rg_prof_end('git_type');
242 242 return $ret; return $ret;
243 243 } }
244 244
 
... ... function rg_git_type($obj)
247 247 */ */
248 248 function rg_git_content($obj) function rg_git_content($obj)
249 249 { {
250 rg_prof_start("git_content");
251 rg_log_enter("git_content: obj=$obj");
250 rg_prof_start('git_content');
251 rg_log_enter('git_content: obj=' . $obj);
252 252
253 253 $ret = FALSE; $ret = FALSE;
254 254 while (1) { while (1) {
255 $cmd = "git cat-file -p '" . escapeshellarg($obj) . "'";
256 $a = rg_exec($cmd, '', FALSE);
255 $cmd = 'git cat-file -p ' . escapeshellarg($obj);
256 $a = rg_exec($cmd, '', FALSE, FALSE);
257 257 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
258 rg_git_set_error("error on cat-file (" . $a['errmsg'] . ")");
258 rg_git_set_error('error on cat-file (' . $a['errmsg'] . ')');
259 259 break; break;
260 260 } }
261 261
 
... ... function rg_git_content($obj)
264 264 } }
265 265
266 266 rg_log_exit(); rg_log_exit();
267 rg_prof_end("git_content");
267 rg_prof_end('git_content');
268 268 return $ret; return $ret;
269 269 } }
270 270
 
... ... function rg_git_rev_ok($rev)
330 330 $ret = FALSE; $ret = FALSE;
331 331 while (1) { while (1) {
332 332 $cmd = 'git rev-parse --verify ' . escapeshellarg($rev); $cmd = 'git rev-parse --verify ' . escapeshellarg($rev);
333 $a = rg_exec($cmd, '', FALSE);
333 $a = rg_exec($cmd, '', FALSE, FALSE);
334 334 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
335 335 rg_git_set_error("error on rev-parse (" . $a['errmsg'] . ")"); rg_git_set_error("error on rev-parse (" . $a['errmsg'] . ")");
336 336 break; break;
 
... ... function rg_git_whitespace_ok($old, $new)
365 365 $cmd = "git diff --check" $cmd = "git diff --check"
366 366 . " " . escapeshellarg($old) . " " . escapeshellarg($old)
367 367 . " " . escapeshellarg($new); . " " . escapeshellarg($new);
368 $a = rg_exec($cmd, '', FALSE);
368 $a = rg_exec($cmd, '', FALSE, FALSE);
369 369 rg_log("a:" . rg_array2string($a)); rg_log("a:" . rg_array2string($a));
370 370 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
371 371 rg_git_set_error("error on diff (" . $a['errmsg'] . ")"); rg_git_set_error("error on diff (" . $a['errmsg'] . ")");
 
... ... function rg_git_merge_base($repo_path, $a, $b)
446 446 . ' merge-base' . ' merge-base'
447 447 . ' ' . escapeshellarg($a) . ' ' . escapeshellarg($a)
448 448 . ' ' . escapeshellarg($b); . ' ' . escapeshellarg($b);
449 $a = rg_exec($cmd, '', FALSE);
449 $a = rg_exec($cmd, '', FALSE, FALSE);
450 450 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
451 451 rg_git_set_error('error on git merge_base (' rg_git_set_error('error on git merge_base ('
452 452 . $a['errmsg'] . ')'); . $a['errmsg'] . ')');
 
... ... function rg_git_update_ref($repo_path, $ref, $old, $new, $reason)
493 493 if (!empty($old)) if (!empty($old))
494 494 $cmd .= " " . escapeshellarg($old); $cmd .= " " . escapeshellarg($old);
495 495
496 $a = rg_exec($cmd, '', FALSE);
496 $a = rg_exec($cmd, '', FALSE, FALSE);
497 497 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
498 498 rg_git_set_error("error on update-ref (" . $a['errmsg'] . ")"); rg_git_set_error("error on update-ref (" . $a['errmsg'] . ")");
499 499 break; break;
 
... ... function rg_git_shortlog($repo_path, $a, $b)
522 522 . ' --git-dir=' . escapeshellarg($repo_path) . ' --git-dir=' . escapeshellarg($repo_path)
523 523 . ' ' . escapeshellarg($a) . ' ' . escapeshellarg($a)
524 524 . '..' . escapeshellarg($b); . '..' . escapeshellarg($b);
525 $r = rg_exec($cmd, '', FALSE);
525 $r = rg_exec($cmd, '', FALSE, FALSE);
526 526 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
527 527 rg_git_set_error('error on shortlog (' . $r['errmsg'] . ')'); rg_git_set_error('error on shortlog (' . $r['errmsg'] . ')');
528 528 break; break;
 
... ... function rg_git_ls_tree($repo_path, $tree, $path)
559 559 . escapeshellarg($tree); . escapeshellarg($tree);
560 560 if (!empty($path)) if (!empty($path))
561 561 $cmd .= ' ' . escapeshellarg($path); $cmd .= ' ' . escapeshellarg($path);
562 $a = rg_exec($cmd, '', FALSE);
562 $a = rg_exec($cmd, '', FALSE, FALSE);
563 563 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
564 564 rg_git_set_error("error on ls-tree (" . $a['errmsg'] . ")"); rg_git_set_error("error on ls-tree (" . $a['errmsg'] . ")");
565 565 break; break;
 
... ... function rg_git_log($path, $max, $from, $to, $also_patch)
868 868 . "%x00ROCKETGIT_END_OF_VARS%x00\""; . "%x00ROCKETGIT_END_OF_VARS%x00\"";
869 869 if (!empty($from_to)) if (!empty($from_to))
870 870 $cmd .= ' ' . escapeshellarg($from_to); $cmd .= ' ' . escapeshellarg($from_to);
871 $a = rg_exec($cmd, '', FALSE);
871 $a = rg_exec($cmd, '', FALSE, FALSE);
872 872 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
873 873 rg_internal_error("error on log (" . $a['errmsg'] . ")"); rg_internal_error("error on log (" . $a['errmsg'] . ")");
874 874 rg_git_set_error("could not generate log; try again later"); rg_git_set_error("could not generate log; try again later");
 
... ... function rg_git_files($old, $new)
1044 1044
1045 1045 $cmd = 'git diff --name-only ' . escapeshellarg($old) $cmd = 'git diff --name-only ' . escapeshellarg($old)
1046 1046 . ' ' . escapeshellarg($new); . ' ' . escapeshellarg($new);
1047 $a = rg_exec($cmd, '', FALSE);
1047 $a = rg_exec($cmd, '', FALSE, FALSE);
1048 1048 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
1049 1049 rg_git_set_error("error on git diff (" . $a['errmsg'] . ")"); rg_git_set_error("error on git diff (" . $a['errmsg'] . ")");
1050 1050 break; break;
 
... ... function rg_git_diff_tree($tree1, $tree2)
1645 1645 while (1) { while (1) {
1646 1646 $cmd = "git diff-tree -r " . escapeshellarg($tree1) $cmd = "git diff-tree -r " . escapeshellarg($tree1)
1647 1647 . " " . escapeshellarg($tree2); . " " . escapeshellarg($tree2);
1648 $a = rg_exec($cmd, '', FALSE);
1648 $a = rg_exec($cmd, '', FALSE, FALSE);
1649 1649 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
1650 1650 rg_git_set_error("error on diff-tree (" . $a['errmsg'] . ")"); rg_git_set_error("error on diff-tree (" . $a['errmsg'] . ")");
1651 1651 break; break;
 
... ... function rg_git_content_by_file($treeish, $file)
1689 1689 while (1) { while (1) {
1690 1690 $cmd = 'git show ' . escapeshellarg($treeish) . ':' $cmd = 'git show ' . escapeshellarg($treeish) . ':'
1691 1691 . escapeshellarg($file); . escapeshellarg($file);
1692 $a = rg_exec($cmd, '', FALSE);
1692 $a = rg_exec($cmd, '', FALSE, FALSE);
1693 1693 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
1694 1694 rg_git_set_error("error on show (" . $a['errmsg'] . ")"); rg_git_set_error("error on show (" . $a['errmsg'] . ")");
1695 1695 break; break;
 
... ... function rg_git_archive($repo_path, $treeish, $archive_name, $format)
1802 1802 . ' archive --format=' . escapeshellarg($format) . ' archive --format=' . escapeshellarg($format)
1803 1803 . ' --output=' . escapeshellarg($archive_name) . ' --output=' . escapeshellarg($archive_name)
1804 1804 . ' ' . escapeshellarg($treeish); . ' ' . escapeshellarg($treeish);
1805 $a = rg_exec($cmd, '', FALSE);
1805 $a = rg_exec($cmd, '', FALSE, FALSE);
1806 1806 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
1807 1807 rg_git_set_error('error on git archive' rg_git_set_error('error on git archive'
1808 1808 . ' (' . $a['errmsg'] . ')'); . ' (' . $a['errmsg'] . ')');
 
... ... function rg_git_merge_tree($repo_path, $base, $a, $b)
1871 1871 . ' ' . escapeshellarg($base) . ' ' . escapeshellarg($base)
1872 1872 . ' ' . escapeshellarg($a) . ' ' . escapeshellarg($a)
1873 1873 . ' ' . escapeshellarg($b); . ' ' . escapeshellarg($b);
1874 $a = rg_exec($cmd, '', FALSE);
1874 $a = rg_exec($cmd, '', FALSE, FALSE);
1875 1875 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
1876 1876 rg_git_set_error('error on git merge-tree (' rg_git_set_error('error on git merge-tree ('
1877 1877 . $a['errmsg'] . ')'); . $a['errmsg'] . ')');
 
... ... function rg_git_merge($repo_path, $a, $b, $ff, $msg)
1973 1973 . ' -m ' . escapeshellarg($msg) . ' -m ' . escapeshellarg($msg)
1974 1974 . ' ' . escapeshellarg($a) . ' ' . escapeshellarg($a)
1975 1975 . ' ' . escapeshellarg($b); . ' ' . escapeshellarg($b);
1976 $a = rg_exec($cmd, '', FALSE);
1976 $a = rg_exec($cmd, '', FALSE, FALSE);
1977 1977 rg_rmdir($work_tree); rg_rmdir($work_tree);
1978 1978 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
1979 1979 rg_git_set_error('error on git merge (' rg_git_set_error('error on git merge ('
 
... ... function rg_git_request_pull($repo_path, $start, $url, $end, $patch)
2022 2022 if ($patch) if ($patch)
2023 2023 $cmd .= ' --patch'; $cmd .= ' --patch';
2024 2024 $cmd .= escapeshellarg($start) . '..' . escapeshellarg($end); $cmd .= escapeshellarg($start) . '..' . escapeshellarg($end);
2025 $r = rg_exec($cmd, '', FALSE);
2025 $r = rg_exec($cmd, '', FALSE, FALSE);
2026 2026 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
2027 2027 rg_git_set_error('error on git diff: ' . $a['errmsg']); rg_git_set_error('error on git diff: ' . $a['errmsg']);
2028 2028 break; break;
File inc/totp.inc.php changed (mode: 100644) (index 16b1368..5842a17)
... ... function rg_totp_png($secret)
155 155 $extra = gmdate('Y-m-d H:i'); $extra = gmdate('Y-m-d H:i');
156 156 $issuer = $rg_ssh_host; $issuer = $rg_ssh_host;
157 157 $cmd = "qrencode -o - --level=H --type=PNG 'otpauth://totp/$extra?secret=$secret&issuer=$issuer'"; $cmd = "qrencode -o - --level=H --type=PNG 'otpauth://totp/$extra?secret=$secret&issuer=$issuer'";
158 $a = rg_exec($cmd, '', FALSE);
158 $a = rg_exec($cmd, '', FALSE, FALSE);
159 159 if ($a['ok'] != 1) if ($a['ok'] != 1)
160 160 return FALSE; return FALSE;
161 161
 
... ... function rg_totp_text($secret)
172 172 $extra = gmdate('Y-m-d H:i'); $extra = gmdate('Y-m-d H:i');
173 173 $issuer = $rg_ssh_host; $issuer = $rg_ssh_host;
174 174 $cmd = "qrencode -o - --level=M --margin=2 --type=UTF8 'otpauth://totp/$extra?secret=$secret&issuer=$issuer'"; $cmd = "qrencode -o - --level=M --margin=2 --type=UTF8 'otpauth://totp/$extra?secret=$secret&issuer=$issuer'";
175 $a = rg_exec($cmd, '', FALSE);
175 $a = rg_exec($cmd, '', FALSE, FALSE);
176 176 if ($a['ok'] != 1) if ($a['ok'] != 1)
177 177 return FALSE; return FALSE;
178 178
File inc/util.inc.php changed (mode: 100644) (index 22c7f3f..4689c32)
... ... function rg_ok($msg)
959 959 /* /*
960 960 * Execute $cmd and returns the output as a string, binary safe * Execute $cmd and returns the output as a string, binary safe
961 961 * @input: some data to be sent to the process and received as stdin * @input: some data to be sent to the process and received as stdin
962 * @stream_stdout - TRUE => will output to stdout, FALSE => store in ret
962 * @cb_stdout - call back called when there is something to be send to stdout
963 * if @cb_stdout is FALSE, stdout output will be returned in $ret
964 * cb_stderr - call back called when there is something to be send to stderr
965 * if @cb_stderr is FALSE, stderr output will be returned in $ret
963 966 */ */
964 function rg_exec($cmd, $input, $stream_stdout)
967 function rg_exec($cmd, $input, $cb_stdout, $cb_stderr)
965 968 { {
966 969 rg_prof_start("exec"); rg_prof_start("exec");
967 970 rg_log_enter("Executing [$cmd]..."); rg_log_enter("Executing [$cmd]...");
 
... ... function rg_exec($cmd, $input, $stream_stdout)
1045 1048 continue; continue;
1046 1049 } }
1047 1050
1048 //rg_log('DEBUG: got data from fd ' . $fd
1049 // . ': ' . bin2hex($_d));
1051 rg_log('DEBUG: got data from fd ' . $fd
1052 . ': ' . $_d);
1050 1053 if ($fd === $pipes[2]) { if ($fd === $pipes[2]) {
1051 $stderr .= $_d;
1054 if ($cb_stderr === FALSE) {
1055 rg_log('DEBUG: fd is pipes[2], append to stderr var');
1056 $stderr .= $_d;
1057 } else {
1058 rg_log('DEBUG: fd is pipes[2], call stdout cb');
1059 cb_stderr($_d);
1060 }
1052 1061 } else if ($fd === $pipes[1]) { } else if ($fd === $pipes[1]) {
1053 if ($stream_stdout)
1054 echo $_d;
1055 else
1062 if ($cb_stdout === FALSE) {
1063 rg_log('Stream data to stdout using echo.');
1056 1064 $ret['data'] .= $_d; $ret['data'] .= $_d;
1065 } else {
1066 rg_log('DEBUG: fd is pipes[1], call stdout cb');
1067 cb_stdout($_d);
1068 }
1057 1069 } }
1058 1070 } }
1059 1071
File scripts/worker.php changed (mode: 100644) (index 6fe3575..022ccf6)
... ... function reload_config()
95 95 $cmd = 'ssh-keygen -t rsa -b 4096 -N \'\'' $cmd = 'ssh-keygen -t rsa -b 4096 -N \'\''
96 96 . ' -C \'Key to connect to builder\'' . ' -C \'Key to connect to builder\''
97 97 . ' -f ' . escapeshellarg($conf['state'] . '/key'); . ' -f ' . escapeshellarg($conf['state'] . '/key');
98 $r = rg_exec($cmd, '', FALSE);
98 $r = rg_exec($cmd, '', FALSE, FALSE);
99 99 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
100 rg_log('Cannot create key: ' . $r['data'] . '!');
100 rg_log('Cannot create key: ' . $r['errmsg'] . '!');
101 101 sleep(60); sleep(60);
102 102 exit(0); exit(0);
103 103 } }
 
... ... function start_worker($job)
135 135 $do_umount = FALSE; $do_umount = FALSE;
136 136 $err = TRUE; $err = TRUE;
137 137 while (1) { while (1) {
138 rg_exec('virsh destroy ' . $ename, '', FALSE);
139 rg_exec('virsh undefine ' . $ename, '', FALSE);
138 rg_exec('virsh destroy ' . $ename, '', FALSE, FALSE);
139 rg_exec('virsh undefine ' . $ename, '', FALSE, FALSE);
140 140
141 141 $r = rg_del_tree($job['main']); $r = rg_del_tree($job['main']);
142 142 if ($r === FALSE) { if ($r === FALSE) {
 
... ... function start_worker($job)
161 161 } }
162 162
163 163 $r = rg_exec('qemu-img create -b ' . $master $r = rg_exec('qemu-img create -b ' . $master
164 . ' -f qcow2 ' . $img, '', FALSE);
164 . ' -f qcow2 ' . $img, '', FALSE, FALSE);
165 165 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
166 166 $reason = 'cannot create image: ' . $r['errmsg']; $reason = 'cannot create image: ' . $r['errmsg'];
167 167 break; break;
168 168 } }
169 169
170 $r = rg_exec('qemu-img create -f raw ' . $img2 . ' 1G', '', FALSE);
170 $r = rg_exec('qemu-img create -f raw ' . $img2 . ' 1G', '',
171 FALSE, FALSE);
171 172 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
172 173 $reason = 'cannot create image2: ' . $r['errmsg']; $reason = 'cannot create image2: ' . $r['errmsg'];
173 174 break; break;
 
... ... function start_worker($job)
177 178 $path = getenv('PATH'); $path = getenv('PATH');
178 179 putenv('PATH=' . $path . ':/usr/sbin'); putenv('PATH=' . $path . ':/usr/sbin');
179 180
180 $r = rg_exec('mkfs.ext4 -L RG ' . $img2, '', FALSE);
181 $r = rg_exec('mkfs.ext4 -L RG ' . $img2, '', FALSE, FALSE);
181 182 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
182 183 $reason = 'cannot create fs: ' . $r['errmsg']; $reason = 'cannot create fs: ' . $r['errmsg'];
183 184 break; break;
184 185 } }
185 186
186 $r = @mkdir($job['main'] . '/root', 0755);
187 $r = @mkdir($job['main'] . '/root', 0700);
187 188 if ($r === FALSE) { if ($r === FALSE) {
188 189 $reason = 'Cannot create root dir: ' . $php_errormsg . '!'; $reason = 'Cannot create root dir: ' . $php_errormsg . '!';
189 190 break; break;
190 191 } }
191 192
192 $r = rg_exec('mount ' . $img2 . ' ' . $emain . '/root', '', FALSE);
193 $r = rg_exec('mount ' . $img2 . ' ' . $emain . '/root', '',
194 FALSE, FALSE);
193 195 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
194 196 $reason = 'cannot mount fs: ' . $r['errmsg']; $reason = 'cannot mount fs: ' . $r['errmsg'];
195 197 break; break;
 
... ... function start_worker($job)
204 206 $cmd = 'git clone --depth 1' $cmd = 'git clone --depth 1'
205 207 . ' ' . escapeshellarg($job['url']) . ' ' . escapeshellarg($job['url'])
206 208 . ' ' . $emain . '/root/git'; . ' ' . $emain . '/root/git';
207 $r = rg_exec($cmd, '', FALSE);
209 $r = rg_exec($cmd, '', FALSE, FALSE);
208 210 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
209 211 $reason = 'cannot clone: ' . $r['errmsg']; $reason = 'cannot clone: ' . $r['errmsg'];
210 212 break; break;
 
... ... function start_worker($job)
300 302 break; break;
301 303 } }
302 304
303 $r = rg_exec('umount ' . $emain . '/root', '', FALSE);
305 $r = rg_exec('umount ' . $emain . '/root', '', FALSE, FALSE);
304 306 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
305 307 $reason = 'cannot umount fs: ' . $r['errmsg']; $reason = 'cannot umount fs: ' . $r['errmsg'];
306 308 break; break;
 
... ... function start_worker($job)
328 330 . ' --rng /dev/random' . ' --rng /dev/random'
329 331 . ' --memballoon virtio' . ' --memballoon virtio'
330 332 . ' --console pty,target_type=virtio' . ' --console pty,target_type=virtio'
331 . ' ' . $env['paras'], '', FALSE);
333 . ' ' . $env['paras'], '', FALSE, FALSE);
332 334 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
333 $reason = 'cannot define and start virtual machine: ' . $r['errmsg'];
335 $reason = 'cannot define and start virtual machine: '
336 . $r['errmsg'];
334 337 break; break;
335 338 } }
336 339
 
... ... function start_worker($job)
338 341 break; break;
339 342 } }
340 343 if ($do_umount) if ($do_umount)
341 rg_exec('umount ' . $emain . '/root', '', FALSE);
344 rg_exec('umount ' . $emain . '/root', '', FALSE, FALSE);
342 345
343 346 // Seems that any error above must retrigger the build on other worker // Seems that any error above must retrigger the build on other worker
344 347 if ($err) if ($err)
 
... ... function rg_job_extract_info(&$job)
447 450 } }
448 451
449 452 $cmd = 'mount ' . $emain . '/image2.raw ' . $emain . '/root'; $cmd = 'mount ' . $emain . '/image2.raw ' . $emain . '/root';
450 $r = rg_exec($cmd, '', FALSE);
453 $r = rg_exec($cmd, '', FALSE, FALSE);
451 454 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
452 $job['error'] = 'Could not mount image: ' . $r['data'];
455 $job['error'] = 'Could not mount image: ' . $r['errmsg'];
453 456 break; break;
454 457 } }
455 458
 
... ... function rg_job_extract_info(&$job)
489 492 unset($job['env']); unset($job['env']);
490 493
491 494 $cmd = 'umount ' . $emain . '/root'; $cmd = 'umount ' . $emain . '/root';
492 $r = rg_exec($cmd, '', FALSE);
495 $r = rg_exec($cmd, '', FALSE, FALSE);
493 496 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
494 rg_log('Cannot unmount!');
497 rg_log('Cannot unmount: ' . $r['errmsg'] . '!');
495 498 break; break;
496 499 } }
497 500
 
... ... while(1) {
600 603
601 604 // TODO: do we destroy the pool in case of crash? // TODO: do we destroy the pool in case of crash?
602 605 $cmd = 'virsh pool-destroy rocketgit-j-' . $jid; $cmd = 'virsh pool-destroy rocketgit-j-' . $jid;
603 $r = rg_exec($cmd, '', FALSE);
606 $r = rg_exec($cmd, '', FALSE, FALSE);
604 607 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
605 $job['error'] = 'Could not destroy pool: ' . $r['data'];
608 $job['error'] = 'Could not destroy pool: ' . $r['errmsg'];
606 609 rg_log('Error: ' . $job['error']); rg_log('Error: ' . $job['error']);
607 610 //break; TODO: do we need to do this?! //break; TODO: do we need to do this?!
608 611 } }
609 612
610 613 // TODO: do we clean the pool in case of crash? // TODO: do we clean the pool in case of crash?
611 614 $cmd = 'virsh pool-undefine rocketgit-j-' . $jid; $cmd = 'virsh pool-undefine rocketgit-j-' . $jid;
612 $r = rg_exec($cmd, '', FALSE);
615 $r = rg_exec($cmd, '', FALSE, FALSE);
613 616 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
614 $job['error'] = 'Could not undefine pool: ' . $r['data'];
617 $job['error'] = 'Could not undefine pool: ' . $r['errmsg'];
615 618 rg_log('Error: ' . $job['error']); rg_log('Error: ' . $job['error']);
616 619 //break; TODO: do we need to do this?! //break; TODO: do we need to do this?!
617 620 } }
618 621
619 622 // TODO: do we clean the machine in case of crash? // TODO: do we clean the machine in case of crash?
620 623 $cmd = 'virsh undefine rg-worker-' . escapeshellarg($jid); $cmd = 'virsh undefine rg-worker-' . escapeshellarg($jid);
621 $r = rg_exec($cmd, '', FALSE);
624 $r = rg_exec($cmd, '', FALSE, FALSE);
622 625 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
623 $job['error'] = 'Could not undefine machine: ' . $r['data'];
626 $job['error'] = 'Could not undefine machine: ' . $r['errmsg'];
624 627 rg_log('Error: ' . $job['error']); rg_log('Error: ' . $job['error']);
625 628 //break; TODO //break; TODO
626 629 } }
File tests/export.php changed (mode: 100644) (index 02263f3..949cb41)
... ... if ($r === FALSE) {
45 45 } }
46 46
47 47 $cmd = 'cat export.json | json_verify'; $cmd = 'cat export.json | json_verify';
48 $a = rg_exec($cmd, '', FALSE);
48 $a = rg_exec($cmd, '', FALSE, FALSE);
49 49 if ($a['ok'] !== 1) { if ($a['ok'] !== 1) {
50 50 rg_log_ml(print_r($a, TRUE)); rg_log_ml(print_r($a, TRUE));
51 51 rg_log('Seems the JSON is not valid!'); rg_log('Seems the JSON is not valid!');
File tests/git2.php changed (mode: 100644) (index 1e41756..48abade)
... ... $remote = 'ssh://rocketgit@' . $rg_ssh_host . ':' .$rg_ssh_port
66 66 . '/' . escapeshellarg($repo['name']); . '/' . escapeshellarg($repo['name']);
67 67 $r = rg_exec("cd git2 && git remote add origin $remote" $r = rg_exec("cd git2 && git remote add origin $remote"
68 68 . " && export GIT_SSH_COMMAND=\"ssh -v -o IdentityFile=../keys/git2\"" . " && export GIT_SSH_COMMAND=\"ssh -v -o IdentityFile=../keys/git2\""
69 . " && git push origin master", '', FALSE);
69 . " && git push origin master", '', FALSE, FALSE);
70 70 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
71 71 rg_log_ml('out: ' . $r['errmsg']); rg_log_ml('out: ' . $r['errmsg']);
72 72 rg_log("Seems I cannot push master! err=$err"); rg_log("Seems I cannot push master! err=$err");
 
... ... rg_log('');
79 79 rg_log_enter('Trying to push tags...'); rg_log_enter('Trying to push tags...');
80 80 $r = rg_exec("cd git2" $r = rg_exec("cd git2"
81 81 . " && export GIT_SSH_COMMAND=\"ssh -v -o IdentityFile=../keys/git2\"" . " && export GIT_SSH_COMMAND=\"ssh -v -o IdentityFile=../keys/git2\""
82 . " && git push --tags origin", '', FALSE);
82 . " && git push --tags origin", '', FALSE, FALSE);
83 83 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
84 84 rg_log_ml('error: ' . $r['errmsg']); rg_log_ml('error: ' . $r['errmsg']);
85 85 rg_log("Seems I cannot push tags!"); rg_log("Seems I cannot push tags!");
File tests/pr_anon.php changed (mode: 100644) (index 65379b5..382192f)
... ... rg_log_exit();
82 82 rg_log(''); rg_log('');
83 83 rg_log_enter('Preparing repo...'); rg_log_enter('Preparing repo...');
84 84 system('rm -rf _pr_anon.git 2>/dev/null'); system('rm -rf _pr_anon.git 2>/dev/null');
85 $r = rg_exec('git init _pr_anon.git', '', FALSE);
85 $r = rg_exec('git init _pr_anon.git', '', FALSE, FALSE);
86 86 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
87 87 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
88 88 rg_log('Could not init repo!'); rg_log('Could not init repo!');
 
... ... if ($r['ok'] != 1) {
91 91 $r = rg_exec('cd _pr_anon.git; git remote add origin_ssh ' $r = rg_exec('cd _pr_anon.git; git remote add origin_ssh '
92 92 . ' ssh://rocketgit@' . $rg_ssh_host . ':' . $rg_ssh_port . ' ssh://rocketgit@' . $rg_ssh_host . ':' . $rg_ssh_port
93 93 . '/user/' . escapeshellarg($rg_ui['username']) . '/' . '/user/' . escapeshellarg($rg_ui['username']) . '/'
94 . escapeshellarg($repo['name']), '', FALSE);
94 . escapeshellarg($repo['name']), '', FALSE, FALSE);
95 95 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
96 96 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
97 97 rg_log('Could not add ssh remote!'); rg_log('Could not add ssh remote!');
 
... ... if ($r['ok'] != 1) {
100 100 $r = rg_exec('cd _pr_anon.git; git remote add origin_git ' $r = rg_exec('cd _pr_anon.git; git remote add origin_git '
101 101 . ' git://' . $rg_git_host . ':' . $rg_git_port . ' git://' . $rg_git_host . ':' . $rg_git_port
102 102 . '/user/' . escapeshellarg($rg_ui['username']) . '/' . '/user/' . escapeshellarg($rg_ui['username']) . '/'
103 . escapeshellarg($repo['name']), '', FALSE);
103 . escapeshellarg($repo['name']), '', FALSE, FALSE);
104 104 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
105 105 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
106 106 rg_log('Could not add git remote!'); rg_log('Could not add git remote!');
 
... ... $r = rg_exec('export GIT_SSH_COMMAND="ssh -o IdentityFile=../keys/pr_anon";'
115 115 . 'cd _pr_anon.git; echo "change1" > a;' . 'cd _pr_anon.git; echo "change1" > a;'
116 116 . 'git add a; git commit -m "change1 desc";' . 'git add a; git commit -m "change1 desc";'
117 117 . 'echo "change2" > a; git commit -a -m "change2 desc";' . 'echo "change2" > a; git commit -a -m "change2 desc";'
118 . 'git push origin_ssh master', '', FALSE);
118 . 'git push origin_ssh master', '', FALSE, FALSE);
119 119 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
120 120 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
121 121 rg_log('Non-anonymous push was rejected!'); rg_log('Non-anonymous push was rejected!');
 
... ... rg_log_enter('Do an anonymous push...');
129 129 $r = rg_exec('cd _pr_anon.git; echo "change3" >> a;' $r = rg_exec('cd _pr_anon.git; echo "change3" >> a;'
130 130 . 'git add a; git commit -m "anon change1 desc";' . 'git add a; git commit -m "anon change1 desc";'
131 131 . 'echo "change4" >> a; git commit -a -m "anon change2 desc";' . 'echo "change4" >> a; git commit -a -m "anon change2 desc";'
132 . 'git push origin_git master', '', FALSE);
132 . 'git push origin_git master', '', FALSE, FALSE);
133 133 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
134 134 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
135 135 rg_log('Anonymous push was rejected!'); rg_log('Anonymous push was rejected!');
 
... ... $r = rg_exec('cd _pr_anon.git;'
212 212 . 'git pull origin_git master;' . 'git pull origin_git master;'
213 213 . 'echo "change2" > a;' . 'echo "change2" > a;'
214 214 . 'git commit -a -m "conflict1b";' . 'git commit -a -m "conflict1b";'
215 . 'git push origin_git master', '', FALSE);
215 . 'git push origin_git master', '', FALSE, FALSE);
216 216 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
217 217 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
218 218 rg_log('Could not pull/commit/push by git proto!'); rg_log('Could not pull/commit/push by git proto!');
 
... ... $r = rg_exec('export GIT_SSH_COMMAND="ssh -o IdentityFile=../keys/pr_anon";'
223 223 . 'git reset --hard HEAD^1;' . 'git reset --hard HEAD^1;'
224 224 . ' echo "change1" > a;' . ' echo "change1" > a;'
225 225 . 'git commit -a -m "conflict1a";' . 'git commit -a -m "conflict1a";'
226 . 'git push origin_ssh master', '', FALSE);
226 . 'git push origin_ssh master', '', FALSE, FALSE);
227 227 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
228 228 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
229 229 rg_log('Could not reset/commit/push by ssh proto!'); rg_log('Could not reset/commit/push by ssh proto!');
File tests/repo.php changed (mode: 100644) (index 52a3cec..0b6bba9)
... ... if ($ri['exists'] != 1) {
192 192
193 193 rg_log(''); rg_log('');
194 194 rg_log_enter('Cleaning repos folder...'); rg_log_enter('Cleaning repos folder...');
195 $r = rg_exec("rm -rf base/*", '', FALSE);
195 $r = rg_exec("rm -rf base/*", '', FALSE, FALSE);
196 196 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
197 197 rg_log("Failed to clean base folder."); rg_log("Failed to clean base folder.");
198 198 exit(1); exit(1);
File tests/user.php changed (mode: 100644) (index d5e6d5d..483b905)
... ... $rg_admin_name = "RocketGit Admin";
27 27 $_SERVER['HTTP_HOST'] = "fake.tld"; $_SERVER['HTTP_HOST'] = "fake.tld";
28 28
29 29
30 $r = rg_exec("rm -rf ubase", '', FALSE);
30 $r = rg_exec("rm -rf ubase", '', FALSE, FALSE);
31 31 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
32 32 rg_log("Cannot remove ubase dir (" . $r['errmsg'] . ")!"); rg_log("Cannot remove ubase dir (" . $r['errmsg'] . ")!");
33 33 exit(1); exit(1);
File tests/util.php changed (mode: 100644) (index 9cf02c7..01a688f)
... ... if ($r !== TRUE) {
264 264 } }
265 265
266 266
267 $r = rg_exec("/xxxx", '', FALSE);
267 $r = rg_exec("/xxxx", '', FALSE, FALSE);
268 268 if ($r['ok'] == 1) { if ($r['ok'] == 1) {
269 269 rg_log("util.php: running non existing command does not return 0!"); rg_log("util.php: running non existing command does not return 0!");
270 270 print_r($r); print_r($r);
271 271 exit(1); exit(1);
272 272 } }
273 273
274 $r = rg_exec("ls", '', FALSE);
274 $r = rg_exec("ls", '', FALSE, FALSE);
275 275 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
276 276 rg_log("util.php: cannot run a command!"); rg_log("util.php: cannot run a command!");
277 277 print_r($r); print_r($r);
278 278 exit(1); exit(1);
279 279 } }
280 280
281 $r = rg_exec("./util_exit_code.sh 5", '', FALSE);
281 $r = rg_exec("./util_exit_code.sh 5", '', FALSE, FALSE);
282 282 if ($r['code'] != 5) { if ($r['code'] != 5) {
283 283 rg_log("util.php: error code seems to not be propageted!"); rg_log("util.php: error code seems to not be propageted!");
284 284 print_r($r); print_r($r);
File tests/wh_cloud.php changed (mode: 100644) (index 7e172ea..1fa813a)
... ... rg_test_create_repo($db, $rg_ui, $repo);
103 103 $repo_url = 'ssh://rocketgit@' . $rg_ssh_host . ':' . $rg_ssh_port $repo_url = 'ssh://rocketgit@' . $rg_ssh_host . ':' . $rg_ssh_port
104 104 . '/user/' . $rg_ui['username'] . '/' . $repo['name']; . '/user/' . $rg_ui['username'] . '/' . $repo['name'];
105 105 rg_log('repo_url=' . escapeshellarg($repo_url)); rg_log('repo_url=' . escapeshellarg($repo_url));
106 $r = rg_exec('./wh_cloud.git.sh ' . escapeshellarg($repo_url), '', FALSE);
106 $r = rg_exec('./wh_cloud.git.sh ' . escapeshellarg($repo_url), '', FALSE, FALSE);
107 107 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
108 108 rg_log('Could not create local git repo: ' . $r['errmsg'] . '!'); rg_log('Could not create local git repo: ' . $r['errmsg'] . '!');
109 109 exit(1); exit(1);
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