File Makefile.in changed (mode: 100644) (index 8e1c27b..9b340fc) |
... |
... |
clean: |
12 |
12 |
|
|
13 |
13 |
install: all |
install: all |
14 |
14 |
@mkdir -p $(I_USR_SHARE)/$(PRJ) |
@mkdir -p $(I_USR_SHARE)/$(PRJ) |
15 |
|
cp -vdr admin inc hooks root scripts $(I_USR_SHARE)/$(PRJ) |
|
|
15 |
|
cp -vdr admin inc hooks root scripts lang $(I_USR_SHARE)/$(PRJ) |
16 |
16 |
@mkdir -p $(I_ETC)/xinetd.d |
@mkdir -p $(I_ETC)/xinetd.d |
17 |
17 |
cp -vd --no-clobber samples/rg $(I_ETC)/xinetd.d/rocketgit |
cp -vd --no-clobber samples/rg $(I_ETC)/xinetd.d/rocketgit |
18 |
18 |
@mkdir -p $(I_ETC)/cron.d |
@mkdir -p $(I_ETC)/cron.d |
|
... |
... |
install: all |
30 |
30 |
@mkdir -p $(I_VAR_LOG)/$(PRJ)-web |
@mkdir -p $(I_VAR_LOG)/$(PRJ)-web |
31 |
31 |
@-chown apache:apache $(I_VAR_LOG)/$(PRJ)-web |
@-chown apache:apache $(I_VAR_LOG)/$(PRJ)-web |
32 |
32 |
@chmod 0700 $(I_VAR_LOG)/$(PRJ)-web |
@chmod 0700 $(I_VAR_LOG)/$(PRJ)-web |
33 |
|
@mkdir -p $(I_VAR_RUN)/$(PRJ) |
|
34 |
|
@-chown rocketgit:rocketgit $(I_VAR_RUN)/$(PRJ) |
|
|
33 |
|
@mkdir -p $(I_VAR_LIB)/$(PRJ) |
|
34 |
|
@-chown rocketgit:rocketgit $(I_VAR_LIB)/$(PRJ) |
|
35 |
|
@chmod 0700 $(I_VAR_LIB)/$(PRJ) |
File TODO changed (mode: 100644) (index 1cc86a5..e53f848) |
14 |
14 |
[ ] Deny any operation till schema update is done. |
[ ] Deny any operation till schema update is done. |
15 |
15 |
[ ] Test and fix update.php script. |
[ ] Test and fix update.php script. |
16 |
16 |
[ ] Check if rewinds are working as expected. |
[ ] Check if rewinds are working as expected. |
|
17 |
|
[ ] Add rg_mr_queue_process function and call it in cron.php or q.php. |
17 |
18 |
[ ] |
[ ] |
18 |
19 |
|
|
19 |
20 |
== Normal priority == |
== Normal priority == |
|
110 |
111 |
- A merge request that is approved in a MR queue will make it |
- A merge request that is approved in a MR queue will make it |
111 |
112 |
automatically to the specified queues. |
automatically to the specified queues. |
112 |
113 |
[ ] Use $rr['prefix'] |
[ ] Use $rr['prefix'] |
113 |
|
[ ] |
|
|
114 |
|
[ ] At push time we may generate some nice informative output (commits, last time when current user commited etc.) |
114 |
115 |
|
|
115 |
116 |
== Graphics == |
== Graphics == |
116 |
117 |
[ ] http://static.phpcloud.com/images/banner/phpcloudcom-spaceship-banner-970x404px.jpg |
[ ] http://static.phpcloud.com/images/banner/phpcloudcom-spaceship-banner-970x404px.jpg |
|
119 |
120 |
== Versus == |
== Versus == |
120 |
121 |
* http://www.wikivs.com/wiki/GitHub_vs_Gitorious |
* http://www.wikivs.com/wiki/GitHub_vs_Gitorious |
121 |
122 |
* http://unfuddle.com/about/tour/plans |
* http://unfuddle.com/about/tour/plans |
|
123 |
|
* bitbucket.org |
122 |
124 |
* |
* |
123 |
125 |
|
|
124 |
126 |
|
|
125 |
127 |
== To recheck == |
== To recheck == |
126 |
128 |
* http://techbase.kde.org/Projects/MovetoGit#Post_Update_hooks |
* http://techbase.kde.org/Projects/MovetoGit#Post_Update_hooks |
127 |
129 |
* |
* |
|
130 |
|
|
|
131 |
|
|
|
132 |
|
== Rights management - to be implemented == |
|
133 |
|
|
|
134 |
|
- A user is trying to push some commits in a branch B, for a file F |
|
135 |
|
- The set of rights may be: |
|
136 |
|
Branch File Rights |
|
137 |
|
B2 dir/*.png FPA |
|
138 |
|
* dir2 A |
|
139 |
|
* * F |
File duilder changed (mode: 100755) (index 081d1c2..a6e2825) |
... |
... |
USR_SHARE="/usr/share" |
325 |
325 |
USR_SHARE_DOC="/usr/share/doc/${PRJ}-${VER}" |
USR_SHARE_DOC="/usr/share/doc/${PRJ}-${VER}" |
326 |
326 |
SBIN="/usr/sbin" |
SBIN="/usr/sbin" |
327 |
327 |
VAR="/var" |
VAR="/var" |
|
328 |
|
VAR_LIB="/var/lib" |
328 |
329 |
|
|
329 |
330 |
while [ "${1}" != "" ]; do |
while [ "${1}" != "" ]; do |
330 |
331 |
VAR="`echo ${1} | cut -d'=' -f1`" |
VAR="`echo ${1} | cut -d'=' -f1`" |
|
... |
... |
while [ "${1}" != "" ]; do |
348 |
349 |
--localstatedir) |
--localstatedir) |
349 |
350 |
VAR="${VAL}" |
VAR="${VAL}" |
350 |
351 |
;; |
;; |
|
352 |
|
--sharedstatedir) |
|
353 |
|
VAR_LIB="${VAL}" |
|
354 |
|
;; |
351 |
355 |
--datadir) |
--datadir) |
352 |
356 |
USR_SHARE="${VAL}" |
USR_SHARE="${VAL}" |
353 |
357 |
;; |
;; |
|
... |
... |
echo "s#@USR_BIN@#${USR_BIN}#g" >> tmp.sed |
459 |
463 |
echo "s#@SBIN@#${SBIN}#g" >> tmp.sed |
echo "s#@SBIN@#${SBIN}#g" >> tmp.sed |
460 |
464 |
echo "s#@USR_SBIN@#${USR_SBIN}#g" >> tmp.sed |
echo "s#@USR_SBIN@#${USR_SBIN}#g" >> tmp.sed |
461 |
465 |
echo "s#@VAR@#${VAR}#g" >> tmp.sed |
echo "s#@VAR@#${VAR}#g" >> tmp.sed |
|
466 |
|
echo "s#@VAR_LIB@#${VAR_LIB}#g" >> tmp.sed |
462 |
467 |
echo "s#@VAR_LOG@#${VAR_LOG}#g" >> tmp.sed |
echo "s#@VAR_LOG@#${VAR_LOG}#g" >> tmp.sed |
463 |
468 |
echo "s#@VAR_RUN@#${VAR_RUN}#g" >> tmp.sed |
echo "s#@VAR_RUN@#${VAR_RUN}#g" >> tmp.sed |
464 |
469 |
echo "s#@USR_INCLUDE@#${USR_INCLUDE}#g" >> tmp.sed |
echo "s#@USR_INCLUDE@#${USR_INCLUDE}#g" >> tmp.sed |
|
... |
... |
if [ -r Makefile.in ]; then |
492 |
497 |
echo "export I_USR_LIB := \$(DESTDIR)${USR_LIB}" >> Makefile |
echo "export I_USR_LIB := \$(DESTDIR)${USR_LIB}" >> Makefile |
493 |
498 |
echo "export I_LIB := \$(DESTDIR)${USR_LIB}" >> Makefile |
echo "export I_LIB := \$(DESTDIR)${USR_LIB}" >> Makefile |
494 |
499 |
echo "export I_VAR := \$(DESTDIR)${VAR}" >> Makefile |
echo "export I_VAR := \$(DESTDIR)${VAR}" >> Makefile |
|
500 |
|
echo "export I_VAR_LIB := \$(DESTDIR)${VAR_LIB}" >> Makefile |
495 |
501 |
echo "export I_VAR_LOG := \$(DESTDIR)${VAR_LOG}" >> Makefile |
echo "export I_VAR_LOG := \$(DESTDIR)${VAR_LOG}" >> Makefile |
496 |
502 |
echo "export I_VAR_RUN := \$(DESTDIR)${VAR_RUN}" >> Makefile |
echo "export I_VAR_RUN := \$(DESTDIR)${VAR_RUN}" >> Makefile |
497 |
503 |
echo >> Makefile |
echo >> Makefile |
File hooks/pre-receive changed (mode: 100755) (index d7d3035..6de9178) |
... |
... |
require_once($INC . "/util.inc.php"); |
19 |
19 |
require_once($INC . "/log.inc.php"); |
require_once($INC . "/log.inc.php"); |
20 |
20 |
require_once($INC . "/sql.inc.php"); |
require_once($INC . "/sql.inc.php"); |
21 |
21 |
require_once($INC . "/repo.inc.php"); |
require_once($INC . "/repo.inc.php"); |
|
22 |
|
require_once($INC . "/mr.inc.php"); |
22 |
23 |
|
|
23 |
|
rg_log_set_file("/var/log/rocketgit/hook_pre-receive.log"); |
|
|
24 |
|
rg_log_set_file($rg_log_dir . "/hook_pre-receive.log"); |
24 |
25 |
|
|
25 |
26 |
$uid = @sprintf("%u", getenv("ROCKETGIT_UID")); |
$uid = @sprintf("%u", getenv("ROCKETGIT_UID")); |
26 |
|
$rights = getenv("ROCKETGIT_RIGHTS"); |
|
|
27 |
|
$rights = getenv("ROCKETGIT_REPO_RIGHTS"); |
|
28 |
|
$repo_id = getenv("ROCKETGIT_REPO_ID"); |
|
29 |
|
$ip = getenv("ROCKETGIT_IP"); |
|
30 |
|
$namespace = getenv("GIT_NAMESPACE"); |
27 |
31 |
|
|
28 |
|
rg_log("Start uid=$uid, rights=[$rights]..."); |
|
|
32 |
|
rg_log("Start uid=$uid repo_id=$repo_id rights=[$rights] namespace=$namespace" |
|
33 |
|
. " ip=$ip..."); |
29 |
34 |
rg_log("_SERVER: " . print_r($_SERVER, TRUE)); |
rg_log("_SERVER: " . print_r($_SERVER, TRUE)); |
30 |
35 |
|
|
31 |
36 |
umask(0022); |
umask(0022); |
|
... |
... |
while (($set = fgets($f))) { |
50 |
55 |
if (empty($refname) || empty($old_rev) || empty($new_rev)) |
if (empty($refname) || empty($old_rev) || empty($new_rev)) |
51 |
56 |
rg_fatal("Invalid parameters [$old_rev $new_rev $refname]!"); |
rg_fatal("Invalid parameters [$old_rev $new_rev $refname]!"); |
52 |
57 |
|
|
53 |
|
if (rg_rights_allow($rights, "P") === FALSE) |
|
54 |
|
rg_fatal("Push is not allowed in this repository!"); |
|
|
58 |
|
if (rg_rights_allow($rights, "P") === FALSE) { |
|
59 |
|
if (rg_rights_allow($rights, "H") === FALSE) { |
|
60 |
|
$msg = rg_template($rg_scripts . "/lang/en/push_not_allowed.txt", array()); |
|
61 |
|
rg_fatal($refname. ":\n" . $msg); |
|
62 |
|
} |
|
63 |
|
|
|
64 |
|
// anonymous push - create a merge request |
|
65 |
|
$r = rg_mr_queue_add($repo_id, $namespace, $old_rev, $new_rev, |
|
66 |
|
$refname, $ip); |
|
67 |
|
if ($r !== TRUE) |
|
68 |
|
rg_fatal($refname . ":\n" . rg_mr_error()); |
|
69 |
|
// TODO: Can we reject individual updates not all of them?! |
|
70 |
|
|
|
71 |
|
$msg = rg_template($rg_scripts . "/lang/en/push_merge_request.txt", array()); |
|
72 |
|
rg_info($refname . ":\n" . $msg); |
|
73 |
|
} |
55 |
74 |
} |
} |
56 |
75 |
fclose($f); |
fclose($f); |
57 |
76 |
|
|
File hooks/update changed (mode: 100755) (index 67b8cf3..30b2d1f) |
... |
... |
require_once($INC . "/log.inc.php"); |
20 |
20 |
require_once($INC . "/sql.inc.php"); |
require_once($INC . "/sql.inc.php"); |
21 |
21 |
require_once($INC . "/repo.inc.php"); |
require_once($INC . "/repo.inc.php"); |
22 |
22 |
|
|
23 |
|
rg_log_set_file("/var/log/rocketgit/hook_update.log"); |
|
|
23 |
|
rg_log_set_file($rg_log_dir . "/hook_update.log"); |
24 |
24 |
|
|
25 |
25 |
$uid = @sprintf("%u", getenv("ROCKETGIT_UID")); |
$uid = @sprintf("%u", getenv("ROCKETGIT_UID")); |
26 |
|
$rights = getenv("ROCKETGIT_RIGHTS"); |
|
|
26 |
|
$rights = getenv("ROCKETGIT_REPO_RIGHTS"); |
27 |
27 |
|
|
28 |
28 |
rg_log("Start uid=$uid, rights=[$rights]..."); |
rg_log("Start uid=$uid, rights=[$rights]..."); |
29 |
29 |
rg_log("_SERVER: " . print_r($_SERVER, TRUE)); |
rg_log("_SERVER: " . print_r($_SERVER, TRUE)); |
|
... |
... |
if (strcmp($new_rev_type, "commit") == 0) { |
77 |
77 |
if (strcmp($old_rev, $rg_git_zero) == 0) { |
if (strcmp($old_rev, $rg_git_zero) == 0) { |
78 |
78 |
rg_log("Creating a branch..."); |
rg_log("Creating a branch..."); |
79 |
79 |
if (!rg_rights_allow($rights, "C")) |
if (!rg_rights_allow($rights, "C")) |
80 |
|
rg_fatal("You have no rights to create a branch!"); |
|
|
80 |
|
rg_fatal("You have no rights to create a branch [$refname]!"); |
81 |
81 |
} else if (rg_git_rev_ok($new_rev . "^2")) { |
} else if (rg_git_rev_ok($new_rev . "^2")) { |
82 |
82 |
rg_log("Merge commit..."); |
rg_log("Merge commit..."); |
83 |
83 |
if (!rg_rights_allow($rights, "M")) |
if (!rg_rights_allow($rights, "M")) |
84 |
|
rg_fatal("You have no rights to push merge commits!"); |
|
|
84 |
|
rg_fatal("You have no rights to push merge commits in [$refname]!"); |
85 |
85 |
} else { |
} else { |
86 |
86 |
rg_log("Normal commit..."); |
rg_log("Normal commit..."); |
87 |
87 |
if (!rg_rights_allow($rights, "W")) { |
if (!rg_rights_allow($rights, "W")) { |
File inc/db/struct.inc.php changed (mode: 100644) (index 8bd1c99..7a4ce72) |
... |
... |
$rg_sql_struct[3]['other'] = array( |
81 |
81 |
"add organization field to user" => "ALTER TABLE users" |
"add organization field to user" => "ALTER TABLE users" |
82 |
82 |
. " ADD organization SMALLINT NOT NULL DEFAULT 0" |
. " ADD organization SMALLINT NOT NULL DEFAULT 0" |
83 |
83 |
); |
); |
|
84 |
|
|
|
85 |
|
$rg_sql_struct[4] = array(); |
|
86 |
|
$rg_sql_struct[4]['tables'] = array( |
|
87 |
|
"merge requests" => "CREATE TABLE merge_requests (" |
|
88 |
|
. "repo_id INT NOT NULL" |
|
89 |
|
. ", itime INT NOT NULL" |
|
90 |
|
. ", namespace TEXT NOT NULL" |
|
91 |
|
. ", refname TEXT NOT NULL" |
|
92 |
|
. ", old_rev CHAR(40) NOT NULL" |
|
93 |
|
. ", new_rev CHAR(40) NOT NULL" |
|
94 |
|
. ", done INT NOT NULL DEFAULT 0" |
|
95 |
|
. ", ip TEXT NOT NULL" |
|
96 |
|
. ")" |
|
97 |
|
); |
|
98 |
|
$rg_sql_struct[4]['other'] = array( |
|
99 |
|
"merge_request_index_repo_id" => "CREATE INDEX merge_requests_i_repo_id" |
|
100 |
|
. " ON merge_requests (repo_id)" |
|
101 |
|
); |
|
102 |
|
|
|
103 |
|
// This must be the last line |
84 |
104 |
$rg_sql_schema_ver = count($rg_sql_struct); |
$rg_sql_schema_ver = count($rg_sql_struct); |
85 |
105 |
|
|
86 |
106 |
|
|
File inc/git.inc.php changed (mode: 100644) (index 80497b2..fe0cf4a) |
... |
... |
function rg_git_init($dst) |
72 |
72 |
} |
} |
73 |
73 |
|
|
74 |
74 |
if (!file_exists($dst . "/rocketgit")) { |
if (!file_exists($dst . "/rocketgit")) { |
75 |
|
$cmd = "git init --bare '" . escapeshellcmd($dst) . "'"; |
|
|
75 |
|
$cmd = "git init --bare " . escapeshellarg($dst); |
76 |
76 |
$a = rg_exec($cmd); |
$a = rg_exec($cmd); |
77 |
77 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
78 |
78 |
rg_git_set_error("error on init " . $a['errmsg']); |
rg_git_set_error("error on init " . $a['errmsg']); |
|
... |
... |
function rg_git_clone($src, $dst) |
109 |
109 |
} |
} |
110 |
110 |
|
|
111 |
111 |
if (!file_exists($dst . "/rocketgit")) { |
if (!file_exists($dst . "/rocketgit")) { |
112 |
|
$cmd = "git clone --bare '" . escapeshellcmd($src) . "'" |
|
113 |
|
. " '" . escapeshellcmd($dst) . "'"; |
|
|
112 |
|
$cmd = "git clone --bare " . escapeshellarg($src) |
|
113 |
|
. " " . escapeshellarg($dst); |
114 |
114 |
$a = rg_exec($cmd); |
$a = rg_exec($cmd); |
115 |
115 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
116 |
116 |
rg_git_set_error("error on clone (" . $a['errmsg']); |
rg_git_set_error("error on clone (" . $a['errmsg']); |
File inc/mr.inc.php added (mode: 100644) (index 0000000..9d8f058) |
|
1 |
|
<?php |
|
2 |
|
// Merge requests |
|
3 |
|
|
|
4 |
|
require_once($INC . "/util.inc.php"); |
|
5 |
|
require_once($INC . "/sql.inc.php"); |
|
6 |
|
|
|
7 |
|
$rg_mr_queue = $rg_base . "/q_merge_requests"; |
|
8 |
|
|
|
9 |
|
$rg_mr_error = ""; |
|
10 |
|
|
|
11 |
|
function rg_mr_set_error($str) |
|
12 |
|
{ |
|
13 |
|
global $rg_mr_error; |
|
14 |
|
|
|
15 |
|
rg_log("\tError: $str"); |
|
16 |
|
$rg_mr_error = $str; |
|
17 |
|
} |
|
18 |
|
|
|
19 |
|
function rg_mr_error() |
|
20 |
|
{ |
|
21 |
|
global $rg_mr_error; |
|
22 |
|
return $rg_mr_error; |
|
23 |
|
} |
|
24 |
|
|
|
25 |
|
/* |
|
26 |
|
* Add a merge request to the queue |
|
27 |
|
* We should put it in a queue, with fsync; also, in cron, we must process it |
|
28 |
|
*/ |
|
29 |
|
function rg_mr_queue_add($repo_id, $namespace, $old_rev, $new_rev, $refname, $ip) |
|
30 |
|
{ |
|
31 |
|
global $rg_mr_queue; |
|
32 |
|
|
|
33 |
|
rg_log("rg_mr_create: repo_id=$repo_id namespace=$namespace" |
|
34 |
|
. " old_rev=$old_rev new_rev=$new_rev, refname=$refname" |
|
35 |
|
. " ip=$ip"); |
|
36 |
|
|
|
37 |
|
$c = "repo_id=$repo_id namespace=$namespace old_rev=$old_rev" |
|
38 |
|
. " new_rev=$new_rev refname=$refname ip=$ip"; |
|
39 |
|
|
|
40 |
|
$f = "mr-" . time() . "-" . rg_id(6); |
|
41 |
|
|
|
42 |
|
if (!file_exists($rg_mr_queue)) { |
|
43 |
|
if (@mkdir($rg_mr_queue, 0700) === FALSE) { |
|
44 |
|
rg_mr_set_error("cannot create merge requests queue"); |
|
45 |
|
return FALSE; |
|
46 |
|
} |
|
47 |
|
} |
|
48 |
|
|
|
49 |
|
if (@file_put_contents($rg_mr_queue . "/" . $f, $c) === FALSE) { |
|
50 |
|
rg_mr_set_error("internal error: cannot store merge request ($php_errormsg)"); |
|
51 |
|
return FALSE; |
|
52 |
|
} |
|
53 |
|
|
|
54 |
|
// TODO: fsync |
|
55 |
|
|
|
56 |
|
return TRUE; |
|
57 |
|
} |
|
58 |
|
|
|
59 |
|
/* |
|
60 |
|
* Add a merge request file to database |
|
61 |
|
*/ |
|
62 |
|
function rg_mr_create($db, $repo_id, $namespace, $old_rev, $new_rev, $refname, $ip) |
|
63 |
|
{ |
|
64 |
|
rg_log("rg_mr_create: repo_id=$repo_id namespace=$namespace" |
|
65 |
|
. " old_rev=$old_rev new_rev=$new_rev, refname=$refname" |
|
66 |
|
. " ip=$ip"); |
|
67 |
|
|
|
68 |
|
$now = time(); |
|
69 |
|
$sql = "INSERT INTO merge_requests (repo_id, itime, namespace" |
|
70 |
|
. ", refname, old_rev, new_rev, done, ip)" |
|
71 |
|
. " VALUES ($repo_id, $now, '$namespace'" |
|
72 |
|
. ", '$refname', '$old_rev', '$new_rev', 0, '$ip')"; |
|
73 |
|
$res = rg_sql_query($db, $sql); |
|
74 |
|
if ($res === FALSE) { |
|
75 |
|
rg_mr_set_error("Cannot insert merge request (" . rg_sql_error() . ")"); |
|
76 |
|
return FALSE; |
|
77 |
|
} |
|
78 |
|
|
|
79 |
|
rg_sql_free_result($res); |
|
80 |
|
|
|
81 |
|
return TRUE; |
|
82 |
|
} |
|
83 |
|
|
|
84 |
|
/* |
|
85 |
|
* Loads info from a merge request file |
|
86 |
|
*/ |
|
87 |
|
function rg_mr_queue_load_file($file) |
|
88 |
|
{ |
|
89 |
|
$ret = array(); |
|
90 |
|
$ret['ok'] = 0; |
|
91 |
|
|
|
92 |
|
$c = @file_get_contents($file); |
|
93 |
|
if ($c === FALSE) { |
|
94 |
|
rg_mr_set_error("cannot load a merge request from $file ($php_errormsg)"); |
|
95 |
|
return $ret; |
|
96 |
|
} |
|
97 |
|
|
|
98 |
|
$tokens = explode(" ", trim($c)); |
|
99 |
|
foreach ($tokens as $token) { |
|
100 |
|
$p = explode("=", $token); |
|
101 |
|
$ret[$p[0]] = $p[1]; |
|
102 |
|
} |
|
103 |
|
|
|
104 |
|
$ret['ok'] = 1; |
|
105 |
|
return $ret; |
|
106 |
|
} |
|
107 |
|
|
|
108 |
|
/* |
|
109 |
|
* Process merge requests queue |
|
110 |
|
*/ |
|
111 |
|
function rg_mr_queue_process($db) |
|
112 |
|
{ |
|
113 |
|
global $rg_mr_queue; |
|
114 |
|
|
|
115 |
|
rg_log("mr_queue_process..."); |
|
116 |
|
|
|
117 |
|
$ret = TRUE; |
|
118 |
|
$dir = @opendir($rg_mr_queue); |
|
119 |
|
if ($dir === FALSE) { |
|
120 |
|
rg_mr_set_error("Cannot open dir $rg_mr_queue ($php_errormsg)!"); |
|
121 |
|
return FALSE; |
|
122 |
|
} |
|
123 |
|
|
|
124 |
|
while (($file = readdir($dir))) { |
|
125 |
|
if (strncmp($file, "mr-", 3) != 0) |
|
126 |
|
continue; |
|
127 |
|
|
|
128 |
|
$path = $rg_mr_queue . "/" . $file; |
|
129 |
|
rg_log("\tLoading merge request from $path..."); |
|
130 |
|
$d = rg_mr_queue_load_file($path); |
|
131 |
|
if ($d['ok'] != 1) { |
|
132 |
|
$ret = FALSE; |
|
133 |
|
break; |
|
134 |
|
} |
|
135 |
|
|
|
136 |
|
$r = rg_mr_create($db, $d['repo_id'], $d['namespace'], |
|
137 |
|
$d['old_rev'], $d['new_rev'], $d['refname'], $d['ip']); |
|
138 |
|
if ($r != TRUE) { |
|
139 |
|
rename($path, $rg_mr_queue . "/BAD-" . $file); |
|
140 |
|
} else { |
|
141 |
|
if (@unlink($path) !== TRUE) |
|
142 |
|
rg_log("Warn: Cannot unlink file $path!"); |
|
143 |
|
} |
|
144 |
|
} |
|
145 |
|
closedir($dir); |
|
146 |
|
|
|
147 |
|
return $ret; |
|
148 |
|
} |
|
149 |
|
|
|
150 |
|
?> |
File inc/prof.inc.php changed (mode: 100644) (index 2aab39c..fbd591a) |
... |
... |
function rg_prof_end($label) |
37 |
37 |
global $rg_prof_state; |
global $rg_prof_state; |
38 |
38 |
global $rg_prof_main; |
global $rg_prof_main; |
39 |
39 |
|
|
40 |
|
if (!isset($rg_prof_tmp[$label])) |
|
|
40 |
|
if (!isset($rg_prof_tmp[$label])) { |
|
41 |
|
rg_log("ERROR: rg_prof_start was not called for label [$label]!"); |
41 |
42 |
return; |
return; |
|
43 |
|
} |
42 |
44 |
|
|
43 |
45 |
$start = $rg_prof_tmp[$label]; |
$start = $rg_prof_tmp[$label]; |
44 |
46 |
|
|
|
... |
... |
function rg_prof_end($label) |
48 |
50 |
$c['mem'] = memory_get_usage(); |
$c['mem'] = memory_get_usage(); |
49 |
51 |
$c['real_mem'] = memory_get_usage(TRUE); |
$c['real_mem'] = memory_get_usage(TRUE); |
50 |
52 |
|
|
51 |
|
// we remove what was before start |
|
|
53 |
|
// we substract what was before start |
52 |
54 |
foreach ($start as $key => $val) |
foreach ($start as $key => $val) |
53 |
55 |
$c[$key] -= $val; |
$c[$key] -= $val; |
54 |
56 |
|
|
|
... |
... |
function rg_prof_end($label) |
56 |
58 |
if (!isset($rg_prof_main[$label])) { |
if (!isset($rg_prof_main[$label])) { |
57 |
59 |
$rg_prof_main[$label] = $c; |
$rg_prof_main[$label] = $c; |
58 |
60 |
} else { |
} else { |
59 |
|
foreach ($c as $key => $val) |
|
60 |
|
$rg_prof_main[$label][$key] += $val; |
|
|
61 |
|
foreach ($c as $key => $val) { |
|
62 |
|
// we may have items that are present at "end" time |
|
63 |
|
// and not at "start" time |
|
64 |
|
if (!isset($rg_prof_main[$label][$key])) |
|
65 |
|
$rg_prof_main[$label][$key] = $val; |
|
66 |
|
else |
|
67 |
|
$rg_prof_main[$label][$key] += $val; |
|
68 |
|
} |
61 |
69 |
} |
} |
62 |
70 |
|
|
63 |
71 |
unset($rg_prof_tmp[$label]); |
unset($rg_prof_tmp[$label]); |
|
... |
... |
function rg_prof_get() |
70 |
78 |
return $rg_prof_main; |
return $rg_prof_main; |
71 |
79 |
} |
} |
72 |
80 |
|
|
73 |
|
function rg_prof_log() |
|
|
81 |
|
function rg_prof_log($cb) |
74 |
82 |
{ |
{ |
75 |
83 |
global $rg_prof_main; |
global $rg_prof_main; |
76 |
84 |
|
|
77 |
|
rg_log("prof_log"); |
|
78 |
|
|
|
79 |
85 |
foreach ($rg_prof_main as $label => $per_label) { |
foreach ($rg_prof_main as $label => $per_label) { |
80 |
86 |
$line = $label . ":"; |
$line = $label . ":"; |
81 |
87 |
|
|
|
... |
... |
function rg_prof_log() |
83 |
89 |
if ($v > 0) |
if ($v > 0) |
84 |
90 |
$line .= " $k=$v"; |
$line .= " $k=$v"; |
85 |
91 |
} |
} |
86 |
|
rg_log($line); |
|
|
92 |
|
$cb($line); |
87 |
93 |
} |
} |
88 |
94 |
} |
} |
89 |
95 |
|
|
File inc/user/repo-page.php changed (mode: 100644) (index 08f9218..5c1ef8c) |
... |
... |
$ri2 = $ri; |
29 |
29 |
$ri2['default_rights'] = implode(", ", rg_rights_text("repo", $ri['default_rights'])); |
$ri2['default_rights'] = implode(", ", rg_rights_text("repo", $ri['default_rights'])); |
30 |
30 |
$ri2['max_commit_size'] = $ri['max_commit_size'] == 0 ? "unlimited" : rg_1024($ri['max_commit_size']); |
$ri2['max_commit_size'] = $ri['max_commit_size'] == 0 ? "unlimited" : rg_1024($ri['max_commit_size']); |
31 |
31 |
$ri2['max_users'] = $ri['max_users'] == 0 ? "unlimited" : rg_1000($ri['max_users']); |
$ri2['max_users'] = $ri['max_users'] == 0 ? "unlimited" : rg_1000($ri['max_users']); |
32 |
|
$_home .= rg_template($THEME . "/repo/main.html", $ri2, $_more); |
|
|
32 |
|
$_home .= rg_template($THEME . "/repo/main.html", array_merge($ri2, $_more)); |
33 |
33 |
|
|
34 |
34 |
$repo_dir = rg_repo_name2base($rr) . $repo . ".git"; |
$repo_dir = rg_repo_name2base($rr) . $repo . ".git"; |
35 |
35 |
putenv("GIT_DIR=$repo_dir"); |
putenv("GIT_DIR=$repo_dir"); |
|
... |
... |
if (strcmp($subop, "tree") == 0) { |
49 |
49 |
"obj" => $obj, |
"obj" => $obj, |
50 |
50 |
"HTML:content" => rg_template_list($c) |
"HTML:content" => rg_template_list($c) |
51 |
51 |
); |
); |
52 |
|
$_home .= rg_template($THEME . "/repo/blob.html", $blob, $_more); |
|
|
52 |
|
$_home .= rg_template($THEME . "/repo/blob.html", array_merge($blob, $_more)); |
53 |
53 |
} else { // log |
} else { // log |
54 |
54 |
if (empty($paras[0])) { |
if (empty($paras[0])) { |
55 |
55 |
rg_log("Show full log"); |
rg_log("Show full log"); |
File inc/util.inc.php changed (mode: 100644) (index cbc80be..7b83490) |
1 |
1 |
<?php |
<?php |
|
2 |
|
require_once($INC . "/prof.inc.php"); |
2 |
3 |
|
|
3 |
4 |
function rg_1024($v) |
function rg_1024($v) |
4 |
5 |
{ |
{ |
|
... |
... |
function rg_id($len) |
28 |
29 |
{ |
{ |
29 |
30 |
$id = ""; |
$id = ""; |
30 |
31 |
|
|
|
32 |
|
rg_prof_start("urandom"); |
31 |
33 |
$f = @fopen("/dev/urandom", "r"); |
$f = @fopen("/dev/urandom", "r"); |
32 |
34 |
if ($f !== NULL) { |
if ($f !== NULL) { |
33 |
35 |
$buf = @fread($f, 128); |
$buf = @fread($f, 128); |
|
... |
... |
function rg_id($len) |
39 |
41 |
if (empty($id)) |
if (empty($id)) |
40 |
42 |
$id = sha1(mt_rand() . serialize($_REQUEST)); |
$id = sha1(mt_rand() . serialize($_REQUEST)); |
41 |
43 |
|
|
|
44 |
|
rg_prof_end("urandom"); |
42 |
45 |
return substr($id, 0, $len); |
return substr($id, 0, $len); |
43 |
46 |
} |
} |
44 |
47 |
|
|
|
... |
... |
$_lock = FALSE; |
46 |
49 |
function rg_lock_or_exit($file) |
function rg_lock_or_exit($file) |
47 |
50 |
{ |
{ |
48 |
51 |
global $_lock; |
global $_lock; |
|
52 |
|
global $rg_lock_dir; |
|
53 |
|
|
|
54 |
|
if (!isset($rg_lock_dir)) |
|
55 |
|
$rg_lock_dir = "/var/lib/rocketgit"; |
49 |
56 |
|
|
50 |
57 |
if ($_lock !== FALSE) { |
if ($_lock !== FALSE) { |
51 |
58 |
rg_log("\tYou already have a lock on $file! Bad!"); |
rg_log("\tYou already have a lock on $file! Bad!"); |
52 |
59 |
exit(1); |
exit(1); |
53 |
60 |
} |
} |
54 |
61 |
|
|
55 |
|
$_lock = @fopen($file, "w"); |
|
|
62 |
|
$_lock = @fopen($rg_lock_dir . "/" . $file, "w"); |
56 |
63 |
if ($_lock === FALSE) { |
if ($_lock === FALSE) { |
57 |
|
rg_log("\tCannot open $file!"); |
|
|
64 |
|
rg_log("\tCannot open $rg_lock_dir/$file!"); |
58 |
65 |
exit(1); |
exit(1); |
59 |
66 |
} |
} |
60 |
67 |
|
|
|
... |
... |
function rg_rmdir($dir) |
216 |
223 |
|
|
217 |
224 |
function rg_fatal($msg) |
function rg_fatal($msg) |
218 |
225 |
{ |
{ |
219 |
|
rg_log("FATAL: $msg"); |
|
220 |
226 |
echo "==========\n"; |
echo "==========\n"; |
221 |
|
echo "RocketGit: $msg\n"; |
|
|
227 |
|
$x = explode("\n", trim($msg)); |
|
228 |
|
foreach ($x as $line) { |
|
229 |
|
rg_log("FATAL: $line"); |
|
230 |
|
echo "RocketGit: $line\n"; |
|
231 |
|
} |
222 |
232 |
echo "==========\n"; |
echo "==========\n"; |
223 |
233 |
exit(1); |
exit(1); |
224 |
234 |
} |
} |
225 |
235 |
|
|
|
236 |
|
function rg_info($msg) |
|
237 |
|
{ |
|
238 |
|
echo "==========\n"; |
|
239 |
|
$x = explode("\n", trim($msg)); |
|
240 |
|
foreach ($x as $line) { |
|
241 |
|
rg_log("INFO: $line"); |
|
242 |
|
echo "RocketGit: $line\n"; |
|
243 |
|
} |
|
244 |
|
echo "==========\n"; |
|
245 |
|
} |
|
246 |
|
|
226 |
247 |
/* |
/* |
227 |
248 |
* Generates a menu |
* Generates a menu |
228 |
249 |
*/ |
*/ |
|
... |
... |
function rg_template_table($dir, $data, $more) |
336 |
357 |
return $head . $body . $foot; |
return $head . $body . $foot; |
337 |
358 |
} |
} |
338 |
359 |
|
|
339 |
|
function rg_template($file, $data, $more) |
|
|
360 |
|
function rg_template($file, $data) |
340 |
361 |
{ |
{ |
341 |
362 |
rg_log("template($file)"); |
rg_log("template($file)"); |
342 |
363 |
|
|
|
... |
... |
function rg_template($file, $data, $more) |
347 |
368 |
$what = array(); |
$what = array(); |
348 |
369 |
$values = array(); |
$values = array(); |
349 |
370 |
|
|
350 |
|
rg_prepare_replace($more, $what, $values); |
|
351 |
371 |
rg_prepare_replace($data, $what, $values); |
rg_prepare_replace($data, $what, $values); |
352 |
372 |
|
|
353 |
373 |
return preg_replace($what, $values, $body); |
return preg_replace($what, $values, $body); |
|
... |
... |
function rg_template_list($c) |
380 |
400 |
function rg_exec($cmd) |
function rg_exec($cmd) |
381 |
401 |
{ |
{ |
382 |
402 |
rg_log("exec($cmd)"); |
rg_log("exec($cmd)"); |
|
403 |
|
rg_prof_start("exec($cmd)"); |
383 |
404 |
|
|
384 |
405 |
$ret = array(); |
$ret = array(); |
385 |
406 |
$ret['ok'] = 0; |
$ret['ok'] = 0; |
|
... |
... |
function rg_exec($cmd) |
410 |
431 |
|
|
411 |
432 |
rg_log("exec returned " . $ret['errmsg']); |
rg_log("exec returned " . $ret['errmsg']); |
412 |
433 |
|
|
|
434 |
|
rg_prof_end("exec($cmd)"); |
413 |
435 |
return $ret; |
return $ret; |
414 |
436 |
} |
} |
415 |
437 |
|
|
File rocketgit.spec.in changed (mode: 100644) (index 694f685..de959fd) |
... |
... |
rm -rf ${RPM_BUILD_ROOT} |
57 |
57 |
%config(noreplace) /etc/cron.d/rocketgit |
%config(noreplace) /etc/cron.d/rocketgit |
58 |
58 |
%config(noreplace) /etc/xinetd.d/rocketgit |
%config(noreplace) /etc/xinetd.d/rocketgit |
59 |
59 |
%config(noreplace) /etc/httpd/conf.d/rocketgit.conf |
%config(noreplace) /etc/httpd/conf.d/rocketgit.conf |
60 |
|
%attr(0700,rocketgit,rocketgit) %dir /var/run/@PRJ@ |
|
61 |
60 |
%attr(0700,rocketgit,rocketgit) %dir /var/log/@PRJ@ |
%attr(0700,rocketgit,rocketgit) %dir /var/log/@PRJ@ |
62 |
61 |
%attr(0700,apache,apache) %dir /var/log/@PRJ@-web |
%attr(0700,apache,apache) %dir /var/log/@PRJ@-web |
|
62 |
|
%attr(0700,rocketgit,rocketgit) %dir /var/lib/@PRJ@ |
63 |
63 |
%config(noreplace) /etc/logrotate.d/rocketgit |
%config(noreplace) /etc/logrotate.d/rocketgit |
64 |
64 |
|
|
65 |
65 |
%changelog |
%changelog |
File root/index.php changed (mode: 100644) (index 8cf84a1..92e5891) |
... |
... |
include_once($INC . "/prof.inc.php"); |
21 |
21 |
|
|
22 |
22 |
rg_prof_start("MAIN"); |
rg_prof_start("MAIN"); |
23 |
23 |
|
|
24 |
|
rg_log_set_file("/var/log/rocketgit-web/main.log"); |
|
|
24 |
|
rg_log_set_file($rg_web_log_dir . "/main.log"); |
25 |
25 |
|
|
26 |
26 |
// Init variables |
// Init variables |
27 |
27 |
$op = ""; $subop = ""; $subsubop = ""; $cop = ""; |
$op = ""; $subop = ""; $subsubop = ""; $cop = ""; |
|
... |
... |
rg_log("paras: " . implode("|", $paras)); |
93 |
93 |
|
|
94 |
94 |
// database connection |
// database connection |
95 |
95 |
$db = rg_sql_open($rg_sql); |
$db = rg_sql_open($rg_sql); |
96 |
|
if ($db === FALSE) |
|
|
96 |
|
if ($db === FALSE) { |
|
97 |
|
// TODO: Retry? |
97 |
98 |
die("Cannot open database!"); |
die("Cannot open database!"); |
|
99 |
|
} |
98 |
100 |
|
|
99 |
101 |
rg_user_login_by_sid($db, $sid, $rg_ui); |
rg_user_login_by_sid($db, $sid, $rg_ui); |
100 |
102 |
rg_log("After login_by_sid, rg_ui=" . print_r($rg_ui, TRUE)); |
rg_log("After login_by_sid, rg_ui=" . print_r($rg_ui, TRUE)); |
|
... |
... |
rg_prof_end("MAIN"); |
152 |
154 |
|
|
153 |
155 |
include($THEME . "/index.php"); |
include($THEME . "/index.php"); |
154 |
156 |
|
|
155 |
|
rg_prof_log(); |
|
|
157 |
|
rg_prof_log("rg_log"); |
156 |
158 |
?> |
?> |
File scripts/cron.php changed (mode: 100644) (index 621be94..6d7eb90) |
... |
... |
require_once($INC . "/sql.inc.php"); |
13 |
13 |
require_once($INC . "/repo.inc.php"); |
require_once($INC . "/repo.inc.php"); |
14 |
14 |
require_once($INC . "/keys.inc.php"); |
require_once($INC . "/keys.inc.php"); |
15 |
15 |
|
|
16 |
|
rg_log_set_file("/var/log/rocketgit/cron.log"); |
|
|
16 |
|
rg_log_set_file($rg_log_dir . "/cron.log"); |
17 |
17 |
|
|
18 |
18 |
// locking |
// locking |
19 |
|
$lock = "/var/run/rocketgit/cron.lock"; |
|
20 |
|
rg_lock_or_exit($lock); |
|
|
19 |
|
rg_lock_or_exit("cron.lock"); |
21 |
20 |
|
|
22 |
21 |
rg_log("Start..."); |
rg_log("Start..."); |
23 |
22 |
|
|
|
... |
... |
if (date("H") == 23) { |
109 |
108 |
|
|
110 |
109 |
// This has to be the last thing that touches the database |
// This has to be the last thing that touches the database |
111 |
110 |
if (date("H") == 3) { |
if (date("H") == 3) { |
112 |
|
rg_log("Run VACUUM on database..."); |
|
113 |
|
$sql = "VACUUM"; |
|
114 |
|
$res = rg_sql_query($db, $sql); |
|
115 |
|
rg_sql_free_result($res); |
|
116 |
|
|
|
117 |
111 |
rg_log("Run ANALYZE on database..."); |
rg_log("Run ANALYZE on database..."); |
118 |
112 |
$sql = "ANALYZE"; |
$sql = "ANALYZE"; |
119 |
113 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
File scripts/q.php changed (mode: 100644) (index da01acd..c3dbddd) |
1 |
1 |
<?php |
<?php |
2 |
2 |
// This is called by cron, and is persistent. |
// This is called by cron, and is persistent. |
3 |
|
// It takes care of repository init/clone |
|
|
3 |
|
// It takes care of repository init/clone, merge request to db etc. |
4 |
4 |
error_reporting(E_ALL); |
error_reporting(E_ALL); |
5 |
5 |
ini_set("track_errors", "On"); |
ini_set("track_errors", "On"); |
6 |
6 |
|
|
|
... |
... |
require_once($INC . "/log.inc.php"); |
14 |
14 |
require_once($INC . "/sql.inc.php"); |
require_once($INC . "/sql.inc.php"); |
15 |
15 |
require_once($INC . "/repo.inc.php"); |
require_once($INC . "/repo.inc.php"); |
16 |
16 |
require_once($INC . "/prof.inc.php"); |
require_once($INC . "/prof.inc.php"); |
|
17 |
|
require_once($INC . "/mr.inc.php"); |
17 |
18 |
|
|
18 |
19 |
rg_prof_start("MAIN"); |
rg_prof_start("MAIN"); |
19 |
20 |
|
|
20 |
|
rg_log_set_file("/var/log/rocketgit/q.log"); |
|
|
21 |
|
rg_log_set_file($rg_log_dir . "/q.log"); |
21 |
22 |
|
|
22 |
23 |
// locking |
// locking |
23 |
|
$lock = "/var/run/rocketgit/q.lock"; |
|
24 |
|
rg_lock_or_exit($lock); |
|
|
24 |
|
rg_lock_or_exit("q.lock"); |
25 |
25 |
|
|
26 |
26 |
rg_log("Start..."); |
rg_log("Start..."); |
27 |
27 |
|
|
|
... |
... |
$original_mtime = filemtime(__FILE__); |
36 |
36 |
|
|
37 |
37 |
// Check our mtime so we can upgrade the software and this script will restart. |
// Check our mtime so we can upgrade the software and this script will restart. |
38 |
38 |
while (TRUE) { |
while (TRUE) { |
|
39 |
|
clearstatcache(); |
39 |
40 |
$mtime = filemtime(__FILE__); |
$mtime = filemtime(__FILE__); |
|
41 |
|
rg_log("mtime=$mtime, original_mtime=$original_mtime"); |
40 |
42 |
if ($mtime != $original_mtime) { |
if ($mtime != $original_mtime) { |
41 |
43 |
rg_log("File changed. Exiting..."); |
rg_log("File changed. Exiting..."); |
42 |
44 |
break; |
break; |
|
... |
... |
while (TRUE) { |
50 |
52 |
continue; |
continue; |
51 |
53 |
} |
} |
52 |
54 |
|
|
|
55 |
|
rg_mr_queue_process($db); |
|
56 |
|
|
53 |
57 |
rg_log("Check to create not-yet-created repos..."); |
rg_log("Check to create not-yet-created repos..."); |
54 |
58 |
// Ordered by master to create masters first |
// Ordered by master to create masters first |
55 |
59 |
$sql = "SELECT a.repo_id, a.master, a.name, b.username, b.organization" |
$sql = "SELECT a.repo_id, a.master, a.name, b.username, b.organization" |
|
... |
... |
while (TRUE) { |
115 |
119 |
} |
} |
116 |
120 |
|
|
117 |
121 |
rg_prof_end("MAIN"); |
rg_prof_end("MAIN"); |
118 |
|
rg_prof_log(); |
|
|
122 |
|
rg_prof_log("rg_log"); |
119 |
123 |
?> |
?> |
File scripts/remote.php changed (mode: 100644) (index 8095947..c17efa5) |
... |
... |
require_once($INC . "/log.inc.php"); |
13 |
13 |
require_once($INC . "/sql.inc.php"); |
require_once($INC . "/sql.inc.php"); |
14 |
14 |
require_once($INC . "/repo.inc.php"); |
require_once($INC . "/repo.inc.php"); |
15 |
15 |
|
|
16 |
|
rg_log_set_file("/var/log/rocketgit/remote.log"); |
|
|
16 |
|
rg_log_set_file($rg_log_dir . "/remote.log"); |
17 |
17 |
|
|
18 |
18 |
function fatal($str) |
function fatal($str) |
19 |
19 |
{ |
{ |
|
... |
... |
if (isset($_SERVER['SSH_CONNECTION'])) { |
53 |
53 |
$cmd_repo = trim(@$_SERVER['SSH_ORIGINAL_COMMAND']); |
$cmd_repo = trim(@$_SERVER['SSH_ORIGINAL_COMMAND']); |
54 |
54 |
if (empty($cmd_repo)) |
if (empty($cmd_repo)) |
55 |
55 |
fatal("No SSH_ORIGINAL_COMMAND provided!"); |
fatal("No SSH_ORIGINAL_COMMAND provided!"); |
|
56 |
|
|
|
57 |
|
$ssh_client = getenv("SSH_CLIENT"); |
|
58 |
|
$_t = explode(" ", $ssh_client); |
|
59 |
|
$ip = $_t[0]; |
56 |
60 |
} else { |
} else { |
57 |
61 |
rg_log("git-daemon connection..."); |
rg_log("git-daemon connection..."); |
58 |
62 |
$access_type = 2; |
$access_type = 2; |
|
... |
... |
if (isset($_SERVER['SSH_CONNECTION'])) { |
80 |
84 |
$v = explode("\0", $line); |
$v = explode("\0", $line); |
81 |
85 |
$cmd_repo = trim($v[0]); |
$cmd_repo = trim($v[0]); |
82 |
86 |
$host = trim(substr($v[1], 5)); |
$host = trim(substr($v[1], 5)); |
|
87 |
|
|
|
88 |
|
$ip = getenv("REMOTE_HOST"); |
83 |
89 |
} |
} |
84 |
90 |
|
|
85 |
91 |
// extract command and compute permissions |
// extract command and compute permissions |
|
... |
... |
if (rg_rights_allow($rights, $needed_rights) === FALSE) |
146 |
152 |
|
|
147 |
153 |
// TODO: limit time and/or cpu |
// TODO: limit time and/or cpu |
148 |
154 |
|
|
|
155 |
|
// TODO: limit cpuset |
|
156 |
|
|
|
157 |
|
// TODO: limit io |
|
158 |
|
|
149 |
159 |
$repo_base = rg_repo_name2base($rr); |
$repo_base = rg_repo_name2base($rr); |
150 |
160 |
$repo_path = $repo_base . $repo . ".git"; |
$repo_path = $repo_base . $repo . ".git"; |
151 |
161 |
rg_log("repo_path=$repo_path."); |
rg_log("repo_path=$repo_path."); |
|
... |
... |
if (($push == 1) && rg_repo_over_limit($ri)) |
157 |
167 |
|
|
158 |
168 |
// Put in environment all we need |
// Put in environment all we need |
159 |
169 |
putenv("ROCKETGIT_UID=" . $uid); |
putenv("ROCKETGIT_UID=" . $uid); |
160 |
|
putenv("ROCKETGIT_RIGHTS=" . $rights); |
|
|
170 |
|
putenv("ROCKETGIT_REPO_ID=" . $ri['repo_id']); |
|
171 |
|
putenv("ROCKETGIT_REPO_RIGHTS=" . $rights); |
|
172 |
|
putenv("ROCKETGIT_IP=$ip"); |
|
173 |
|
if ($push == 1) { |
|
174 |
|
$namespace = "rg_" . rg_id(8); |
|
175 |
|
rg_log("namespace is $namespace."); |
|
176 |
|
putenv("GIT_NAMESPACE=" . $namespace); |
|
177 |
|
} |
161 |
178 |
|
|
162 |
|
$run = "git-shell -c \"" . $cmd . " '" . escapeshellcmd($repo_path) . "'\""; |
|
|
179 |
|
$run = "git-shell -c \"" . $cmd . " " . escapeshellarg($repo_path) . "\""; |
163 |
180 |
rg_log("Running [$run]..."); |
rg_log("Running [$run]..."); |
164 |
181 |
passthru($run, $ret); |
passthru($run, $ret); |
165 |
182 |
rg_log("[$run] returned $ret."); |
rg_log("[$run] returned $ret."); |
File tests/hook_pre-receive.sh changed (mode: 100755) (index 29522c7..8090618) |
... |
... |
mkdir hook_pre-receive_dest.git |
6 |
6 |
cd hook_pre-receive_dest.git |
cd hook_pre-receive_dest.git |
7 |
7 |
git init --bare |
git init --bare |
8 |
8 |
) |
) |
9 |
|
cp ../hooks/pre-receive hook_pre-receive_dest.git/hooks/ |
|
|
9 |
|
cp ../hooks/* hook_pre-receive_dest.git/hooks/ |
10 |
10 |
|
|
11 |
11 |
git clone hook_pre-receive_dest.git hook_pre-receive_src.git |
git clone hook_pre-receive_dest.git hook_pre-receive_src.git |
12 |
12 |
|
|
13 |
13 |
cd hook_pre-receive_src.git |
cd hook_pre-receive_src.git |
14 |
14 |
|
|
|
15 |
|
export ROCKETGIT_REPO_ID=2000000000 |
|
16 |
|
export ROCKETGIT_IP="IP" |
|
17 |
|
|
15 |
18 |
echo "=== Testing push without rights..." |
echo "=== Testing push without rights..." |
16 |
19 |
echo "aaa" > a |
echo "aaa" > a |
17 |
20 |
git add a |
git add a |
|
... |
... |
if [ "${?}" != "1" ]; then |
22 |
25 |
exit 1 |
exit 1 |
23 |
26 |
fi |
fi |
24 |
27 |
echo "=== Testing push with rights..." |
echo "=== Testing push with rights..." |
25 |
|
export ROCKETGIT_RIGHTS="P" |
|
|
28 |
|
export ROCKETGIT_REPO_RIGHTS="CP" |
26 |
29 |
git push origin master |
git push origin master |
27 |
30 |
if [ "${?}" != "0" ]; then |
if [ "${?}" != "0" ]; then |
28 |
31 |
echo "Should work!" |
echo "Should work!" |
29 |
32 |
exit 1 |
exit 1 |
30 |
33 |
fi |
fi |
31 |
34 |
|
|
|
35 |
|
echo "=== Testing anon push without rights..." |
|
36 |
|
export ROCKETGIT_REPO_RIGHTS="C" |
|
37 |
|
echo "bbb" > a |
|
38 |
|
git add a |
|
39 |
|
git commit -m "b" a |
|
40 |
|
git push origin master |
|
41 |
|
if [ "${?}" = "0" ]; then |
|
42 |
|
echo "Should not work!" |
|
43 |
|
exit 1 |
|
44 |
|
fi |
|
45 |
|
|
|
46 |
|
echo "=== Testing anon push with rights..." |
|
47 |
|
export ROCKETGIT_REPO_RIGHTS="CH" |
|
48 |
|
export GIT_NAMESPACE="abcdefgh" # we have to set it manually |
|
49 |
|
git push origin master |
|
50 |
|
if [ "${?}" != "0" ]; then |
|
51 |
|
echo "Should work!" |
|
52 |
|
exit 1 |
|
53 |
|
fi |
|
54 |
|
# TODO: we should not allow force pushes on anon branches |
32 |
55 |
|
|
33 |
56 |
cd .. |
cd .. |
34 |
|
echo "Rights=${ROCKETGIT_RIGHTS}." |
|
35 |
57 |
|
|
36 |
58 |
rm -rf hook_pre-receive_*.git |
rm -rf hook_pre-receive_*.git |
37 |
59 |
|
|
File tests/hook_update.sh changed (mode: 100755) (index 5341187..74f5d45) |
... |
... |
if [ "${?}" != "1" ]; then |
24 |
24 |
exit 1 |
exit 1 |
25 |
25 |
fi |
fi |
26 |
26 |
echo "=== Testing push with rights..." |
echo "=== Testing push with rights..." |
27 |
|
export ROCKETGIT_RIGHTS="C" |
|
|
27 |
|
export ROCKETGIT_REPO_RIGHTS="C" |
28 |
28 |
git push origin master |
git push origin master |
29 |
29 |
if [ "${?}" != "0" ]; then |
if [ "${?}" != "0" ]; then |
30 |
30 |
echo "Should work!" |
echo "Should work!" |
|
... |
... |
if [ "${?}" != "1" ]; then |
41 |
41 |
exit 1 |
exit 1 |
42 |
42 |
fi |
fi |
43 |
43 |
echo "=== Testing not fast-forward with rights..." |
echo "=== Testing not fast-forward with rights..." |
44 |
|
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}O" |
|
|
44 |
|
export ROCKETGIT_REPO_RIGHTS="${ROCKETGIT_REPO_RIGHTS}O" |
45 |
45 |
cd hook_update_src.git |
cd hook_update_src.git |
46 |
46 |
git push --force origin master |
git push --force origin master |
47 |
47 |
if [ "${?}" != "0" ]; then |
if [ "${?}" != "0" ]; then |
|
... |
... |
if [ "${?}" != "1" ]; then |
57 |
57 |
exit 1 |
exit 1 |
58 |
58 |
fi |
fi |
59 |
59 |
echo "=== Testing un-annotated tag creation with rights..." |
echo "=== Testing un-annotated tag creation with rights..." |
60 |
|
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}Y" |
|
|
60 |
|
export ROCKETGIT_REPO_RIGHTS="${ROCKETGIT_REPO_RIGHTS}Y" |
61 |
61 |
git push --tags origin |
git push --tags origin |
62 |
62 |
if [ "${?}" != "0" ]; then |
if [ "${?}" != "0" ]; then |
63 |
63 |
echo "Should work!" |
echo "Should work!" |
|
... |
... |
if [ "${?}" != "1" ]; then |
73 |
73 |
exit 1 |
exit 1 |
74 |
74 |
fi |
fi |
75 |
75 |
echo "=== Testing un-annotated tag modify with rights..." |
echo "=== Testing un-annotated tag modify with rights..." |
76 |
|
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}U" |
|
|
76 |
|
export ROCKETGIT_REPO_RIGHTS="${ROCKETGIT_REPO_RIGHTS}U" |
77 |
77 |
git push --force --tags origin |
git push --force --tags origin |
78 |
78 |
if [ "${?}" != "0" ]; then |
if [ "${?}" != "0" ]; then |
79 |
79 |
echo "Should work!" |
echo "Should work!" |
|
... |
... |
if [ "${?}" != "1" ]; then |
88 |
88 |
exit 1 |
exit 1 |
89 |
89 |
fi |
fi |
90 |
90 |
echo "=== Testing un-annotated tag deletion with rights..." |
echo "=== Testing un-annotated tag deletion with rights..." |
91 |
|
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}u" |
|
|
91 |
|
export ROCKETGIT_REPO_RIGHTS="${ROCKETGIT_REPO_RIGHTS}u" |
92 |
92 |
git push origin :refs/tags/tag1 |
git push origin :refs/tags/tag1 |
93 |
93 |
if [ "${?}" != "0" ]; then |
if [ "${?}" != "0" ]; then |
94 |
94 |
echo "Should work!" |
echo "Should work!" |
|
... |
... |
if [ "${?}" != "1" ]; then |
109 |
109 |
exit 1 |
exit 1 |
110 |
110 |
fi |
fi |
111 |
111 |
echo "=== Testing merge-commit with rights..." |
echo "=== Testing merge-commit with rights..." |
112 |
|
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}M" |
|
|
112 |
|
export ROCKETGIT_REPO_RIGHTS="${ROCKETGIT_REPO_RIGHTS}M" |
113 |
113 |
git push |
git push |
114 |
114 |
if [ "${?}" != "0" ]; then |
if [ "${?}" != "0" ]; then |
115 |
115 |
echo "Should work!" |
echo "Should work!" |
|
... |
... |
if [ "${?}" != "1" ]; then |
125 |
125 |
exit 1 |
exit 1 |
126 |
126 |
fi |
fi |
127 |
127 |
echo "=== Testing merge-commit with rights..." |
echo "=== Testing merge-commit with rights..." |
128 |
|
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}W" |
|
|
128 |
|
export ROCKETGIT_REPO_RIGHTS="${ROCKETGIT_REPO_RIGHTS}W" |
129 |
129 |
git push |
git push |
130 |
130 |
if [ "${?}" != "0" ]; then |
if [ "${?}" != "0" ]; then |
131 |
131 |
echo "Should work!" |
echo "Should work!" |
|
... |
... |
if [ "${?}" != "1" ]; then |
140 |
140 |
exit 1 |
exit 1 |
141 |
141 |
fi |
fi |
142 |
142 |
echo "=== Testing branch delete with rights..." |
echo "=== Testing branch delete with rights..." |
143 |
|
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}D" |
|
|
143 |
|
export ROCKETGIT_REPO_RIGHTS="${ROCKETGIT_REPO_RIGHTS}D" |
144 |
144 |
git push origin :branch1 |
git push origin :branch1 |
145 |
145 |
if [ "${?}" != "0" ]; then |
if [ "${?}" != "0" ]; then |
146 |
146 |
echo "Should work!" |
echo "Should work!" |
|
... |
... |
if [ "${?}" != "1" ]; then |
155 |
155 |
exit 1 |
exit 1 |
156 |
156 |
fi |
fi |
157 |
157 |
echo "=== Testing annotated tag create with rights..." |
echo "=== Testing annotated tag create with rights..." |
158 |
|
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}S" |
|
|
158 |
|
export ROCKETGIT_REPO_RIGHTS="${ROCKETGIT_REPO_RIGHTS}S" |
159 |
159 |
git push origin --tags |
git push origin --tags |
160 |
160 |
if [ "${?}" != "0" ]; then |
if [ "${?}" != "0" ]; then |
161 |
161 |
echo "Should work!" |
echo "Should work!" |
|
... |
... |
fi |
164 |
164 |
|
|
165 |
165 |
|
|
166 |
166 |
cd .. |
cd .. |
167 |
|
echo "Rights=${ROCKETGIT_RIGHTS}." |
|
|
167 |
|
echo "Rights=${ROCKETGIT_REPO_RIGHTS}." |
168 |
168 |
|
|
169 |
169 |
rm -rf hook_update_*.git |
rm -rf hook_update_*.git |
170 |
170 |
|
|