| File inc/git.inc.php changed (mode: 100644) (index ac532c0..c63f455) |
| ... |
... |
function rg_git_fatal($msg) |
| 30 |
30 |
echo "RocketGit: $line\n"; |
echo "RocketGit: $line\n"; |
| 31 |
31 |
} |
} |
| 32 |
32 |
echo "==========\n"; |
echo "==========\n"; |
|
33 |
|
flush(); |
| 33 |
34 |
exit(1); |
exit(1); |
| 34 |
35 |
} |
} |
| 35 |
36 |
|
|
| |
| ... |
... |
function rg_git_rev($rev) |
| 258 |
259 |
*/ |
*/ |
| 259 |
260 |
function rg_git_reference($refname) |
function rg_git_reference($refname) |
| 260 |
261 |
{ |
{ |
| 261 |
|
$pattern = "[a-zA-Z0-9^~\/_]*"; |
|
|
262 |
|
// We do not accept '..' chars |
|
263 |
|
if (preg_match('/\.\./', $refname) !== 0) { |
|
264 |
|
rg_git_set_error('we do not accept \'..\' inside the ref name'); |
|
265 |
|
return FALSE; |
|
266 |
|
} |
|
267 |
|
|
|
268 |
|
// We do not accept '/.' chars |
|
269 |
|
if (preg_match('/\/\./', $refname) !== 0) { |
|
270 |
|
rg_git_set_error('we do not accept \'/.\' inside the ref name'); |
|
271 |
|
return FALSE; |
|
272 |
|
} |
|
273 |
|
|
|
274 |
|
// We do not accept '\\' chars |
|
275 |
|
if (preg_match('/\\\\/', $refname) !== 0) { |
|
276 |
|
rg_git_set_error('we do not accept \'\\\\\' inside the ref name'); |
|
277 |
|
return FALSE; |
|
278 |
|
} |
|
279 |
|
|
|
280 |
|
// We do not accept ending '.lock' chars |
|
281 |
|
if (preg_match('/(.lock|\/|\.)$/', $refname) !== 0) { |
|
282 |
|
rg_git_set_error('we do not accept a ref name ending in .lock' |
|
283 |
|
. ' or slash or dot'); |
|
284 |
|
return FALSE; |
|
285 |
|
} |
|
286 |
|
|
|
287 |
|
$pattern = "[-a-zA-Z0-9\/_.]*"; |
| 262 |
288 |
$r = preg_match('/^' . $pattern . '$/uD', $refname); |
$r = preg_match('/^' . $pattern . '$/uD', $refname); |
| 263 |
289 |
if ($r === FALSE) { |
if ($r === FALSE) { |
| 264 |
290 |
rg_internal_error("preg_match failed!"); |
rg_internal_error("preg_match failed!"); |
| |
| ... |
... |
function rg_git_reference($refname) |
| 266 |
292 |
} |
} |
| 267 |
293 |
if ($r !== 1) { |
if ($r !== 1) { |
| 268 |
294 |
$chars = preg_replace('/' . $pattern . '/', '', $refname); |
$chars = preg_replace('/' . $pattern . '/', '', $refname); |
| 269 |
|
rg_log("git_reference: ref [$refname] contains invalid chars ($chars) (r=$r)"); |
|
| 270 |
|
return ""; |
|
|
295 |
|
rg_git_set_error('we do not accept [' . $chars |
|
296 |
|
. '] inside a ref name'); |
|
297 |
|
return FALSE; |
| 271 |
298 |
} |
} |
| 272 |
299 |
|
|
| 273 |
300 |
return $refname; |
return $refname; |
| |
| ... |
... |
function rg_git_merge_base($old, $new) |
| 358 |
385 |
return $ret; |
return $ret; |
| 359 |
386 |
} |
} |
| 360 |
387 |
|
|
| 361 |
|
// TODO: Unit testing |
|
| 362 |
388 |
/* |
/* |
| 363 |
389 |
* Safely update a reference - used to update main namespace from other ns |
* Safely update a reference - used to update main namespace from other ns |
| 364 |
390 |
* If @new is empty, we assume a delete |
* If @new is empty, we assume a delete |
|
391 |
|
* TODO: Unit testing |
| 365 |
392 |
*/ |
*/ |
| 366 |
393 |
function rg_git_update_ref($ref, $old, $new, $reason) |
function rg_git_update_ref($ref, $old, $new, $reason) |
| 367 |
394 |
{ |
{ |
| |
| ... |
... |
function rg_git_update_tag($db, $a) |
| 1047 |
1074 |
rg_git_fatal($a['refname'] . "\nNo rights to" |
rg_git_fatal($a['refname'] . "\nNo rights to" |
| 1048 |
1075 |
. " create an annotated tag."); |
. " create an annotated tag."); |
| 1049 |
1076 |
$history['history_category'] = REPO_CAT_GIT_ATAG_CREATE; |
$history['history_category'] = REPO_CAT_GIT_ATAG_CREATE; |
| 1050 |
|
$history['history_message'] = 'Annotated tag ' . $a['refname'] . ' created (' . $a['new_rev'] . ').'; |
|
| 1051 |
|
rg_repo_history_insert($db, $history); |
|
|
1077 |
|
$history['history_message'] = 'Annotated tag ' |
|
1078 |
|
. $a['refname'] . ' created (' . $a['new_rev'] . ')'; |
| 1052 |
1079 |
} else if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete |
} else if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete |
| 1053 |
1080 |
rg_log("delete ann tag"); |
rg_log("delete ann tag"); |
| 1054 |
1081 |
$x['needed_rights'] = 'n'; |
$x['needed_rights'] = 'n'; |
| |
| ... |
... |
function rg_git_update_tag($db, $a) |
| 1056 |
1083 |
rg_git_fatal($a['refname'] . "\nNo rights to" |
rg_git_fatal($a['refname'] . "\nNo rights to" |
| 1057 |
1084 |
. " delete an annotated tag."); |
. " delete an annotated tag."); |
| 1058 |
1085 |
$history['history_category'] = REPO_CAT_GIT_ATAG_DELETE; |
$history['history_category'] = REPO_CAT_GIT_ATAG_DELETE; |
| 1059 |
|
$history['history_message'] = 'Annotated tag ' . $a['refname'] . ' deleted (' . $a['old_rev'] . ').'; |
|
| 1060 |
|
rg_repo_history_insert($db, $history); |
|
|
1086 |
|
$history['history_message'] = 'Annotated tag ' |
|
1087 |
|
. $a['refname'] . ' deleted" |
|
1088 |
|
. " (' . $a['old_rev'] . ')'; |
| 1061 |
1089 |
} else { // change |
} else { // change |
| 1062 |
1090 |
rg_log("This seems it cannot happen in recent git."); |
rg_log("This seems it cannot happen in recent git."); |
| 1063 |
1091 |
$x['needed_rights'] = 'S'; |
$x['needed_rights'] = 'S'; |
| |
| ... |
... |
function rg_git_update_tag($db, $a) |
| 1065 |
1093 |
rg_git_fatal($a['refname'] . "\nNo rights to" |
rg_git_fatal($a['refname'] . "\nNo rights to" |
| 1066 |
1094 |
. " change an annotated tag."); |
. " change an annotated tag."); |
| 1067 |
1095 |
$history['history_category'] = REPO_CAT_GIT_ATAG_UPDATE; |
$history['history_category'] = REPO_CAT_GIT_ATAG_UPDATE; |
| 1068 |
|
$history['history_message'] = 'Annotated tag ' . $a['refname'] . ' updated from ' . $a['old_rev'] . ' to ' . $a['new_rev'] . '.'; |
|
| 1069 |
|
rg_repo_history_insert($db, $history); |
|
|
1096 |
|
$history['history_message'] = 'Annotated tag ' |
|
1097 |
|
. $a['refname'] . ' updated from ' |
|
1098 |
|
. $a['old_rev'] . ' to ' . $a['new_rev']; |
| 1070 |
1099 |
} |
} |
| 1071 |
1100 |
} else { // Un-annotated |
} else { // Un-annotated |
| 1072 |
1101 |
if (strcmp($a['old_rev'], $rg_git_zero) == 0) { // create |
if (strcmp($a['old_rev'], $rg_git_zero) == 0) { // create |
| |
| ... |
... |
function rg_git_update_tag($db, $a) |
| 1075 |
1104 |
rg_git_fatal($a['refname'] . "\nNo rights to" |
rg_git_fatal($a['refname'] . "\nNo rights to" |
| 1076 |
1105 |
. " create an un-annotated tag."); |
. " create an un-annotated tag."); |
| 1077 |
1106 |
$history['history_category'] = REPO_CAT_GIT_UTAG_CREATE; |
$history['history_category'] = REPO_CAT_GIT_UTAG_CREATE; |
| 1078 |
|
$history['history_message'] = 'Un-annotated tag ' . $a['refname'] . ' created (' . $a['new_rev'] . ').'; |
|
| 1079 |
|
rg_repo_history_insert($db, $history); |
|
|
1107 |
|
$history['history_message'] = 'Un-annotated tag ' |
|
1108 |
|
. $a['refname'] . ' created' |
|
1109 |
|
. ' (' . $a['new_rev'] . ')'; |
| 1080 |
1110 |
} else if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete |
} else if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete |
| 1081 |
1111 |
$x['needed_rights'] = 'u'; |
$x['needed_rights'] = 'u'; |
| 1082 |
1112 |
if (rg_rights_allow($db, $x) !== TRUE) |
if (rg_rights_allow($db, $x) !== TRUE) |
| 1083 |
1113 |
rg_git_fatal($a['refname'] . "\nNo rights to" |
rg_git_fatal($a['refname'] . "\nNo rights to" |
| 1084 |
1114 |
. " delete an un-annotated tag."); |
. " delete an un-annotated tag."); |
| 1085 |
1115 |
$history['history_category'] = REPO_CAT_GIT_UTAG_DELETE; |
$history['history_category'] = REPO_CAT_GIT_UTAG_DELETE; |
| 1086 |
|
$history['history_message'] = 'Un-annotated tag ' . $a['refname'] . ' deleted (' . $a['old_rev'] . ').'; |
|
| 1087 |
|
rg_repo_history_insert($db, $history); |
|
|
1116 |
|
$history['history_message'] = 'Un-annotated tag ' |
|
1117 |
|
. $a['refname'] . ' deleted' |
|
1118 |
|
. ' (' . $a['old_rev'] . ')'; |
| 1088 |
1119 |
} else { // change |
} else { // change |
| 1089 |
1120 |
$x['needed_rights'] = 'U'; |
$x['needed_rights'] = 'U'; |
| 1090 |
1121 |
if (rg_rights_allow($db, $x) !== TRUE) |
if (rg_rights_allow($db, $x) !== TRUE) |
| 1091 |
1122 |
rg_git_fatal($a['refname'] . "\nNo rights to" |
rg_git_fatal($a['refname'] . "\nNo rights to" |
| 1092 |
1123 |
. " change an un-annotated tag."); |
. " change an un-annotated tag."); |
| 1093 |
1124 |
$history['history_category'] = REPO_CAT_GIT_UTAG_UPDATE; |
$history['history_category'] = REPO_CAT_GIT_UTAG_UPDATE; |
| 1094 |
|
$history['history_message'] = 'Annotated tag ' . $a['refname'] . ' updated from ' . $a['old_rev'] . ' to ' . $a['new_rev'] . '.'; |
|
| 1095 |
|
rg_repo_history_insert($db, $history); |
|
|
1125 |
|
$history['history_message'] = 'Annotated tag ' |
|
1126 |
|
. $a['refname'] . ' updated from ' |
|
1127 |
|
. $a['old_rev'] . ' to ' . $a['new_rev']; |
| 1096 |
1128 |
} |
} |
| 1097 |
1129 |
} |
} |
| 1098 |
1130 |
|
|
| |
| ... |
... |
function rg_git_update_tag($db, $a) |
| 1100 |
1132 |
// Not clear when we do not have a namespace. |
// Not clear when we do not have a namespace. |
| 1101 |
1133 |
if (!empty($a['namespace'])) { |
if (!empty($a['namespace'])) { |
| 1102 |
1134 |
// Update the main namespace |
// Update the main namespace |
|
1135 |
|
$reason = $a['login_username'] . ' pushed tag ' . $a['refname']; |
| 1103 |
1136 |
$r = rg_git_update_ref($a['refname'], $a['old_rev'], |
$r = rg_git_update_ref($a['refname'], $a['old_rev'], |
| 1104 |
|
$a['new_rev'], "reason"); |
|
|
1137 |
|
$a['new_rev'], $reason); |
| 1105 |
1138 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
| 1106 |
1139 |
rg_git_fatal($a['refname'] . "\nCannot update ref (" |
rg_git_fatal($a['refname'] . "\nCannot update ref (" |
| 1107 |
1140 |
. rg_git_error() . ")"); |
. rg_git_error() . ")"); |
| |
| ... |
... |
function rg_git_update_tag($db, $a) |
| 1110 |
1143 |
// We can clean now the tmp namespace - TODO |
// We can clean now the tmp namespace - TODO |
| 1111 |
1144 |
} |
} |
| 1112 |
1145 |
|
|
|
1146 |
|
rg_repo_history_insert($db, $history); |
|
1147 |
|
|
| 1113 |
1148 |
rg_log_exit(); |
rg_log_exit(); |
| 1114 |
1149 |
rg_prof_end("git_update_tag"); |
rg_prof_end("git_update_tag"); |
| 1115 |
1150 |
} |
} |
| |
| ... |
... |
function rg_git_update_branch($db, $a) |
| 1145 |
1180 |
rg_git_fatal($a['refname'] . "\nNo rights to delete" |
rg_git_fatal($a['refname'] . "\nNo rights to delete" |
| 1146 |
1181 |
. " a branch."); |
. " a branch."); |
| 1147 |
1182 |
$history['history_category'] = REPO_CAT_GIT_BRANCH_DELETE; |
$history['history_category'] = REPO_CAT_GIT_BRANCH_DELETE; |
| 1148 |
|
$history['history_message'] = 'Reference ' . $a['refname'] . ' deleted.'; |
|
|
1183 |
|
$history['history_message'] = 'Reference ' . $a['refname'] |
|
1184 |
|
. ' deleted'; |
| 1149 |
1185 |
rg_repo_history_insert($db, $history); |
rg_repo_history_insert($db, $history); |
| 1150 |
1186 |
return; |
return; |
| 1151 |
1187 |
} |
} |
| |
| ... |
... |
function rg_git_update_branch($db, $a) |
| 1243 |
1279 |
$mr = "refs/mr/" |
$mr = "refs/mr/" |
| 1244 |
1280 |
. preg_replace('/refs\/heads\//', '', $a['refname']) |
. preg_replace('/refs\/heads\//', '', $a['refname']) |
| 1245 |
1281 |
. "_" . preg_replace('/rg_/', '', $a['namespace']); |
. "_" . preg_replace('/rg_/', '', $a['namespace']); |
| 1246 |
|
$r = rg_git_update_ref($mr, "", $a['new_rev'], "mr"); |
|
|
1282 |
|
$reason = $a['login_username'] . ' pushed a merge request' |
|
1283 |
|
. ' for ref ' . $a['refname'] |
|
1284 |
|
. ' into namespace ' . $a['namespace']; |
|
1285 |
|
$r = rg_git_update_ref($mr, "", $a['new_rev'], $reason); |
| 1247 |
1286 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
| 1248 |
1287 |
rg_log("Cannot update-ref: " . rg_git_error()); |
rg_log("Cannot update-ref: " . rg_git_error()); |
| 1249 |
1288 |
rg_git_fatal($a['refname'] . ": Cannot set refs/mr/." |
rg_git_fatal($a['refname'] . ": Cannot set refs/mr/." |
| 1250 |
1289 |
. " Try again later."); |
. " Try again later."); |
| 1251 |
1290 |
} |
} |
|
1291 |
|
// TODO: here or inside below function we should record |
|
1292 |
|
// a hisotry event that an anon push was done. |
| 1252 |
1293 |
$r = rg_mr_queue_add($a['repo_id'], $a['namespace'], |
$r = rg_mr_queue_add($a['repo_id'], $a['namespace'], |
| 1253 |
1294 |
$a['old_rev'], $a['new_rev'], $a['refname'], $a['ip']); |
$a['old_rev'], $a['new_rev'], $a['refname'], $a['ip']); |
| 1254 |
1295 |
if ($r !== TRUE) |
if ($r !== TRUE) |
| |
| ... |
... |
function rg_git_update_branch($db, $a) |
| 1256 |
1297 |
$_x = array(); |
$_x = array(); |
| 1257 |
1298 |
$msg = rg_template("msg/push_merge_request.txt", $_x); |
$msg = rg_template("msg/push_merge_request.txt", $_x); |
| 1258 |
1299 |
rg_git_info($a['refname'] . "\n" . $msg); |
rg_git_info($a['refname'] . "\n" . $msg); |
|
1300 |
|
|
|
1301 |
|
$history['history_category'] = REPO_CAT_GIT_BRANCH_ANON_PUSH; |
|
1302 |
|
$history['history_message'] = 'Anonymous push to ref ' |
|
1303 |
|
. $a['refname']; |
|
1304 |
|
|
|
1305 |
|
// TODO: we shoult notify by e-mail that a merge request is |
|
1306 |
|
// waiting. |
| 1259 |
1307 |
} else { |
} else { |
| 1260 |
1308 |
rg_log("We are allowed to push."); |
rg_log("We are allowed to push."); |
| 1261 |
1309 |
|
|
| |
| ... |
... |
function rg_git_update_branch($db, $a) |
| 1263 |
1311 |
// Not clear when we do not have a namespace. |
// Not clear when we do not have a namespace. |
| 1264 |
1312 |
if (!empty($a['namespace'])) { |
if (!empty($a['namespace'])) { |
| 1265 |
1313 |
// Update the main namespace |
// Update the main namespace |
|
1314 |
|
$reason = $a['login_username'] |
|
1315 |
|
. ' pushed ref ' . $a['refname']; |
| 1266 |
1316 |
$r = rg_git_update_ref($a['refname'], $a['old_rev'], |
$r = rg_git_update_ref($a['refname'], $a['old_rev'], |
| 1267 |
|
$a['new_rev'], "push"); |
|
|
1317 |
|
$a['new_rev'], $reason); |
| 1268 |
1318 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
| 1269 |
1319 |
rg_git_fatal($a['refname'] . "\nCannot update ref (" |
rg_git_fatal($a['refname'] . "\nCannot update ref (" |
| 1270 |
1320 |
. rg_git_error() . ")"); |
. rg_git_error() . ")"); |
| |
| ... |
... |
function rg_git_update_branch($db, $a) |
| 1275 |
1325 |
|
|
| 1276 |
1326 |
if (strcmp($a['old_rev'], $rg_git_zero) == 0) { |
if (strcmp($a['old_rev'], $rg_git_zero) == 0) { |
| 1277 |
1327 |
$history['history_category'] = REPO_CAT_GIT_BRANCH_CREATE; |
$history['history_category'] = REPO_CAT_GIT_BRANCH_CREATE; |
| 1278 |
|
$history['history_message'] = 'Reference ' . $a['refname'] . ' created.'; |
|
|
1328 |
|
$history['history_message'] = 'Reference ' |
|
1329 |
|
. $a['refname'] . ' created' |
|
1330 |
|
. ' (' . $a['new_rev'] . ')'; |
| 1279 |
1331 |
} else { |
} else { |
| 1280 |
1332 |
$history['history_category'] = REPO_CAT_GIT_BRANCH_UPDATE; |
$history['history_category'] = REPO_CAT_GIT_BRANCH_UPDATE; |
| 1281 |
|
$history['history_message'] = 'Reference ' . $a['refname'] . ' updated from ' . $a['old_rev'] . ' to ' . $a['new_rev'] . '.'; |
|
|
1333 |
|
$history['history_message'] = 'Reference ' |
|
1334 |
|
. $a['refname'] . ' updated from ' |
|
1335 |
|
. $a['old_rev'] . ' to ' . $a['new_rev']; |
| 1282 |
1336 |
} |
} |
| 1283 |
|
rg_repo_history_insert($db, $history); |
|
| 1284 |
1337 |
} |
} |
|
1338 |
|
rg_repo_history_insert($db, $history); |
| 1285 |
1339 |
|
|
| 1286 |
1340 |
rg_prof_end("git_update_branch"); |
rg_prof_end("git_update_branch"); |
| 1287 |
1341 |
} |
} |