File inc/git.inc.php changed (mode: 100644) (index 8873a3e..dfd89e6) |
... |
... |
function rg_git_type($obj) |
137 |
137 |
} |
} |
138 |
138 |
|
|
139 |
139 |
/* |
/* |
140 |
|
* Outputs the content of an object |
|
|
140 |
|
* Outputs the content (array) of an object |
141 |
141 |
*/ |
*/ |
142 |
142 |
function rg_git_content($obj) |
function rg_git_content($obj) |
143 |
143 |
{ |
{ |
|
... |
... |
function rg_git_content($obj) |
149 |
149 |
return FALSE; |
return FALSE; |
150 |
150 |
} |
} |
151 |
151 |
|
|
152 |
|
return trim($a); |
|
|
152 |
|
return $output; |
153 |
153 |
} |
} |
154 |
154 |
|
|
155 |
155 |
/* |
/* |
|
... |
... |
function rg_git_ls_tree($tree) |
255 |
255 |
return $ret; |
return $ret; |
256 |
256 |
} |
} |
257 |
257 |
|
|
|
258 |
|
/* |
|
259 |
|
* Transforms a diff into an array (ready for rg_git_diff) |
|
260 |
|
*/ |
|
261 |
|
function rg_git_diff2array($diff) |
|
262 |
|
{ |
|
263 |
|
$ret = array(); |
|
264 |
|
|
|
265 |
|
$lines = explode("\n", $diff); |
|
266 |
|
$file = 0; |
|
267 |
|
foreach ($lines as $line) { |
|
268 |
|
if (empty($line)) |
|
269 |
|
continue; |
|
270 |
|
|
|
271 |
|
if (strncmp($line, "diff ", 5) == 0) { |
|
272 |
|
$file++; |
|
273 |
|
$ret[$file] = array(); |
|
274 |
|
$ret[$file]['flags'] = ""; |
|
275 |
|
$ret[$file]['chunks'] = array(); |
|
276 |
|
$file_name_sel = "dst"; |
|
277 |
|
$file_name_tmp = array(); |
|
278 |
|
continue; |
|
279 |
|
} |
|
280 |
|
|
|
281 |
|
if (strncmp($line, "new file ", 9) == 0) { |
|
282 |
|
$ret[$file]['flags'] .= "N"; |
|
283 |
|
continue; |
|
284 |
|
} |
|
285 |
|
|
|
286 |
|
if (strncmp($line, "deleted file ", 13) == 0) { |
|
287 |
|
$ret[$file]['flags'] .= "D"; |
|
288 |
|
$file_name_sel = "src"; |
|
289 |
|
continue; |
|
290 |
|
} |
|
291 |
|
|
|
292 |
|
if (strncmp($line, "index ", 6) == 0) { |
|
293 |
|
$ret[$file]['index'] = substr($line, 6); |
|
294 |
|
continue; |
|
295 |
|
} |
|
296 |
|
|
|
297 |
|
if (strncmp($line, "--- ", 4) == 0) { |
|
298 |
|
if (strncmp($line, "--- a/", 2) == 0) |
|
299 |
|
$file_name_tmp['src'] = substr($line, 6); |
|
300 |
|
else |
|
301 |
|
$file_name_tmp['src'] = substr($line, 4); |
|
302 |
|
continue; |
|
303 |
|
} |
|
304 |
|
|
|
305 |
|
if (strncmp($line, "+++ ", 4) == 0) { |
|
306 |
|
if (strncmp($line, "+++ b/", 2) == 0) |
|
307 |
|
$file_name_tmp['dst'] = substr($line, 6); |
|
308 |
|
else |
|
309 |
|
$file_name_tmp['dst'] = substr($line, 4); |
|
310 |
|
continue; |
|
311 |
|
} |
|
312 |
|
|
|
313 |
|
// parse line "@@ -14,6 +14,8 @@ function..." |
|
314 |
|
// @@ from_file_range to_file_range @@ ... |
|
315 |
|
if (strncmp($line, "@@ ", 3) == 0) { |
|
316 |
|
$_t = explode(" ", $line, 5); |
|
317 |
|
$chunk = $_t[1] . " " . $_t[2]; |
|
318 |
|
$ret[$file]['chunks'][$chunk] = array(); |
|
319 |
|
$ret[$file]['chunks'][$chunk]['section'] = @trim($_t[4]); |
|
320 |
|
$from = explode(",", substr($_t[1], 1)); |
|
321 |
|
$ret[$file]['chunks'][$chunk]['from'] = intval($from[0]); |
|
322 |
|
$to = explode(",", substr($_t[2], 1)); |
|
323 |
|
$ret[$file]['chunks'][$chunk]['to'] = intval($to[0]); |
|
324 |
|
continue; |
|
325 |
|
} |
|
326 |
|
|
|
327 |
|
if (!isset($file_name_tmp[$file_name_sel])) { |
|
328 |
|
echo "bad!"; |
|
329 |
|
echo $diff; |
|
330 |
|
exit(0); |
|
331 |
|
} |
|
332 |
|
|
|
333 |
|
if (!isset($ret[$file]['file'])) |
|
334 |
|
$ret[$file]['file'] = $file_name_tmp[$file_name_sel]; |
|
335 |
|
|
|
336 |
|
if ((strncmp($line, " ", 1) == 0) |
|
337 |
|
|| (strncmp($line, "+", 1) == 0) |
|
338 |
|
|| (strncmp($line, "-", 1) == 0)) { |
|
339 |
|
$ret[$file]['chunks'][$chunk]['lines'][] = $line; |
|
340 |
|
continue; |
|
341 |
|
} |
|
342 |
|
|
|
343 |
|
echo "I do not know how to parse [" . trim($line) . "]!\n"; |
|
344 |
|
exit(0); |
|
345 |
|
} |
|
346 |
|
|
|
347 |
|
return $ret; |
|
348 |
|
} |
|
349 |
|
|
258 |
350 |
/* |
/* |
259 |
351 |
* Show last @max commits, no merges, sort by topo |
* Show last @max commits, no merges, sort by topo |
260 |
352 |
* @also_patch = TRUE if caller needs also the patch |
* @also_patch = TRUE if caller needs also the patch |
261 |
353 |
*/ |
*/ |
262 |
|
function rg_git_log($max, $also_patch) |
|
|
354 |
|
function rg_git_log($max, $from, $to, $also_patch) |
263 |
355 |
{ |
{ |
264 |
356 |
rg_log("git_log: max=$max"); |
rg_log("git_log: max=$max"); |
265 |
357 |
|
|
266 |
358 |
$max_count = ($max == 0) ? "" : " --max-count=$max"; |
$max_count = ($max == 0) ? "" : " --max-count=$max"; |
267 |
359 |
$patches = $also_patch ? " --patch" : ""; |
$patches = $also_patch ? " --patch" : ""; |
268 |
360 |
|
|
|
361 |
|
if (empty($from) && empty($to)) |
|
362 |
|
$from_to = ""; |
|
363 |
|
else |
|
364 |
|
$from_to = " " . $from . ".." . $to; |
|
365 |
|
|
269 |
366 |
$cmd = "git log" |
$cmd = "git log" |
270 |
367 |
. " --no-merges" |
. " --no-merges" |
271 |
368 |
. " -z" |
. " -z" |
|
... |
... |
function rg_git_log($max, $also_patch) |
289 |
386 |
. "body:%b%x00\"\"" |
. "body:%b%x00\"\"" |
290 |
387 |
. "notes:%N%x00\"\"" |
. "notes:%N%x00\"\"" |
291 |
388 |
. "%x00ROCKETGIT_END_OF_VARS%x00\"" |
. "%x00ROCKETGIT_END_OF_VARS%x00\"" |
292 |
|
. " --numstat"; |
|
|
389 |
|
. " --numstat" |
|
390 |
|
. $from_to; |
293 |
391 |
rg_log("\texec $cmd..."); |
rg_log("\texec $cmd..."); |
294 |
392 |
$a = @exec($cmd, $output, $err); |
$a = @exec($cmd, $output, $err); |
295 |
393 |
if ($err != 0) { |
if ($err != 0) { |
|
... |
... |
function rg_git_log($max, $also_patch) |
297 |
395 |
return FALSE; |
return FALSE; |
298 |
396 |
} |
} |
299 |
397 |
|
|
300 |
|
$a = implode("", $output); |
|
|
398 |
|
$a = implode("\n", $output); |
301 |
399 |
|
|
302 |
400 |
$blocks = explode("\0-=ROCKETGIT=-\0", $a); |
$blocks = explode("\0-=ROCKETGIT=-\0", $a); |
303 |
401 |
// ignore first entry because of separator |
// ignore first entry because of separator |
|
... |
... |
function rg_git_log($max, $also_patch) |
309 |
407 |
|
|
310 |
408 |
// split block in two: vars and stats + patches |
// split block in two: vars and stats + patches |
311 |
409 |
$parts = explode("\0ROCKETGIT_END_OF_VARS\0", $block, 2); |
$parts = explode("\0ROCKETGIT_END_OF_VARS\0", $block, 2); |
|
410 |
|
//rg_log("DEBUG: parts:" . print_r($parts, TRUE)); |
312 |
411 |
|
|
313 |
412 |
// vars |
// vars |
314 |
|
$x = explode ("\0", $parts[0]); |
|
|
413 |
|
$x = explode ("\0", trim($parts[0])); |
315 |
414 |
$count = count($x); |
$count = count($x); |
316 |
415 |
for ($i = 0; $i < $count - 1; $i++) { |
for ($i = 0; $i < $count - 1; $i++) { |
317 |
416 |
$_t = explode(":", $x[$i], 2); |
$_t = explode(":", $x[$i], 2); |
|
... |
... |
function rg_git_log($max, $also_patch) |
323 |
422 |
|
|
324 |
423 |
// stats & patches |
// stats & patches |
325 |
424 |
$stats_and_patches = trim($parts[1]); |
$stats_and_patches = trim($parts[1]); |
|
425 |
|
rg_log("DEBUG: stats_and_patches:" . print_r($stats_and_patches, TRUE)); |
326 |
426 |
$_sp = explode("\0\0", $stats_and_patches, 2); |
$_sp = explode("\0\0", $stats_and_patches, 2); |
327 |
427 |
$stats = $_sp[0]; |
$stats = $_sp[0]; |
328 |
428 |
if (isset($_sp[1])) |
if (isset($_sp[1])) |
329 |
|
$y['patches'] = rg_git_diff2array(trim($_sp[1])); |
|
|
429 |
|
$y['patches'] = rg_git_diff2array($_sp[1]); |
330 |
430 |
|
|
331 |
431 |
// stats |
// stats |
332 |
432 |
$_t = explode("\0", $stats); |
$_t = explode("\0", $stats); |
|
... |
... |
function rg_git_log($max, $also_patch) |
354 |
454 |
return $ret; |
return $ret; |
355 |
455 |
} |
} |
356 |
456 |
|
|
357 |
|
/* |
|
358 |
|
* Transforms a diff into an array (ready for rg_git_diff_template) |
|
359 |
|
*/ |
|
360 |
|
function rg_git_diff2array($diff) |
|
361 |
|
{ |
|
362 |
|
$ret = array(); |
|
363 |
|
|
|
364 |
|
$lines = explode("\n", $diff); |
|
365 |
|
$file = 0; |
|
366 |
|
foreach ($lines as $line) { |
|
367 |
|
if (strncmp($line, "diff ", 5) == 0) { |
|
368 |
|
$file++; |
|
369 |
|
$ret[$file] = array(); |
|
370 |
|
$ret[$file]['flags'] = ""; |
|
371 |
|
$ret[$file]['chunks'] = array(); |
|
372 |
|
$file_name_sel = "dst"; |
|
373 |
|
$file_name_tmp = array(); |
|
374 |
|
continue; |
|
375 |
|
} |
|
376 |
|
|
|
377 |
|
if (strncmp($line, "new file ", 9) == 0) { |
|
378 |
|
$ret[$file]['flags'] .= "N"; |
|
379 |
|
continue; |
|
380 |
|
} |
|
381 |
|
|
|
382 |
|
if (strncmp($line, "deleted file ", 13) == 0) { |
|
383 |
|
$ret[$file]['flags'] .= "D"; |
|
384 |
|
$file_name_sel = "src"; |
|
385 |
|
continue; |
|
386 |
|
} |
|
387 |
|
|
|
388 |
|
if (strncmp($line, "index ", 6) == 0) { |
|
389 |
|
$ret[$file]['index'] = substr($line, 6); |
|
390 |
|
continue; |
|
391 |
|
} |
|
392 |
|
|
|
393 |
|
if (strncmp($line, "--- ", 4) == 0) { |
|
394 |
|
if (strncmp($line, "--- a/", 2) == 0) |
|
395 |
|
$file_name_tmp['src'] = substr($line, 6); |
|
396 |
|
else |
|
397 |
|
$file_name_tmp['src'] = substr($line, 4); |
|
398 |
|
continue; |
|
399 |
|
} |
|
400 |
|
|
|
401 |
|
if (strncmp($line, "+++ ", 4) == 0) { |
|
402 |
|
if (strncmp($line, "+++ b/", 2) == 0) |
|
403 |
|
$file_name_tmp['dst'] = substr($line, 6); |
|
404 |
|
else |
|
405 |
|
$file_name_tmp['dst'] = substr($line, 4); |
|
406 |
|
continue; |
|
407 |
|
} |
|
408 |
|
|
|
409 |
|
if (strncmp($line, "@@ ", 3) == 0) { |
|
410 |
|
$_t = explode(" ", $line, 5); |
|
411 |
|
$chunk = $_t[1] . " " . $_t[2]; |
|
412 |
|
$ret[$file]['chunks'][$chunk] = array(); |
|
413 |
|
$ret[$file]['chunks'][$chunk]['section'] = @trim($_t[4]); |
|
414 |
|
$lineno = substr($line, 3); |
|
415 |
|
$lineno = 0; // TODO: fixit! |
|
416 |
|
continue; |
|
417 |
|
} |
|
418 |
|
|
|
419 |
|
if (!isset($file_name_tmp[$file_name_sel])) { |
|
420 |
|
echo "bad!"; |
|
421 |
|
echo $diff; |
|
422 |
|
exit(0); |
|
423 |
|
} |
|
424 |
|
|
|
425 |
|
if (!isset($ret[$file]['file'])) |
|
426 |
|
$ret[$file]['file'] = $file_name_tmp[$file_name_sel]; |
|
427 |
|
|
|
428 |
|
if ((strncmp($line, " ", 1) == 0) |
|
429 |
|
|| (strncmp($line, "+", 1) == 0) |
|
430 |
|
|| (strncmp($line, "-", 1) == 0)) { |
|
431 |
|
$ret[$file]['chunks'][$chunk]['lines'][$lineno++] = $line; |
|
432 |
|
continue; |
|
433 |
|
} |
|
434 |
|
|
|
435 |
|
echo "I do not know how to parse [" . trim($line) . "]!\n"; |
|
436 |
|
exit(0); |
|
437 |
|
} |
|
438 |
|
|
|
439 |
|
return $ret; |
|
440 |
|
} |
|
441 |
|
|
|
442 |
457 |
/* |
/* |
443 |
458 |
* Outputs the result of replacing variables in a template with real variables |
* Outputs the result of replacing variables in a template with real variables |
444 |
459 |
*/ |
*/ |
|
... |
... |
function rg_git_stats($log) |
511 |
526 |
* Outputs the result of replacing variables in a template with real variables |
* Outputs the result of replacing variables in a template with real variables |
512 |
527 |
* @a - output of rg_git_diff2array[index] |
* @a - output of rg_git_diff2array[index] |
513 |
528 |
*/ |
*/ |
514 |
|
function rg_git_diff_template($a, $template_file) |
|
|
529 |
|
function rg_git_diff($a, $template_file) |
515 |
530 |
{ |
{ |
|
531 |
|
rg_log("git_diff: a: " . print_r($a, TRUE)); |
|
532 |
|
|
516 |
533 |
$ret = ""; |
$ret = ""; |
517 |
534 |
|
|
518 |
535 |
$template = @file_get_contents($template_file); |
$template = @file_get_contents($template_file); |
|
... |
... |
function rg_git_diff_template($a, $template_file) |
520 |
537 |
return "Error: cannot load template ($template_file)!"; |
return "Error: cannot load template ($template_file)!"; |
521 |
538 |
|
|
522 |
539 |
foreach ($a as $fileindex => $finfo) { |
foreach ($a as $fileindex => $finfo) { |
|
540 |
|
if (!isset($finfo['file'])) |
|
541 |
|
rg_log("BAD finfo:" . print_r($finfo, TRUE)); |
523 |
542 |
$f = $finfo['file']; |
$f = $finfo['file']; |
|
543 |
|
$ret .= "<br />"; |
524 |
544 |
$ret .= "<b>"; |
$ret .= "<b>"; |
525 |
545 |
if (strstr($finfo['flags'], "N")) |
if (strstr($finfo['flags'], "N")) |
526 |
|
$ret .= "file [$f] added </br/>\n"; |
|
|
546 |
|
$ret .= "file [$f] added\n"; |
527 |
547 |
else if (strstr($finfo['flags'], "D")) |
else if (strstr($finfo['flags'], "D")) |
528 |
|
$ret .= "file [$f] deleted:<br />"; |
|
|
548 |
|
$ret .= "file [$f] deleted:\n"; |
529 |
549 |
else |
else |
530 |
|
$ret .= "file [$f] changed:<br />\n"; |
|
|
550 |
|
$ret .= "file [$f] changed:\n"; |
531 |
551 |
$ret .= "</b>"; |
$ret .= "</b>"; |
532 |
552 |
|
|
533 |
553 |
foreach ($finfo['chunks'] as $chunk => $ci) { |
foreach ($finfo['chunks'] as $chunk => $ci) { |
534 |
|
$ret .= "chunk [$chunk], section [" . $ci['section'] . "]:<br />\n"; |
|
535 |
|
$ret .= "<table border=1>\n"; |
|
536 |
|
foreach ($ci['lines'] as $line_no => $line) { |
|
|
554 |
|
$ret .= "<br />"; |
|
555 |
|
$ret .= "Section [" . $ci['section'] . "] ($chunk):<br />\n"; |
|
556 |
|
$ret .= "<table>\n"; |
|
557 |
|
|
|
558 |
|
$line_no_left = $ci['from']; |
|
559 |
|
$line_no_right = $ci['to']; |
|
560 |
|
foreach ($ci['lines'] as $line) { |
537 |
561 |
$v = $template; |
$v = $template; |
538 |
562 |
|
|
539 |
563 |
$left_color = "#eeeeee"; |
$left_color = "#eeeeee"; |
|
... |
... |
function rg_git_diff_template($a, $template_file) |
541 |
565 |
|
|
542 |
566 |
$c = substr($line, 0, 1); |
$c = substr($line, 0, 1); |
543 |
567 |
$line = substr($line, 1); |
$line = substr($line, 1); |
544 |
|
if (strcmp($c, " ") == 0) { |
|
545 |
|
$left = $line; |
|
546 |
|
$right = $line; |
|
547 |
|
} else if (strcmp($c, "+") == 0) { |
|
|
568 |
|
if (strcmp($c, "+") == 0) { |
548 |
569 |
$left = ""; |
$left = ""; |
549 |
570 |
$right = $line; |
$right = $line; |
550 |
571 |
$right_color = "#00ff00"; |
$right_color = "#00ff00"; |
|
572 |
|
$line_left = " "; |
|
573 |
|
$line_right = $line_no_right; |
|
574 |
|
$line_no_right++; |
551 |
575 |
} else if (strcmp($c, "-") == 0) { |
} else if (strcmp($c, "-") == 0) { |
552 |
576 |
$left = $line; |
$left = $line; |
553 |
577 |
$left_color = "#ff0000"; |
$left_color = "#ff0000"; |
554 |
578 |
$right = ""; |
$right = ""; |
555 |
|
} else { |
|
556 |
|
echo "Something wrong with [$line]!\n"; |
|
557 |
|
exit(0); |
|
|
579 |
|
$line_left = $line_no_left; |
|
580 |
|
$line_right = " "; |
|
581 |
|
$line_no_left++; |
|
582 |
|
} else { // ' ' or any other character |
|
583 |
|
$left = $line; |
|
584 |
|
$right = $line; |
|
585 |
|
$line_left = $line_no_left; |
|
586 |
|
$line_right = $line_no_right; |
|
587 |
|
$line_no_left++; |
|
588 |
|
$line_no_right++; |
558 |
589 |
} |
} |
559 |
590 |
|
|
560 |
|
$v = preg_replace("/@@line@@/", $line_no, $v); |
|
|
591 |
|
$v = preg_replace("/@@line_left@@/", $line_left, $v); |
|
592 |
|
$v = preg_replace("/@@line_right@@/", $line_right, $v); |
561 |
593 |
$v = preg_replace("/@@left@@/", htmlspecialchars($left), $v); |
$v = preg_replace("/@@left@@/", htmlspecialchars($left), $v); |
562 |
594 |
$v = preg_replace("/@@right@@/", htmlspecialchars($right), $v); |
$v = preg_replace("/@@right@@/", htmlspecialchars($right), $v); |
563 |
595 |
|
|
|
... |
... |
function rg_git_diff_template($a, $template_file) |
572 |
604 |
return $ret; |
return $ret; |
573 |
605 |
} |
} |
574 |
606 |
|
|
|
607 |
|
/* |
|
608 |
|
* Show stats for files changed |
|
609 |
|
*/ |
|
610 |
|
function rg_git_files_stats($a, $theme_dir) |
|
611 |
|
{ |
|
612 |
|
$t = array(); |
|
613 |
|
foreach ($a as $file => $info) { |
|
614 |
|
$line = array(); |
|
615 |
|
$line['file'] = $file; |
|
616 |
|
$line['add'] = $info['add']; |
|
617 |
|
$line['del'] = $info['del']; |
|
618 |
|
$t[] = $line; |
|
619 |
|
} |
|
620 |
|
|
|
621 |
|
$more = array(); |
|
622 |
|
return rg_template_table($theme_dir, $t, $more); |
|
623 |
|
} |
|
624 |
|
|
575 |
625 |
?> |
?> |
File inc/repo.inc.php changed (mode: 100644) (index d783a35..10267db) |
... |
... |
function rg_repo_info($db, $rr) |
112 |
112 |
} else if (!empty($user) && !empty($repo)) { |
} else if (!empty($user) && !empty($repo)) { |
113 |
113 |
$ui = rg_user_info($db, 0, $user, ""); |
$ui = rg_user_info($db, 0, $user, ""); |
114 |
114 |
if ($ui['ok'] != 1) { |
if ($ui['ok'] != 1) { |
115 |
|
$ret['errmsg'] = "Invalid repo path (user)"; |
|
|
115 |
|
rg_repo_set_error("invalid repo path (user)"); |
116 |
116 |
return $ret; |
return $ret; |
117 |
117 |
} |
} |
118 |
118 |
$e_repo = rg_sql_escape($db, $repo); |
$e_repo = rg_sql_escape($db, $repo); |
119 |
119 |
$add = " uid = " . $ui['uid'] . " AND name = '$e_repo'"; |
$add = " uid = " . $ui['uid'] . " AND name = '$e_repo'"; |
120 |
120 |
} else { |
} else { |
121 |
|
$ret['errmsg'] = "No repo_id or user/name specified!"; |
|
|
121 |
|
rg_repo_set_error("no repo_id or user/name specified!"); |
122 |
122 |
return $ret; |
return $ret; |
123 |
123 |
} |
} |
124 |
124 |
|
|
125 |
125 |
$sql = "SELECT * FROM repos WHERE " . $add; |
$sql = "SELECT * FROM repos WHERE " . $add; |
126 |
126 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
127 |
127 |
if ($res === FALSE) { |
if ($res === FALSE) { |
128 |
|
$ret['errmsg'] = "Cannot query (" . rg_sql_error() . ")"; |
|
129 |
|
rg_log("\t" . $ret['errmsg']); |
|
|
128 |
|
rg_repo_set_error("cannot query (" . rg_sql_error() . ")"); |
130 |
129 |
return $ret; |
return $ret; |
131 |
130 |
} |
} |
132 |
131 |
$ret['ok'] = 1; |
$ret['ok'] = 1; |
|
... |
... |
function rg_repo_create($db, $master, $rg_ui, $name, $max_commit_size, |
205 |
204 |
return FALSE; |
return FALSE; |
206 |
205 |
|
|
207 |
206 |
// First, test if it already exists |
// First, test if it already exists |
208 |
|
$ri = rg_repo_info($db, 0, $name); |
|
|
207 |
|
$rr = array("user" => $rg_ui['username'], "repo" => $name); |
|
208 |
|
$ri = rg_repo_info($db, $rr); |
209 |
209 |
if ($ri['ok'] != 1) |
if ($ri['ok'] != 1) |
210 |
210 |
return FALSE; |
return FALSE; |
211 |
211 |
if ($ri['exists'] == 1) { |
if ($ri['exists'] == 1) { |
|
... |
... |
function rg_repo_list_query($db, $url, $sql) |
330 |
330 |
$_line = array(); |
$_line = array(); |
331 |
331 |
|
|
332 |
332 |
foreach ($row as $k => $v) |
foreach ($row as $k => $v) |
333 |
|
$_line[$k] = htmlspecialchars($v); |
|
|
333 |
|
$_line[$k] = $v; |
334 |
334 |
|
|
335 |
335 |
$_ui = rg_user_info($db, $row['uid'], "", ""); |
$_ui = rg_user_info($db, $row['uid'], "", ""); |
336 |
336 |
if ($_ui['exists'] != 1) { |
if ($_ui['exists'] != 1) { |
337 |
|
$v = "?" . $row['uid'] . "?"; |
|
338 |
|
$organization = 0; |
|
339 |
|
} else { |
|
340 |
|
$v = $_ui['username']; |
|
341 |
|
$organization = $_ui['organization']; |
|
|
337 |
|
rg_repo_set_error("user associated with this repo not found"); |
|
338 |
|
return FALSE; |
342 |
339 |
} |
} |
343 |
|
$_line['owner'] = htmlspecialchars($v); |
|
|
340 |
|
$_line['owner'] = $_ui['username']; |
344 |
341 |
|
|
345 |
|
$_line['link'] = rg_re_repopage($organization, $_line['owner'], |
|
346 |
|
$row['name']); |
|
|
342 |
|
$rr = array( |
|
343 |
|
"type" => ($_ui['organization'] == 1) ? "org" : "user", |
|
344 |
|
"user" => $_ui['username'], |
|
345 |
|
"repo" => $row['name'] |
|
346 |
|
); |
|
347 |
|
$_line['link'] = rg_re_repopage($rr); |
347 |
348 |
|
|
348 |
|
$_line['description'] = nl2br(htmlspecialchars($row['description'])); |
|
|
349 |
|
$_line['HTML:description'] = nl2br(htmlspecialchars($row['description'])); |
349 |
350 |
|
|
350 |
351 |
$master_repo = "-"; |
$master_repo = "-"; |
351 |
352 |
if ($row['master'] > 0) { |
if ($row['master'] > 0) { |
|
... |
... |
function rg_repo_list_query($db, $url, $sql) |
354 |
355 |
if ($_mi['exists'] = 1) |
if ($_mi['exists'] = 1) |
355 |
356 |
$master_repo = $_mi['name']; |
$master_repo = $_mi['name']; |
356 |
357 |
} |
} |
357 |
|
$_line['clone_of'] = htmlspecialchars($master_repo); |
|
|
358 |
|
$_line['clone_of'] = $master_repo; |
358 |
359 |
$_line['creation'] = gmdate("Y-m-d H:i:s", $row['itime']); |
$_line['creation'] = gmdate("Y-m-d H:i:s", $row['itime']); |
359 |
360 |
|
|
360 |
361 |
// rights |
// rights |
|
... |
... |
function rg_repo_rights_get($db, $ri, $uid, $flags) |
478 |
479 |
return $ret; |
return $ret; |
479 |
480 |
} |
} |
480 |
481 |
} else { |
} else { |
|
482 |
|
rg_log("\tuid $uid is NOT the owner (" . $ri['uid'] . ");" |
|
483 |
|
. " assign default rights."); |
481 |
484 |
$rights = $ri['default_rights']; |
$rights = $ri['default_rights']; |
482 |
485 |
} |
} |
483 |
486 |
|
|
File inc/user/repo-page.php changed (mode: 100644) (index 85aa2e4..05c84d4) |
... |
... |
if (rg_repo_ok($repo) !== TRUE) { |
13 |
13 |
return; |
return; |
14 |
14 |
} |
} |
15 |
15 |
|
|
16 |
|
$rr = array("user" => $user, "repo" => $repo); |
|
17 |
16 |
$ri = rg_repo_info($db, $rr); |
$ri = rg_repo_info($db, $rr); |
18 |
17 |
if ($ri === FALSE) { |
if ($ri === FALSE) { |
19 |
18 |
$_home .= "Internal error!"; |
$_home .= "Internal error!"; |
|
... |
... |
if ($ri === FALSE) { |
22 |
21 |
|
|
23 |
22 |
$_more = array( |
$_more = array( |
24 |
23 |
"owner" => $user, |
"owner" => $user, |
25 |
|
"url" => rg_re_repopage($ri['organization'], $user, $repo), |
|
|
24 |
|
"url" => rg_re_repopage($rr), |
26 |
25 |
); |
); |
27 |
26 |
$_home .= rg_template($THEME . "/repo/main.html", $ri, $_more); |
$_home .= rg_template($THEME . "/repo/main.html", $ri, $_more); |
28 |
27 |
|
|
29 |
|
$type = ($ri['organization'] == 1) ? "" : "user"; |
|
30 |
|
$rr = array("type" => $type, "user" => $user, "repo" => $repo); |
|
31 |
28 |
$repo_dir = rg_repo_name2base($rr) . $repo . ".git"; |
$repo_dir = rg_repo_name2base($rr) . $repo . ".git"; |
32 |
|
|
|
33 |
29 |
putenv("GIT_DIR=$repo_dir"); |
putenv("GIT_DIR=$repo_dir"); |
34 |
30 |
|
|
35 |
31 |
if (strcmp($subop, "tree") == 0) { |
if (strcmp($subop, "tree") == 0) { |
|
... |
... |
if (strcmp($subop, "tree") == 0) { |
38 |
34 |
$_home .= rg_template_table($THEME . "/repo/tree", $_tree, $_more); |
$_home .= rg_template_table($THEME . "/repo/tree", $_tree, $_more); |
39 |
35 |
} else if (strcmp($subop, "blob") == 0) { |
} else if (strcmp($subop, "blob") == 0) { |
40 |
36 |
$obj = rg_git_reference($paras[0]); |
$obj = rg_git_reference($paras[0]); |
|
37 |
|
$c = rg_git_content($obj); |
41 |
38 |
$blob = array( |
$blob = array( |
42 |
39 |
"obj" => $obj, |
"obj" => $obj, |
43 |
|
"content" => rg_git_content($obj) |
|
|
40 |
|
"HTML:content" => rg_template_list($c) |
44 |
41 |
); |
); |
45 |
42 |
$_home .= rg_template($THEME . "/repo/blob.html", $blob, $_more); |
$_home .= rg_template($THEME . "/repo/blob.html", $blob, $_more); |
46 |
43 |
} else { // log |
} else { // log |
47 |
|
$log = rg_git_log(10, FALSE); |
|
48 |
|
rg_log("log: " . print_r($log, TRUE)); |
|
49 |
|
$_home .= rg_git_log_template($log, $THEME . "/repo/log", $_more); |
|
|
44 |
|
$commit = rg_git_reference($paras[0]); |
|
45 |
|
if (empty($commit)) { |
|
46 |
|
$log = rg_git_log(10, "", "", FALSE); |
|
47 |
|
rg_log("log: " . print_r($log, TRUE)); |
|
48 |
|
$_home .= rg_git_log_template($log, $THEME . "/repo/log", $_more); |
|
49 |
|
} else { |
|
50 |
|
$log = rg_git_log(1, $commit . "~1", $commit, TRUE); |
|
51 |
|
rg_log("log: " . print_r($log, TRUE)); |
|
52 |
|
|
|
53 |
|
// stats |
|
54 |
|
$_home .= rg_git_files_stats($log[0]['files'], $THEME . "/repo/fstat"); |
|
55 |
|
|
|
56 |
|
// diff |
|
57 |
|
//rg_log("patch: " . print_r($log[0]['patches'], TRUE)); |
|
58 |
|
$_home .= rg_git_diff($log[0]['patches'], $THEME . "/repo/diff.html"); |
|
59 |
|
} |
50 |
60 |
} |
} |
51 |
61 |
|
|
52 |
62 |
?> |
?> |
File inc/util.inc.php changed (mode: 100644) (index 70db616..70432b0) |
... |
... |
function rg_re_post($op) |
93 |
93 |
return "/"; |
return "/"; |
94 |
94 |
} |
} |
95 |
95 |
|
|
96 |
|
function rg_re_repopage($org, $owner, $repo_name) |
|
|
96 |
|
function rg_re_repopage($rr) |
97 |
97 |
{ |
{ |
98 |
|
if ($org == 0) |
|
|
98 |
|
if (strcmp($rr['type'], "user") == 0) |
99 |
99 |
$prefix = "/user"; |
$prefix = "/user"; |
100 |
100 |
else |
else |
101 |
101 |
$prefix = ""; |
$prefix = ""; |
102 |
102 |
|
|
103 |
|
$s = $prefix . "/" . $owner . "/" . $repo_name; |
|
|
103 |
|
$s = $prefix . "/" . $rr['user'] . "/" . $rr['repo']; |
104 |
104 |
|
|
105 |
105 |
if (isset($_REQUEST['rwe'])) |
if (isset($_REQUEST['rwe'])) |
106 |
106 |
return $s; |
return $s; |
|
... |
... |
function rg_menu($a, $rg_ui) |
235 |
235 |
return $ret; |
return $ret; |
236 |
236 |
} |
} |
237 |
237 |
|
|
|
238 |
|
function rg_prepare_replace(&$data, &$what, &$values) |
|
239 |
|
{ |
|
240 |
|
if (count($data) == 0) |
|
241 |
|
return; |
|
242 |
|
|
|
243 |
|
foreach ($data as $k => $v) { |
|
244 |
|
if (strncmp($k, "HTML:", 5) == 0) { |
|
245 |
|
$k = substr($k, 5); |
|
246 |
|
} else { |
|
247 |
|
$v = htmlspecialchars($v); |
|
248 |
|
} |
|
249 |
|
$what[] = "/@@" . $k . "@@/"; |
|
250 |
|
$values[] = $v; |
|
251 |
|
} |
|
252 |
|
} |
|
253 |
|
|
238 |
254 |
/* |
/* |
239 |
255 |
* 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 |
240 |
256 |
*/ |
*/ |
241 |
257 |
function rg_template_table($dir, $data, $more) |
function rg_template_table($dir, $data, $more) |
242 |
258 |
{ |
{ |
|
259 |
|
rg_log("template_table($dir)"); |
|
260 |
|
|
243 |
261 |
$head = @file_get_contents($dir . "/header.html"); |
$head = @file_get_contents($dir . "/header.html"); |
244 |
262 |
if ($head === FALSE) |
if ($head === FALSE) |
245 |
263 |
$head = ""; |
$head = ""; |
|
... |
... |
function rg_template_table($dir, $data, $more) |
252 |
270 |
if ($foot === FALSE) |
if ($foot === FALSE) |
253 |
271 |
$foot = ""; |
$foot = ""; |
254 |
272 |
|
|
255 |
|
foreach ($more as $k => $v) { |
|
256 |
|
$m_what[] = "/@@" . $k . "@@/"; |
|
257 |
|
$m_values[] = htmlspecialchars($v); |
|
258 |
|
} |
|
|
273 |
|
$m_what = array(); $m_values = array(); |
|
274 |
|
rg_prepare_replace($more, $m_what, $m_values); |
259 |
275 |
|
|
260 |
276 |
$head = preg_replace($m_what, $m_values, $head); |
$head = preg_replace($m_what, $m_values, $head); |
261 |
277 |
$foot = preg_replace($m_what, $m_values, $foot); |
$foot = preg_replace($m_what, $m_values, $foot); |
262 |
278 |
|
|
263 |
279 |
$body = ""; |
$body = ""; |
264 |
280 |
foreach ($data as $index => $info) { |
foreach ($data as $index => $info) { |
265 |
|
$what = $m_what; |
|
266 |
|
$values = $m_values; |
|
|
281 |
|
$what = $m_what; $values = $m_values; |
267 |
282 |
|
|
268 |
|
foreach ($info as $k => $v) { |
|
269 |
|
$what[] = "/@@" . $k . "@@/"; |
|
270 |
|
$values[] = htmlspecialchars($v); |
|
271 |
|
} |
|
|
283 |
|
rg_prepare_replace($info, $what, $values); |
272 |
284 |
|
|
273 |
285 |
$body .= preg_replace($what, $values, $line); |
$body .= preg_replace($what, $values, $line); |
274 |
286 |
} |
} |
|
... |
... |
function rg_template_table($dir, $data, $more) |
278 |
290 |
|
|
279 |
291 |
function rg_template($file, $data, $more) |
function rg_template($file, $data, $more) |
280 |
292 |
{ |
{ |
|
293 |
|
rg_log("template($file)"); |
|
294 |
|
|
281 |
295 |
$body = @file_get_contents($file); |
$body = @file_get_contents($file); |
282 |
296 |
if ($body === FALSE) |
if ($body === FALSE) |
283 |
297 |
return ""; |
return ""; |
|
... |
... |
function rg_template($file, $data, $more) |
285 |
299 |
$what = array(); |
$what = array(); |
286 |
300 |
$values = array(); |
$values = array(); |
287 |
301 |
|
|
288 |
|
foreach ($more as $k => $v) { |
|
289 |
|
$what[] = "/@@" . $k . "@@/"; |
|
290 |
|
$values[] = htmlspecialchars($v); |
|
291 |
|
} |
|
292 |
|
|
|
293 |
|
foreach ($data as $k => $v) { |
|
294 |
|
$what[] = "/@@" . $k . "@@/"; |
|
295 |
|
$values[] = htmlspecialchars($v); |
|
296 |
|
} |
|
|
302 |
|
rg_prepare_replace($more, $what, $values); |
|
303 |
|
rg_prepare_replace($data, $what, $values); |
297 |
304 |
|
|
298 |
305 |
return preg_replace($what, $values, $body); |
return preg_replace($what, $values, $body); |
299 |
306 |
} |
} |
300 |
307 |
|
|
|
308 |
|
/* |
|
309 |
|
* Outputs a numbered list |
|
310 |
|
*/ |
|
311 |
|
function rg_template_list($a) |
|
312 |
|
{ |
|
313 |
|
if (count($a) == 0) |
|
314 |
|
return ""; |
|
315 |
|
|
|
316 |
|
$ret = ""; |
|
317 |
|
$i = 1; |
|
318 |
|
$add = ""; |
|
319 |
|
foreach ($a as $line) { |
|
320 |
|
$ret .= $add . $i . " " . htmlspecialchars($line); |
|
321 |
|
$add = "<br />"; |
|
322 |
|
$i++; |
|
323 |
|
} |
|
324 |
|
|
|
325 |
|
return $ret; |
|
326 |
|
} |
301 |
327 |
?> |
?> |