File inc/git.inc.php changed (mode: 100644) (index d580e10..1a16e22) |
... |
... |
function rg_git_repo_is_empty($repo_path) |
64 |
64 |
if (empty($scan)) |
if (empty($scan)) |
65 |
65 |
return TRUE; |
return TRUE; |
66 |
66 |
|
|
|
67 |
|
rg_log_ml('DEBUG: scan: ' . print_r($scan, TRUE)); |
|
68 |
|
return FALSE; |
|
69 |
|
} |
|
70 |
|
|
|
71 |
|
/* |
|
72 |
|
* Returns true if the branch contains no commit |
|
73 |
|
*/ |
|
74 |
|
function rg_git_branch_is_empty($repo_path, $ref) |
|
75 |
|
{ |
|
76 |
|
if (empty($repo_path)) |
|
77 |
|
$repo_path = '.'; |
|
78 |
|
|
|
79 |
|
if (file_exists($repo_path . '/.git')) |
|
80 |
|
$repo_path .= '/.git'; |
|
81 |
|
|
|
82 |
|
if (!file_exists($repo_path . '/refs/heads/' . $ref)) |
|
83 |
|
return TRUE; |
|
84 |
|
|
67 |
85 |
return FALSE; |
return FALSE; |
68 |
86 |
} |
} |
69 |
87 |
|
|
|
... |
... |
function rg_git_merge_base($repo_path, $a, $b) |
621 |
639 |
|
|
622 |
640 |
$ret = FALSE; |
$ret = FALSE; |
623 |
641 |
while (1) { |
while (1) { |
624 |
|
if (rg_git_repo_is_empty($repo_path)) { |
|
625 |
|
$ret = $rg_git_zero; |
|
|
642 |
|
if (rg_git_branch_is_empty($repo_path, $a)) { |
|
643 |
|
$ret = $rg_git_empty; |
626 |
644 |
break; |
break; |
627 |
645 |
} |
} |
628 |
646 |
|
|
|
... |
... |
function rg_git_ls_tree($repo_path, $tree, $path) |
761 |
779 |
|
|
762 |
780 |
$ret = FALSE; |
$ret = FALSE; |
763 |
781 |
while (1) { |
while (1) { |
|
782 |
|
if (rg_git_repo_is_empty($repo_path)) { |
|
783 |
|
$ret = array(); |
|
784 |
|
break; |
|
785 |
|
} |
|
786 |
|
|
764 |
787 |
$op = " "; |
$op = " "; |
765 |
788 |
if (empty($tree)) { |
if (empty($tree)) { |
766 |
789 |
$op = " --full-tree"; |
$op = " --full-tree"; |
|
... |
... |
function rg_git_log_simple($repo_path, $max, $from, $to, $also_patch, $files, |
1163 |
1186 |
|
|
1164 |
1187 |
$ret = FALSE; |
$ret = FALSE; |
1165 |
1188 |
while (1) { |
while (1) { |
1166 |
|
if (rg_git_repo_is_empty($repo_path)) { |
|
1167 |
|
rg_log('Repo is empty.'); |
|
1168 |
|
$ret = array(); |
|
1169 |
|
break; |
|
1170 |
|
} |
|
1171 |
|
|
|
1172 |
1189 |
$max_count = ($max == 0) ? "" : " --max-count=$max"; |
$max_count = ($max == 0) ? "" : " --max-count=$max"; |
1173 |
1190 |
$patches = $also_patch ? " --patch" : ""; |
$patches = $also_patch ? " --patch" : ""; |
1174 |
1191 |
$from_to = rg_git_from_to($from, $to); |
$from_to = rg_git_from_to($from, $to); |
|
... |
... |
function rg_git_merge_tree($repo_path, $base, $a, $b) |
2479 |
2496 |
|
|
2480 |
2497 |
$ret = FALSE; |
$ret = FALSE; |
2481 |
2498 |
while (1) { |
while (1) { |
|
2499 |
|
if (rg_git_repo_is_empty($repo_path)) |
|
2500 |
|
$a = $rg_git_empty; |
|
2501 |
|
|
2482 |
2502 |
$head = rg_git_load_ref($repo_path, $a); |
$head = rg_git_load_ref($repo_path, $a); |
2483 |
2503 |
if ($head === FALSE) |
if ($head === FALSE) |
2484 |
2504 |
break; |
break; |
|
2505 |
|
|
2485 |
2506 |
$key = 'git' |
$key = 'git' |
2486 |
2507 |
. '::' . sha1($repo_path) |
. '::' . sha1($repo_path) |
2487 |
2508 |
. '::' . 'merge-tree' |
. '::' . 'merge-tree' |
|
... |
... |
function rg_git_merge_tree($repo_path, $base, $a, $b) |
2495 |
2516 |
$cmd = RG_GIT_CMD . ' --git-dir=' . escapeshellarg($repo_path) |
$cmd = RG_GIT_CMD . ' --git-dir=' . escapeshellarg($repo_path) |
2496 |
2517 |
. ' merge-tree' |
. ' merge-tree' |
2497 |
2518 |
. ' ' . escapeshellarg($base) |
. ' ' . escapeshellarg($base) |
2498 |
|
. ' ' . escapeshellarg($a) |
|
|
2519 |
|
. ' ' . escapeshellarg($head) |
2499 |
2520 |
. ' ' . escapeshellarg($b); |
. ' ' . escapeshellarg($b); |
2500 |
2521 |
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
2501 |
2522 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
|
... |
... |
function rg_git_merge($repo_path, $ref_name, $new, $ff, $msg) |
2576 |
2597 |
|
|
2577 |
2598 |
$ret = FALSE; |
$ret = FALSE; |
2578 |
2599 |
while (1) { |
while (1) { |
|
2600 |
|
if (rg_git_repo_is_empty($repo_path)) |
|
2601 |
|
$ref_name_tmp = $rg_git_empty; |
|
2602 |
|
else |
|
2603 |
|
$ref_name_tmp = $ref_name; |
|
2604 |
|
|
2579 |
2605 |
// TODO: this must go away - the cache will malfunction? |
// TODO: this must go away - the cache will malfunction? |
2580 |
2606 |
if (empty($repo_path)) |
if (empty($repo_path)) |
2581 |
2607 |
$add = ''; |
$add = ''; |
|
... |
... |
function rg_git_merge($repo_path, $ref_name, $new, $ff, $msg) |
2592 |
2618 |
break; |
break; |
2593 |
2619 |
} |
} |
2594 |
2620 |
|
|
2595 |
|
$mb = rg_git_merge_base($repo_path, $ref_name, $new); |
|
|
2621 |
|
$mb = rg_git_merge_base($repo_path, $ref_name_tmp, $new); |
2596 |
2622 |
if ($mb === FALSE) |
if ($mb === FALSE) |
2597 |
2623 |
break; |
break; |
2598 |
2624 |
rg_log('DEBUG: merge-base=' . $mb); |
rg_log('DEBUG: merge-base=' . $mb); |
2599 |
2625 |
|
|
2600 |
|
$cur = rg_git_load_ref($repo_path, $ref_name); |
|
|
2626 |
|
$cur = rg_git_load_ref($repo_path, $ref_name_tmp); |
2601 |
2627 |
if ($cur === FALSE) |
if ($cur === FALSE) |
2602 |
2628 |
break; |
break; |
2603 |
2629 |
rg_log('DEBUG: ref_name points to ' . $cur); |
rg_log('DEBUG: ref_name points to ' . $cur); |
2604 |
2630 |
|
|
|
2631 |
|
// If repo was empty, we are forced to do a ff |
|
2632 |
|
if (strcmp($mb, $rg_git_empty) == 0) |
|
2633 |
|
$ff = 1; |
|
2634 |
|
|
2605 |
2635 |
if (($ff == 1) && (strcmp($mb, $cur) == 0)) { |
if (($ff == 1) && (strcmp($mb, $cur) == 0)) { |
2606 |
2636 |
rg_log('DEBUG: we can do a fast forward...'); |
rg_log('DEBUG: we can do a fast forward...'); |
2607 |
2637 |
$commit = $new; |
$commit = $new; |
2608 |
2638 |
} else { |
} else { |
2609 |
|
rg_log('DEBUG: we cannot do a fast forward.'); |
|
|
2639 |
|
rg_log('DEBUG: we must not do a fast forward.'); |
2610 |
2640 |
$e_mb = escapeshellarg($mb); |
$e_mb = escapeshellarg($mb); |
2611 |
|
$e_ref_name = escapeshellarg($ref_name); |
|
|
2641 |
|
$e_ref_name_tmp = escapeshellarg($ref_name_tmp); |
2612 |
2642 |
$e_new = escapeshellarg($new); |
$e_new = escapeshellarg($new); |
2613 |
2643 |
|
|
2614 |
2644 |
$cmd = RG_GIT_CMD |
$cmd = RG_GIT_CMD |
2615 |
2645 |
. $add . ' read-tree -i -m ' |
. $add . ' read-tree -i -m ' |
2616 |
|
. $e_mb . ' ' . $e_ref_name . ' ' . $e_new; |
|
|
2646 |
|
. $e_mb . ' ' . $e_ref_name_tmp . ' ' . $e_new; |
2617 |
2647 |
$r = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
$r = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
2618 |
2648 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
2619 |
2649 |
rg_git_set_error('error on merge (read-tree) (' |
rg_git_set_error('error on merge (read-tree) (' |
|
... |
... |
function rg_git_merge($repo_path, $ref_name, $new, $ff, $msg) |
2632 |
2662 |
|
|
2633 |
2663 |
$cmd = RG_GIT_CMD . $add . ' commit-tree ' |
$cmd = RG_GIT_CMD . $add . ' commit-tree ' |
2634 |
2664 |
. escapeshellarg($tree) |
. escapeshellarg($tree) |
2635 |
|
. ' -p ' . $e_ref_name . ' -p ' . $e_new |
|
|
2665 |
|
. ' -p ' . $e_ref_name_tmp . ' -p ' . $e_new |
2636 |
2666 |
. ' -m ' . escapeshellarg($msg); |
. ' -m ' . escapeshellarg($msg); |
2637 |
2667 |
$r = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
$r = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
2638 |
2668 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |