File inc/git.inc.php changed (mode: 100644) (index f76bbcd..dd2e737) |
... |
... |
$rg_git_patch_limit_default = 5000; |
9 |
9 |
if (!isset($rg_git_debug)) |
if (!isset($rg_git_debug)) |
10 |
10 |
$rg_git_debug = 0; |
$rg_git_debug = 0; |
11 |
11 |
|
|
12 |
|
$rg_git_zero = "0000000000000000000000000000000000000000"; |
|
13 |
|
$rg_git_empty = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"; |
|
|
12 |
|
define('RG_GIT_ZERO', '0000000000000000000000000000000000000000'); |
|
13 |
|
define('RG_GIT_ZERO_SHA256', '0000000000000000000000000000000000000000000000000000000000000000'); |
|
14 |
|
|
|
15 |
|
// generated by 'git hash-object -t tree /dev/null' |
|
16 |
|
define('RG_GIT_EMPTY', '4b825dc642cb6eb9a060e54bf8d69288fbee4904'); |
|
17 |
|
define('RG_GIT_EMPTY_SHA256', '6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321'); |
|
18 |
|
|
14 |
19 |
define('GIT_LINK_MASK', intval(base_convert('160000', 8, 10))); |
define('GIT_LINK_MASK', intval(base_convert('160000', 8, 10))); |
15 |
20 |
define('RG_GIT_HASH_LEN', 10); |
define('RG_GIT_HASH_LEN', 10); |
16 |
21 |
|
|
|
... |
... |
function rg_git_repo_is_empty($repo_path) |
69 |
74 |
return 0; |
return 0; |
70 |
75 |
} |
} |
71 |
76 |
|
|
|
77 |
|
/* |
|
78 |
|
* Returns the type of the repo (sha1 or sha256) |
|
79 |
|
*/ |
|
80 |
|
function rg_git_repo_get_hash($repo_path) |
|
81 |
|
{ |
|
82 |
|
$f = $repo_path . '/rocketgit/hash'; |
|
83 |
|
if (!file_exists($f)) |
|
84 |
|
return 'sha1'; |
|
85 |
|
|
|
86 |
|
$hash = @file_get_contents($f); |
|
87 |
|
if ($hash === FALSE) |
|
88 |
|
return ''; |
|
89 |
|
|
|
90 |
|
return trim($hash); |
|
91 |
|
} |
|
92 |
|
|
72 |
93 |
/* |
/* |
73 |
94 |
* Returns true if the ref is present in the repo |
* Returns true if the ref is present in the repo |
74 |
95 |
*/ |
*/ |
|
... |
... |
function rg_git_info_pack($band, $msg) |
225 |
246 |
*/ |
*/ |
226 |
247 |
function rg_git_from_to($from, $to) |
function rg_git_from_to($from, $to) |
227 |
248 |
{ |
{ |
228 |
|
global $rg_git_zero; |
|
229 |
|
global $rg_git_empty; |
|
230 |
|
|
|
231 |
249 |
if (empty($from) && empty($to)) { |
if (empty($from) && empty($to)) { |
232 |
250 |
rg_log_debug('from/to empty'); |
rg_log_debug('from/to empty'); |
233 |
251 |
$from_to = ''; |
$from_to = ''; |
234 |
252 |
} else if (empty($from)) { |
} else if (empty($from)) { |
235 |
253 |
rg_log_debug('from empty'); |
rg_log_debug('from empty'); |
236 |
254 |
$from_to = $to; |
$from_to = $to; |
237 |
|
} else if (strcmp($from, $rg_git_zero) == 0) { |
|
|
255 |
|
} else if (strcmp($from, RG_GIT_ZERO) == 0) { |
238 |
256 |
rg_log_debug('from zero'); |
rg_log_debug('from zero'); |
239 |
|
$from_to = $rg_git_empty . '..' . $to; |
|
|
257 |
|
$from_to = RG_GIT_EMPTY . '..' . $to; |
|
258 |
|
} else if (strcmp($from, RG_GIT_ZERO_SHA256) == 0) { |
|
259 |
|
rg_log_debug('from zero 256'); |
|
260 |
|
$from_to = RG_GIT_EMPTY_SHA256 . '..' . $to; |
240 |
261 |
} else if (empty($to)) { |
} else if (empty($to)) { |
241 |
262 |
rg_log_debug('to empty'); |
rg_log_debug('to empty'); |
242 |
263 |
$from_to = $from; |
$from_to = $from; |
|
... |
... |
function rg_git_install_hooks($dst) |
332 |
353 |
/* |
/* |
333 |
354 |
* Init a dir to host a git repository |
* Init a dir to host a git repository |
334 |
355 |
*/ |
*/ |
335 |
|
function rg_git_init($dst) |
|
|
356 |
|
function rg_git_init($dst, $branch, $hash) |
336 |
357 |
{ |
{ |
337 |
358 |
rg_prof_start("git_init"); |
rg_prof_start("git_init"); |
338 |
|
rg_log_enter("git_init: dst=$dst"); |
|
|
359 |
|
rg_log_enter('git_init: dst=' . $dst . ' branch=' . $branch |
|
360 |
|
. ' hash=' . $hash); |
339 |
361 |
|
|
340 |
362 |
$ret = FALSE; |
$ret = FALSE; |
341 |
363 |
while (1) { |
while (1) { |
|
... |
... |
function rg_git_init($dst) |
351 |
373 |
// TODO: What to do if the creation fails? |
// TODO: What to do if the creation fails? |
352 |
374 |
if (!is_dir($dst . "/rocketgit")) { |
if (!is_dir($dst . "/rocketgit")) { |
353 |
375 |
$dst2 = $dst . '.tmp'; |
$dst2 = $dst . '.tmp'; |
354 |
|
$cmd = RG_GIT_CMD . ' init --bare ' . escapeshellarg($dst2); |
|
|
376 |
|
if (strcmp($hash, 'sha256') == 0) |
|
377 |
|
$hash_add = ' --object-format=sha256'; |
|
378 |
|
else |
|
379 |
|
$hash_add = ''; |
|
380 |
|
$cmd = RG_GIT_CMD . ' init --bare' |
|
381 |
|
. ' --initial-branch=' . escapeshellarg($branch) |
|
382 |
|
. $hash_add |
|
383 |
|
. ' ' . escapeshellarg($dst2); |
355 |
384 |
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
356 |
385 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
|
386 |
|
rg_internal_error('git init: ' . $a['stderr']); |
357 |
387 |
rg_git_set_error("error on init " . $a['errmsg'] . ")"); |
rg_git_set_error("error on init " . $a['errmsg'] . ")"); |
358 |
388 |
break; |
break; |
359 |
389 |
} |
} |
|
... |
... |
function rg_git_init($dst) |
363 |
393 |
break; |
break; |
364 |
394 |
} |
} |
365 |
395 |
|
|
|
396 |
|
$r = @file_put_contents($dst2 . '/rocketgit/hash', $hash); |
|
397 |
|
if ($r === FALSE) { |
|
398 |
|
rg_git_set_error('cannot create [' . $dst |
|
399 |
|
. '/rocketgit/hash] file (' . rg_php_err() . ')'); |
|
400 |
|
break; |
|
401 |
|
} |
|
402 |
|
|
366 |
403 |
$r = @rename($dst2, $dst); |
$r = @rename($dst2, $dst); |
367 |
404 |
if ($r === FALSE) { |
if ($r === FALSE) { |
368 |
405 |
rg_git_set_error('cannot rename git dir from .tmp'); |
rg_git_set_error('cannot rename git dir from .tmp'); |
|
... |
... |
function rg_git_clone($src, $dst) |
430 |
467 |
*/ |
*/ |
431 |
468 |
function rg_git_type($obj) |
function rg_git_type($obj) |
432 |
469 |
{ |
{ |
433 |
|
global $rg_git_zero; |
|
434 |
|
|
|
435 |
470 |
rg_prof_start('git_type'); |
rg_prof_start('git_type'); |
436 |
471 |
rg_log_enter('git_type: obj=' . $obj); |
rg_log_enter('git_type: obj=' . $obj); |
437 |
472 |
|
|
438 |
473 |
$ret = FALSE; |
$ret = FALSE; |
439 |
474 |
while (1) { |
while (1) { |
440 |
|
if (strcmp($obj, $rg_git_zero) == 0) { |
|
|
475 |
|
if (strcmp($obj, RG_GIT_ZERO) == 0) { |
|
476 |
|
$ret = 'zero'; |
|
477 |
|
break; |
|
478 |
|
} |
|
479 |
|
|
|
480 |
|
if (strcmp($obj, RG_GIT_ZERO_SHA256) == 0) { |
441 |
481 |
$ret = 'zero'; |
$ret = 'zero'; |
442 |
482 |
break; |
break; |
443 |
483 |
} |
} |
|
... |
... |
function rg_git_rev_ok($rev) |
562 |
602 |
*/ |
*/ |
563 |
603 |
function rg_git_whitespace_ok($old, $new) |
function rg_git_whitespace_ok($old, $new) |
564 |
604 |
{ |
{ |
565 |
|
global $rg_git_zero; |
|
566 |
|
global $rg_git_empty; |
|
567 |
|
|
|
568 |
605 |
rg_prof_start("git_whitespace_ok"); |
rg_prof_start("git_whitespace_ok"); |
569 |
606 |
rg_log_enter("git_whitespace_ok: old=$old new=$new"); |
rg_log_enter("git_whitespace_ok: old=$old new=$new"); |
570 |
607 |
|
|
571 |
608 |
$ret = FALSE; |
$ret = FALSE; |
572 |
609 |
while (1) { |
while (1) { |
573 |
|
if (strcmp($old, $rg_git_zero) == 0) |
|
574 |
|
$old = $rg_git_empty; |
|
|
610 |
|
if (strcmp($old, RG_GIT_ZERO) == 0) |
|
611 |
|
$old = RG_GIT_EMPTY; |
|
612 |
|
else if (strcmp($old, RG_GIT_ZERO_SHA256) == 0) |
|
613 |
|
$old = RG_GIT_EMPTY_SHA256; |
575 |
614 |
|
|
576 |
615 |
$cmd = RG_GIT_CMD . " diff --check" |
$cmd = RG_GIT_CMD . " diff --check" |
577 |
616 |
. " " . escapeshellarg($old) |
. " " . escapeshellarg($old) |
|
... |
... |
function rg_git_whitespace_ok($old, $new) |
597 |
636 |
*/ |
*/ |
598 |
637 |
function rg_git_load_ref($repo_path, $ref) |
function rg_git_load_ref($repo_path, $ref) |
599 |
638 |
{ |
{ |
600 |
|
global $rg_git_empty; |
|
601 |
|
|
|
602 |
639 |
$b = rg_git_reference($ref); |
$b = rg_git_reference($ref); |
603 |
640 |
if ($b === FALSE) |
if ($b === FALSE) |
604 |
641 |
return FALSE; |
return FALSE; |
|
... |
... |
function rg_git_load_ref($repo_path, $ref) |
622 |
659 |
*/ |
*/ |
623 |
660 |
function rg_git_merge_base($repo_path, $refname_or_hash, $b) |
function rg_git_merge_base($repo_path, $refname_or_hash, $b) |
624 |
661 |
{ |
{ |
625 |
|
global $rg_git_zero; |
|
626 |
|
global $rg_git_empty; |
|
627 |
|
|
|
628 |
662 |
rg_prof_start('git_merge_base'); |
rg_prof_start('git_merge_base'); |
629 |
663 |
rg_log_enter('git_merge_base' . ' refname_or_hash=' . $refname_or_hash |
rg_log_enter('git_merge_base' . ' refname_or_hash=' . $refname_or_hash |
630 |
664 |
. ' b=' . $b); |
. ' b=' . $b); |
|
... |
... |
function rg_git_merge_base($repo_path, $refname_or_hash, $b) |
637 |
671 |
|
|
638 |
672 |
if ($r === 1) { |
if ($r === 1) { |
639 |
673 |
rg_log('DEBUG_MERGE: repo is empty. Return rg_git_empty.'); |
rg_log('DEBUG_MERGE: repo is empty. Return rg_git_empty.'); |
640 |
|
$ret = $rg_git_empty; |
|
|
674 |
|
$hash = rg_git_repo_get_hash($repo_path); |
|
675 |
|
if (empty($hash)) |
|
676 |
|
break; |
|
677 |
|
if (strcmp($hash, 'sha1') == 0) |
|
678 |
|
$ret = RG_GIT_EMPTY; |
|
679 |
|
else |
|
680 |
|
$ret = RG_GIT_EMPTY_SHA256; |
641 |
681 |
break; |
break; |
642 |
682 |
} |
} |
643 |
683 |
|
|
|
... |
... |
function rg_git_ls_tree($repo_path, $tree, $path) |
812 |
852 |
} |
} |
813 |
853 |
|
|
814 |
854 |
if (empty($a['data']) && !empty($path)) { |
if (empty($a['data']) && !empty($path)) { |
|
855 |
|
rg_log_debug('a[data] is empty; a: ' . print_r($a, TRUE)); |
815 |
856 |
rg_git_set_error('path does not exists'); |
rg_git_set_error('path does not exists'); |
816 |
857 |
break; |
break; |
817 |
858 |
} |
} |
|
... |
... |
function rg_git_log_simple($repo_path, $max, $from, $to, $also_patch, $files, |
1266 |
1307 |
. $patches |
. $patches |
1267 |
1308 |
. " --pretty=\"format:" |
. " --pretty=\"format:" |
1268 |
1309 |
. $sep_start |
. $sep_start |
1269 |
|
. "sha1:%H%x00\"\"" |
|
1270 |
|
. "sha1_short:%h%x00\"\"" |
|
|
1310 |
|
. "hash:%H%x00\"\"" |
|
1311 |
|
. "hash_short:%h%x00\"\"" |
1271 |
1312 |
. "tree:%T%x00\"\"" |
. "tree:%T%x00\"\"" |
1272 |
1313 |
. "tree_short:%t%x00\"\"" |
. "tree_short:%t%x00\"\"" |
1273 |
1314 |
. "parents:%P%x00\"\"" |
. "parents:%P%x00\"\"" |
|
... |
... |
function rg_git_log_simple($repo_path, $max, $from, $to, $also_patch, $files, |
1295 |
1336 |
} |
} |
1296 |
1337 |
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
1297 |
1338 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
|
1339 |
|
rg_log_debug('stderr: ' . $a['stderr']); |
1298 |
1340 |
rg_internal_error("error on log (" . $a['errmsg'] . ")" |
rg_internal_error("error on log (" . $a['errmsg'] . ")" |
1299 |
1341 |
. " cmd=" . $cmd); |
. " cmd=" . $cmd); |
1300 |
1342 |
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_log_detect_big_diff($stat) |
1476 |
1518 |
$ret = array(); |
$ret = array(); |
1477 |
1519 |
$at_least_one_bad = FALSE; |
$at_least_one_bad = FALSE; |
1478 |
1520 |
foreach ($stat as $junk => $per_commit) { |
foreach ($stat as $junk => $per_commit) { |
1479 |
|
$hash = $per_commit['vars']['sha1']; |
|
|
1521 |
|
$hash = $per_commit['vars']['hash']; |
1480 |
1522 |
|
|
1481 |
1523 |
$good_files = array(); |
$good_files = array(); |
1482 |
1524 |
$cur = 'good'; |
$cur = 'good'; |
|
... |
... |
function rg_git_stats($log) |
1706 |
1748 |
*/ |
*/ |
1707 |
1749 |
function rg_git_files($old, $new) |
function rg_git_files($old, $new) |
1708 |
1750 |
{ |
{ |
1709 |
|
global $rg_git_zero; |
|
1710 |
|
global $rg_git_empty; |
|
1711 |
|
|
|
1712 |
1751 |
rg_prof_start("git_files"); |
rg_prof_start("git_files"); |
1713 |
1752 |
rg_log_enter('git_files old=' . $old . ' new=' . $new); |
rg_log_enter('git_files old=' . $old . ' new=' . $new); |
1714 |
1753 |
|
|
1715 |
1754 |
$ret = FALSE; |
$ret = FALSE; |
1716 |
1755 |
while (1) { |
while (1) { |
1717 |
|
if (strcmp($old, $rg_git_zero) == 0) |
|
1718 |
|
$old = $rg_git_empty; |
|
|
1756 |
|
if (strcmp($old, RG_GIT_ZERO) == 0) |
|
1757 |
|
$old = RG_GIT_EMPTY; |
|
1758 |
|
else if (strcmp($old, RG_GIT_ZERO_SHA256) == 0) |
|
1759 |
|
$old = RG_GIT_EMPTY_SHA256; |
1719 |
1760 |
|
|
1720 |
|
$cmd = RG_GIT_CMD . ' diff --name-only ' . escapeshellarg($old) |
|
|
1761 |
|
$cmd = RG_GIT_CMD . ' diff --name-only ' |
|
1762 |
|
. ' ' . escapeshellarg($old) |
1721 |
1763 |
. ' ' . escapeshellarg($new); |
. ' ' . escapeshellarg($new); |
1722 |
1764 |
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
1723 |
1765 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
1724 |
1766 |
rg_git_set_error("error on git diff (" . $a['errmsg'] . ")"); |
rg_git_set_error("error on git diff (" . $a['errmsg'] . ")"); |
|
1767 |
|
rg_log_debug('stderr: ' . $a['stderr']); |
1725 |
1768 |
break; |
break; |
1726 |
1769 |
} |
} |
1727 |
1770 |
|
|
|
... |
... |
function rg_git_files($old, $new) |
1738 |
1781 |
/* |
/* |
1739 |
1782 |
* Nice diff per file |
* Nice diff per file |
1740 |
1783 |
* Outputs the result of replacing variables in a template with real variables |
* Outputs the result of replacing variables in a template with real variables |
1741 |
|
* @id - uniq id, most of the time the commit sha1; used to differentiate |
|
|
1784 |
|
* @id - uniq id, most of the time the commit hash; used to differentiate |
1742 |
1785 |
* between same files in different commits. |
* between same files in different commits. |
1743 |
1786 |
* @a - output of rg_git_diff2array[index]['files'] |
* @a - output of rg_git_diff2array[index]['files'] |
1744 |
1787 |
* TODO: Switch to rg_template_table? |
* TODO: Switch to rg_template_table? |
|
... |
... |
function rg_git_files_stats($hash, $a, $dir) |
1896 |
1939 |
*/ |
*/ |
1897 |
1940 |
function rg_git_update_tag($db, $a) |
function rg_git_update_tag($db, $a) |
1898 |
1941 |
{ |
{ |
1899 |
|
global $rg_git_zero; |
|
1900 |
|
|
|
1901 |
1942 |
rg_prof_start("git_update_tag"); |
rg_prof_start("git_update_tag"); |
1902 |
1943 |
rg_log_enter("git_update_tag: " . rg_array2string($a)); |
rg_log_enter("git_update_tag: " . rg_array2string($a)); |
1903 |
1944 |
|
|
|
... |
... |
function rg_git_update_tag($db, $a) |
1912 |
1953 |
$history['ui_login']['uid'] = $a['login_uid']; |
$history['ui_login']['uid'] = $a['login_uid']; |
1913 |
1954 |
|
|
1914 |
1955 |
if (strcmp($a['new_rev_type'], "tag") == 0) { // Annotated |
if (strcmp($a['new_rev_type'], "tag") == 0) { // Annotated |
1915 |
|
if (strcmp($a['old_rev'], $rg_git_zero) == 0) { // create |
|
|
1956 |
|
if ((strcmp($a['old_rev'], RG_GIT_ZERO) == 0) |
|
1957 |
|
|| (strcmp($a['old_rev'], RG_GIT_ZERO_SHA256) == 0)) { // create |
1916 |
1958 |
$x['needed_rights'] = 'S'; |
$x['needed_rights'] = 'S'; |
1917 |
1959 |
if (rg_rights_allow($db, $x) !== TRUE) |
if (rg_rights_allow($db, $x) !== TRUE) |
1918 |
1960 |
rg_git_fatal($a['refname'] . "\nNo rights to" |
rg_git_fatal($a['refname'] . "\nNo rights to" |
|
... |
... |
function rg_git_update_tag($db, $a) |
1920 |
1962 |
$history['history_category'] = REPO_CAT_GIT_ATAG_CREATE; |
$history['history_category'] = REPO_CAT_GIT_ATAG_CREATE; |
1921 |
1963 |
$history['history_message'] = 'Annotated tag ' |
$history['history_message'] = 'Annotated tag ' |
1922 |
1964 |
. $a['refname'] . ' created (' . $a['new_rev'] . ')'; |
. $a['refname'] . ' created (' . $a['new_rev'] . ')'; |
1923 |
|
} else if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete |
|
|
1965 |
|
} else if ((strcmp($a['new_rev'], RG_GIT_ZERO) == 0) |
|
1966 |
|
|| (strcmp($a['new_rev'], RG_GIT_ZERO_SHA256) == 0)) { // delete |
1924 |
1967 |
rg_log("delete ann tag"); |
rg_log("delete ann tag"); |
1925 |
1968 |
$x['needed_rights'] = 'n'; |
$x['needed_rights'] = 'n'; |
1926 |
1969 |
if (rg_rights_allow($db, $x) !== TRUE) |
if (rg_rights_allow($db, $x) !== TRUE) |
|
... |
... |
function rg_git_update_tag($db, $a) |
1942 |
1985 |
. $a['old_rev'] . ' to ' . $a['new_rev']; |
. $a['old_rev'] . ' to ' . $a['new_rev']; |
1943 |
1986 |
} |
} |
1944 |
1987 |
} else { // Un-annotated |
} else { // Un-annotated |
1945 |
|
if (strcmp($a['old_rev'], $rg_git_zero) == 0) { // create |
|
|
1988 |
|
if ((strcmp($a['old_rev'], RG_GIT_ZERO) == 0) |
|
1989 |
|
|| (strcmp($a['old_rev'], RG_GIT_ZERO_SHA256) == 0)) { // create |
1946 |
1990 |
$x['needed_rights'] = 'Y'; |
$x['needed_rights'] = 'Y'; |
1947 |
1991 |
if (rg_rights_allow($db, $x) !== TRUE) |
if (rg_rights_allow($db, $x) !== TRUE) |
1948 |
1992 |
rg_git_fatal($a['refname'] . "\nNo rights to" |
rg_git_fatal($a['refname'] . "\nNo rights to" |
|
... |
... |
function rg_git_update_tag($db, $a) |
1951 |
1995 |
$history['history_message'] = 'Un-annotated tag ' |
$history['history_message'] = 'Un-annotated tag ' |
1952 |
1996 |
. $a['refname'] . ' created' |
. $a['refname'] . ' created' |
1953 |
1997 |
. ' (' . $a['new_rev'] . ')'; |
. ' (' . $a['new_rev'] . ')'; |
1954 |
|
} else if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete |
|
|
1998 |
|
} else if ((strcmp($a['new_rev'], RG_GIT_ZERO) == 0) |
|
1999 |
|
|| (strcmp($a['new_rev'], RG_GIT_ZERO_SHA256) == 0)) { // delete |
1955 |
2000 |
$x['needed_rights'] = 'u'; |
$x['needed_rights'] = 'u'; |
1956 |
2001 |
if (rg_rights_allow($db, $x) !== TRUE) |
if (rg_rights_allow($db, $x) !== TRUE) |
1957 |
2002 |
rg_git_fatal($a['refname'] . "\nNo rights to" |
rg_git_fatal($a['refname'] . "\nNo rights to" |
|
... |
... |
function rg_git_update_tag($db, $a) |
1996 |
2041 |
*/ |
*/ |
1997 |
2042 |
function rg_git_update_branch($db, $a) |
function rg_git_update_branch($db, $a) |
1998 |
2043 |
{ |
{ |
1999 |
|
global $rg_git_zero; |
|
2000 |
|
|
|
2001 |
2044 |
rg_prof_start("git_update_branch"); |
rg_prof_start("git_update_branch"); |
2002 |
2045 |
rg_log_enter("git_update_branch: " . rg_array2string($a)); |
rg_log_enter("git_update_branch: " . rg_array2string($a)); |
2003 |
2046 |
|
|
|
... |
... |
function rg_git_update_branch($db, $a) |
2012 |
2055 |
$history['ri']['repo_id'] = $a['repo_id']; |
$history['ri']['repo_id'] = $a['repo_id']; |
2013 |
2056 |
$history['ui_login']['uid'] = $a['login_uid']; |
$history['ui_login']['uid'] = $a['login_uid']; |
2014 |
2057 |
|
|
2015 |
|
if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete |
|
|
2058 |
|
if ((strcmp($a['new_rev'], RG_GIT_ZERO) == 0) |
|
2059 |
|
|| (strcmp($a['new_rev'], RG_GIT_ZERO_SHA256) == 0)) { // delete |
2016 |
2060 |
$x = $_x; |
$x = $_x; |
2017 |
2061 |
$x['needed_rights'] = 'D'; |
$x['needed_rights'] = 'D'; |
2018 |
2062 |
if (rg_rights_allow($db, $x) !== TRUE) |
if (rg_rights_allow($db, $x) !== TRUE) |
|
... |
... |
function rg_git_update_branch($db, $a) |
2027 |
2071 |
|
|
2028 |
2072 |
// If we have 'H' (anonymous push), we have also 'create branch' right |
// If we have 'H' (anonymous push), we have also 'create branch' right |
2029 |
2073 |
$check_fast_forward = 1; |
$check_fast_forward = 1; |
2030 |
|
if (strcmp($a['old_rev'], $rg_git_zero) == 0) { // create |
|
|
2074 |
|
if ((strcmp($a['old_rev'], RG_GIT_ZERO) == 0) |
|
2075 |
|
|| (strcmp($a['old_rev'], RG_GIT_ZERO_SHA256) == 0)) { // create |
2031 |
2076 |
$x = $_x; |
$x = $_x; |
2032 |
2077 |
$x['needed_rights'] = 'H|C'; |
$x['needed_rights'] = 'H|C'; |
2033 |
2078 |
if (rg_rights_allow($db, $x) !== TRUE) |
if (rg_rights_allow($db, $x) !== TRUE) |
|
... |
... |
function rg_git_update_branch($db, $a) |
2162 |
2207 |
rg_git_fatal($a['refname'] . ": " . rg_event_error()); |
rg_git_fatal($a['refname'] . ": " . rg_event_error()); |
2163 |
2208 |
rg_event_signal_daemon('', 0); |
rg_event_signal_daemon('', 0); |
2164 |
2209 |
|
|
2165 |
|
if (strcmp($a['old_rev'], $rg_git_zero) == 0) { |
|
|
2210 |
|
if ((strcmp($a['old_rev'], RG_GIT_ZERO) == 0) |
|
2211 |
|
|| (strcmp($a['old_rev'], RG_GIT_ZERO_SHA256) == 0)) { |
2166 |
2212 |
$history['history_category'] = REPO_CAT_GIT_BRANCH_CREATE; |
$history['history_category'] = REPO_CAT_GIT_BRANCH_CREATE; |
2167 |
2213 |
$history['history_message'] = 'Reference ' |
$history['history_message'] = 'Reference ' |
2168 |
2214 |
. $a['refname'] . ' created' |
. $a['refname'] . ' created' |
|
... |
... |
function rg_git_log2listing($log, $rg, $commit_table) |
2415 |
2461 |
foreach ($log as $index => $i) |
foreach ($log as $index => $i) |
2416 |
2462 |
$log[$index]['vars']['commit_url'] = |
$log[$index]['vars']['commit_url'] = |
2417 |
2463 |
rg_xss_safe($rg['mr']['id']) |
rg_xss_safe($rg['mr']['id']) |
2418 |
|
. "#sha1-" . rg_xss_safe($i['vars']['sha1']); |
|
|
2464 |
|
. "#hash-" . rg_xss_safe($i['vars']['hash']); |
2419 |
2465 |
$rg['HTML:commit_table'] = rg_git_log_template($log, |
$rg['HTML:commit_table'] = rg_git_log_template($log, |
2420 |
2466 |
'repo/log', $rg); |
'repo/log', $rg); |
2421 |
2467 |
} else { |
} else { |
|
... |
... |
function rg_git_log2listing($log, $rg, $commit_table) |
2447 |
2493 |
= gmdate("Y-m-d H:i", $i['vars']['committer date']); |
= gmdate("Y-m-d H:i", $i['vars']['committer date']); |
2448 |
2494 |
|
|
2449 |
2495 |
// stats |
// stats |
2450 |
|
$r = rg_git_files_stats($i['vars']['sha1'], $i['files'], |
|
|
2496 |
|
$r = rg_git_files_stats($i['vars']['hash'], $i['files'], |
2451 |
2497 |
'repo/fstat'); |
'repo/fstat'); |
2452 |
2498 |
if ($r === FALSE) |
if ($r === FALSE) |
2453 |
2499 |
$i['HTML:x_stats'] = rg_template('repo/err/stats.html', $rg, TRUE /*xss*/); |
$i['HTML:x_stats'] = rg_template('repo/err/stats.html', $rg, TRUE /*xss*/); |
|
... |
... |
function rg_git_log2listing($log, $rg, $commit_table) |
2456 |
2502 |
|
|
2457 |
2503 |
// diff |
// diff |
2458 |
2504 |
//rg_log_debug('i[files]=' . print_r($i['files'], TRUE)); |
//rg_log_debug('i[files]=' . print_r($i['files'], TRUE)); |
2459 |
|
$r = rg_git_diff($i['vars']['sha1'], $i['files'], |
|
|
2505 |
|
$r = rg_git_diff($i['vars']['hash'], $i['files'], |
2460 |
2506 |
'repo/diff.html'); |
'repo/diff.html'); |
2461 |
2507 |
if ($r === FALSE) |
if ($r === FALSE) |
2462 |
2508 |
$i['HTML:x_diff'] = rg_template('repo/err/diff.html', $rg, TRUE /*xss*/); |
$i['HTML:x_diff'] = rg_template('repo/err/diff.html', $rg, TRUE /*xss*/); |
|
... |
... |
function rg_git_archive($repo_path, $treeish, $archive_name, $format) |
2530 |
2576 |
*/ |
*/ |
2531 |
2577 |
function rg_git_merge_tree($repo_path, $base, $a, $b) |
function rg_git_merge_tree($repo_path, $base, $a, $b) |
2532 |
2578 |
{ |
{ |
2533 |
|
global $rg_git_zero; |
|
2534 |
|
global $rg_git_empty; |
|
2535 |
|
|
|
2536 |
2579 |
rg_prof_start('git_merge_tree'); |
rg_prof_start('git_merge_tree'); |
2537 |
2580 |
rg_log_enter('git_merge_tree base=' |
rg_log_enter('git_merge_tree base=' |
2538 |
2581 |
. $base . ' a=' . $a . ' b=' . $b); |
. $base . ' a=' . $a . ' b=' . $b); |
|
... |
... |
function rg_git_merge_tree($repo_path, $base, $a, $b) |
2543 |
2586 |
if ($r === -1) |
if ($r === -1) |
2544 |
2587 |
break; |
break; |
2545 |
2588 |
|
|
2546 |
|
if ($r === 1) |
|
2547 |
|
$a = $rg_git_empty; |
|
|
2589 |
|
if ($r === 1) { |
|
2590 |
|
$hash = rg_git_repo_get_hash($repo_path); |
|
2591 |
|
if (empty($hash)) |
|
2592 |
|
break; |
|
2593 |
|
if (strcmp($hash, 'sha1') == 0) |
|
2594 |
|
$a = RG_GIT_EMPTY; |
|
2595 |
|
else |
|
2596 |
|
$a = RG_GIT_EMPTY_SHA256; |
|
2597 |
|
} |
2548 |
2598 |
|
|
2549 |
2599 |
$head = rg_git_load_ref($repo_path, $a); |
$head = rg_git_load_ref($repo_path, $a); |
2550 |
2600 |
if ($head === FALSE) |
if ($head === FALSE) |
|
... |
... |
function rg_git_merge_without_conflict($repo_path, $a, $b) |
2639 |
2689 |
*/ |
*/ |
2640 |
2690 |
function rg_git_merge($repo_path, $ref_name, $new, $ff, $msg) |
function rg_git_merge($repo_path, $ref_name, $new, $ff, $msg) |
2641 |
2691 |
{ |
{ |
2642 |
|
global $rg_git_zero; |
|
2643 |
|
global $rg_git_empty; |
|
2644 |
|
|
|
2645 |
2692 |
rg_prof_start('git_merge'); |
rg_prof_start('git_merge'); |
2646 |
2693 |
rg_log_enter('git_merge' . ' ref_name=' . $ref_name |
rg_log_enter('git_merge' . ' ref_name=' . $ref_name |
2647 |
2694 |
. ' new=' . $new . ' ff=' . $ff . ' msg=[' . $msg . ']'); |
. ' new=' . $new . ' ff=' . $ff . ' msg=[' . $msg . ']'); |
|
... |
... |
function rg_git_merge($repo_path, $ref_name, $new, $ff, $msg) |
2652 |
2699 |
if ($r === -1) |
if ($r === -1) |
2653 |
2700 |
break; |
break; |
2654 |
2701 |
|
|
2655 |
|
if ($r === 1) |
|
2656 |
|
$ref_name_tmp = $rg_git_empty; |
|
2657 |
|
else |
|
|
2702 |
|
if ($r === 1) { |
|
2703 |
|
$hash = rg_git_repo_get_hash($repo_path); |
|
2704 |
|
if (empty($hash)) |
|
2705 |
|
break; |
|
2706 |
|
if (strcmp($hash, 'sha1') == 0) |
|
2707 |
|
$ref_name_tmp = RG_GIT_EMPTY; |
|
2708 |
|
else |
|
2709 |
|
$ref_name_tmp = RG_GIT_EMPTY_SHA256; |
|
2710 |
|
} else { |
2658 |
2711 |
$ref_name_tmp = $ref_name; |
$ref_name_tmp = $ref_name; |
|
2712 |
|
} |
2659 |
2713 |
|
|
2660 |
2714 |
$r = rg_git_lock($repo_path, 60); |
$r = rg_git_lock($repo_path, 60); |
2661 |
2715 |
if ($r === FALSE) |
if ($r === FALSE) |
|
... |
... |
function rg_git_merge($repo_path, $ref_name, $new, $ff, $msg) |
2678 |
2732 |
rg_log_debug('ref_name points to ' . $cur); |
rg_log_debug('ref_name points to ' . $cur); |
2679 |
2733 |
|
|
2680 |
2734 |
// If repo was empty, we are forced to do a ff |
// If repo was empty, we are forced to do a ff |
2681 |
|
if (strcmp($mb, $rg_git_empty) == 0) { |
|
|
2735 |
|
if ((strcmp($mb, RG_GIT_EMPTY) == 0) |
|
2736 |
|
|| (strcmp($mb, RG_GIT_EMPTY_SHA256) == 0)) { |
2682 |
2737 |
rg_log_debug('merge base is empty, allow fast-forward.'); |
rg_log_debug('merge base is empty, allow fast-forward.'); |
2683 |
2738 |
$ff = 1; |
$ff = 1; |
2684 |
2739 |
} |
} |
|
... |
... |
function rg_git_merge($repo_path, $ref_name, $new, $ff, $msg) |
2751 |
2806 |
*/ |
*/ |
2752 |
2807 |
function rg_git_request_pull($repo_path, $start, $url, $end, $patch) |
function rg_git_request_pull($repo_path, $start, $url, $end, $patch) |
2753 |
2808 |
{ |
{ |
2754 |
|
global $rg_git_zero; |
|
2755 |
|
global $rg_git_empty; |
|
2756 |
|
|
|
2757 |
2809 |
rg_prof_start('git_request_pull'); |
rg_prof_start('git_request_pull'); |
2758 |
2810 |
rg_log_enter('git_request_pull' . ' start=' . $start |
rg_log_enter('git_request_pull' . ' start=' . $start |
2759 |
2811 |
. ' url=' . $url . ' end=' . $end |
. ' url=' . $url . ' end=' . $end |
File inc/repo.inc.php changed (mode: 100644) (index 4bb4e42..72de84d) |
... |
... |
function rg_repo_cosmetic($db, &$row) |
153 |
153 |
|
|
154 |
154 |
if (isset($row['disk_used_mb'])) |
if (isset($row['disk_used_mb'])) |
155 |
155 |
$row['disk_used'] = rg_1024($row['disk_used_mb'] * 1024 * 1024); |
$row['disk_used'] = rg_1024($row['disk_used_mb'] * 1024 * 1024); |
|
156 |
|
|
|
157 |
|
if (empty($row['main_branch'])) |
|
158 |
|
$row['main_branch'] = 'main'; |
|
159 |
|
|
|
160 |
|
if (empty($row['hash'])) |
|
161 |
|
$row['hash'] = 'sha1'; |
156 |
162 |
} |
} |
157 |
163 |
|
|
158 |
164 |
/* |
/* |
|
... |
... |
function rg_repo_event_storage_create($db, $e) |
627 |
633 |
} |
} |
628 |
634 |
|
|
629 |
635 |
if ($e['ri']['master'] == 0) { |
if ($e['ri']['master'] == 0) { |
630 |
|
$r = rg_git_init($by_id_path); |
|
|
636 |
|
$r = rg_git_init($by_id_path, $e['ri']['main_branch'], |
|
637 |
|
$e['ri']['hash']); |
631 |
638 |
if ($r === FALSE) { |
if ($r === FALSE) { |
632 |
639 |
rg_repo_set_error("cannot init master" |
rg_repo_set_error("cannot init master" |
633 |
640 |
. " (" . rg_git_error() . ")"); |
. " (" . rg_git_error() . ")"); |
|
... |
... |
function rg_repo_edit($db, $ui_login, &$new) |
1154 |
1161 |
$new['itime'] = time(); |
$new['itime'] = time(); |
1155 |
1162 |
$new['uid'] = $ui_login['uid']; |
$new['uid'] = $ui_login['uid']; |
1156 |
1163 |
if (!isset($new['main_branch'])) |
if (!isset($new['main_branch'])) |
1157 |
|
$new['main_branch'] = ''; |
|
|
1164 |
|
$new['main_branch'] = 'main'; |
1158 |
1165 |
|
|
1159 |
1166 |
if ($new['repo_id'] == 0) { |
if ($new['repo_id'] == 0) { |
1160 |
1167 |
$new['deleted'] = 0; |
$new['deleted'] = 0; |
|
... |
... |
function rg_repo_edit($db, $ui_login, &$new) |
1166 |
1173 |
$sql = "INSERT INTO repos (uid, master, name" |
$sql = "INSERT INTO repos (uid, master, name" |
1167 |
1174 |
. ", itime, max_commit_size, description" |
. ", itime, max_commit_size, description" |
1168 |
1175 |
. ", git_dir_done, public, license, template" |
. ", git_dir_done, public, license, template" |
1169 |
|
. ", main_branch)" |
|
|
1176 |
|
. ", main_branch, hash)" |
1170 |
1177 |
. " VALUES (@@uid@@, @@master@@, @@name@@" |
. " VALUES (@@uid@@, @@master@@, @@name@@" |
1171 |
1178 |
. ", @@itime@@, @@max_commit_size@@" |
. ", @@itime@@, @@max_commit_size@@" |
1172 |
1179 |
. ", @@description@@, 0, @@public@@" |
. ", @@description@@, 0, @@public@@" |
1173 |
|
. ", @@license@@, @@template@@, @@main_branch@@)" |
|
|
1180 |
|
. ", @@license@@, @@template@@, @@main_branch@@" |
|
1181 |
|
. ", @@hash@@)" |
1174 |
1182 |
. " RETURNING repo_id"; |
. " RETURNING repo_id"; |
1175 |
1183 |
} else { |
} else { |
1176 |
1184 |
$sql = "UPDATE repos SET name = @@name@@" |
$sql = "UPDATE repos SET name = @@name@@" |
|
... |
... |
function rg_repo_edit($db, $ui_login, &$new) |
1180 |
1188 |
. ", license = @@license@@" |
. ", license = @@license@@" |
1181 |
1189 |
. ", template = @@template@@" |
. ", template = @@template@@" |
1182 |
1190 |
. ", main_branch = @@main_branch@@" |
. ", main_branch = @@main_branch@@" |
|
1191 |
|
. ", hash = @@hash@@" |
1183 |
1192 |
. " WHERE repo_id = @@repo_id@@"; |
. " WHERE repo_id = @@repo_id@@"; |
1184 |
1193 |
} |
} |
1185 |
1194 |
$res = rg_sql_query_params($db, $sql, $new); |
$res = rg_sql_query_params($db, $sql, $new); |
|
... |
... |
function rg_repo_edit_high_level($db, &$rg) |
1734 |
1743 |
. 'Application version(s) affected?' . "\n\n" |
. 'Application version(s) affected?' . "\n\n" |
1735 |
1744 |
. 'Steps to reproduce?'; |
. 'Steps to reproduce?'; |
1736 |
1745 |
$rg['ri']['main_branch'] = ''; |
$rg['ri']['main_branch'] = ''; |
|
1746 |
|
$rg['ri']['hash'] = 'sha1'; |
1737 |
1747 |
} |
} |
1738 |
1748 |
break; |
break; |
1739 |
1749 |
} |
} |
|
... |
... |
function rg_repo_edit_high_level($db, &$rg) |
1747 |
1757 |
$rg['ri']['license'] = trim(rg_var_str('license')); |
$rg['ri']['license'] = trim(rg_var_str('license')); |
1748 |
1758 |
$rg['ri']['template'] = trim(rg_var_str('template')); |
$rg['ri']['template'] = trim(rg_var_str('template')); |
1749 |
1759 |
$rg['ri']['main_branch'] = trim(rg_var_str_nocr('main_branch')); |
$rg['ri']['main_branch'] = trim(rg_var_str_nocr('main_branch')); |
|
1760 |
|
$rg['ri']['hash'] = trim(rg_var_str_nocr('hash')); |
1750 |
1761 |
rg_repo_cosmetic($db, $rg['ri']); |
rg_repo_cosmetic($db, $rg['ri']); |
1751 |
1762 |
//rg_log_ml("CHECK: after repo edit: rg[ri]=" . print_r($rg['ri'], TRUE)); |
//rg_log_ml("CHECK: after repo edit: rg[ri]=" . print_r($rg['ri'], TRUE)); |
1752 |
1763 |
|
|