xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
Commit 1108f43c3639ffcc06f1314d901640564fae7483

Added support for other branch then master (main prefered)
Author: Catalin(ux) M. BOIE
Author date (UTC): 2020-08-23 14:55
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2020-08-23 14:55
Parent(s): 05068314021bbdf6f26bc92bee47177b170b2a1c
Signing key:
Tree: 6b3e8d73bc7a1a8139e2bd480225df4b7619a1c9
File Lines added Lines deleted
inc/admin.inc.php 10 9
inc/repo.inc.php 9 3
inc/struct.inc.php 3 1
inc/user.inc.php 2 2
inc/user/repo-page.php 41 25
root/themes/default/repo/add_edit.html 5 0
File inc/admin.inc.php changed (mode: 100644) (index af420bb..5bca566)
... ... function rg_admin_report1_suggestions($db, $from, $to)
673 673 */ */
674 674 function rg_admin_report_big_repos($db) function rg_admin_report_big_repos($db)
675 675 { {
676 $ret = 'Biggest repos (name, owner, total, git, artifacts):' . "\n";
676 $ret = 'Biggest repos (name, owner, total, git, artifacts; MiB):' . "\n";
677 677 while (1) { while (1) {
678 $sql = 'SELECT uid, name, disk_used_mb, artifacts_mb'
678 $sql = 'SELECT uid, name, disk_used_mb, git_mb, artifacts_mb'
679 679 . ' FROM repos' . ' FROM repos'
680 680 . ' ORDER BY disk_used_mb DESC LIMIT 20'; . ' ORDER BY disk_used_mb DESC LIMIT 20';
681 681 $res = rg_sql_query($db, $sql); $res = rg_sql_query($db, $sql);
 
... ... function rg_admin_report_big_repos($db)
684 684
685 685 while (($row = rg_sql_fetch_array($res))) { while (($row = rg_sql_fetch_array($res))) {
686 686 $ui = rg_user_nice($db, $row['uid']); $ui = rg_user_nice($db, $row['uid']);
687 $ret .= "\t" . $row['name']
688 . "\t" . $ui
689 . "\t" . $row['disk_used_mb'] . ' MiB'
690 . "\t" . $row['git_mb'] . ' MiB'
691 . "\t" . $row['artifacts_mb'] . ' MiB'
687 $ret .= ' ' . $row['name']
688 . ' ' . $ui
689 . ' ' . $row['disk_used_mb']
690 . ' ' . $row['git_mb']
691 . ' ' . $row['artifacts_mb']
692 692 . "\n"; . "\n";
693 693 } }
694 694 rg_sql_free_result($res); rg_sql_free_result($res);
 
... ... function rg_admin_report_big_repos($db)
704 704 */ */
705 705 function rg_admin_report_big_users($db) function rg_admin_report_big_users($db)
706 706 { {
707 $ret = 'Biggest users:' . "\n";
707 $ret = 'Biggest users (total, git, artifacts; MiB):' . "\n";
708 708 while (1) { while (1) {
709 $sql = 'SELECT username, disk_used_mb FROM users'
709 $sql = 'SELECT username, disk_used_mb, git_mb, artifacts_mb'
710 . ' FROM users'
710 711 . ' WHERE deleted = 0' . ' WHERE deleted = 0'
711 712 . ' ORDER BY disk_used_mb DESC LIMIT 20'; . ' ORDER BY disk_used_mb DESC LIMIT 20';
712 713 $res = rg_sql_query($db, $sql); $res = rg_sql_query($db, $sql);
File inc/repo.inc.php changed (mode: 100644) (index 7e4ffa7..2728da7)
... ... function rg_repo_edit($db, $login_ui, &$new)
1145 1145 // Small fixes // Small fixes
1146 1146 $new['itime'] = time(); $new['itime'] = time();
1147 1147 $new['uid'] = $login_ui['uid']; $new['uid'] = $login_ui['uid'];
1148 if (!isset($new['main_branch']))
1149 $new['main_branch'] = '';
1148 1150
1149 1151 if ($new['repo_id'] == 0) { if ($new['repo_id'] == 0) {
1150 1152 $new['deleted'] = 0; $new['deleted'] = 0;
 
... ... function rg_repo_edit($db, $login_ui, &$new)
1155 1157
1156 1158 $sql = "INSERT INTO repos (uid, master, name" $sql = "INSERT INTO repos (uid, master, name"
1157 1159 . ", itime, max_commit_size, description" . ", itime, max_commit_size, description"
1158 . ", git_dir_done, public, license, template)"
1160 . ", git_dir_done, public, license, template"
1161 . ", main_branch)"
1159 1162 . " VALUES (@@uid@@, @@master@@, @@name@@" . " VALUES (@@uid@@, @@master@@, @@name@@"
1160 1163 . ", @@itime@@, @@max_commit_size@@" . ", @@itime@@, @@max_commit_size@@"
1161 1164 . ", @@description@@, 0, @@public@@" . ", @@description@@, 0, @@public@@"
1162 . ", @@license@@, @@template@@)"
1165 . ", @@license@@, @@template@@, @@main_branch@@)"
1163 1166 . " RETURNING repo_id"; . " RETURNING repo_id";
1164 1167 } else { } else {
1165 1168 $sql = "UPDATE repos SET name = @@name@@" $sql = "UPDATE repos SET name = @@name@@"
 
... ... function rg_repo_edit($db, $login_ui, &$new)
1168 1171 . ", public = @@public@@" . ", public = @@public@@"
1169 1172 . ", license = @@license@@" . ", license = @@license@@"
1170 1173 . ", template = @@template@@" . ", template = @@template@@"
1174 . ", main_branch = @@main_branch@@"
1171 1175 . " WHERE repo_id = @@repo_id@@"; . " WHERE repo_id = @@repo_id@@";
1172 1176 } }
1173 1177 $res = rg_sql_query_params($db, $sql, $new); $res = rg_sql_query_params($db, $sql, $new);
 
... ... function rg_repo_edit_high_level($db, &$rg)
1884 1888 'OS type(s) and version(s)?' . "\n\n" 'OS type(s) and version(s)?' . "\n\n"
1885 1889 . 'Application version(s) affected?' . "\n\n" . 'Application version(s) affected?' . "\n\n"
1886 1890 . 'Steps to reproduce?'; . 'Steps to reproduce?';
1891 $rg['ri']['main_branch'] = '';
1887 1892 } }
1888 1893 break; break;
1889 1894 } }
1890 1895
1891 1896 $rg['ri']['repo_id'] = rg_var_uint('repo_id'); $rg['ri']['repo_id'] = rg_var_uint('repo_id');
1892 1897 $rg['ri']['master'] = rg_var_uint('master'); $rg['ri']['master'] = rg_var_uint('master');
1893 $rg['ri']['name'] = trim(rg_var_str('name')); // TODO: filter name!
1898 $rg['ri']['name'] = trim(rg_var_str_nocr('name')); // TODO: filter name!
1894 1899 $rg['ri']['max_commit_size'] = rg_var_uint('max_commit_size'); $rg['ri']['max_commit_size'] = rg_var_uint('max_commit_size');
1895 1900 $rg['ri']['description'] = trim(rg_var_str('description')); $rg['ri']['description'] = trim(rg_var_str('description'));
1896 1901 $rg['ri']['public'] = rg_var_bool('public'); $rg['ri']['public'] = rg_var_bool('public');
1897 1902 $rg['ri']['license'] = trim(rg_var_str('license')); $rg['ri']['license'] = trim(rg_var_str('license'));
1898 1903 $rg['ri']['template'] = trim(rg_var_str('template')); $rg['ri']['template'] = trim(rg_var_str('template'));
1904 $rg['ri']['main_branch'] = trim(rg_var_str_nocr('main_branch'));
1899 1905 rg_repo_cosmetic($db, $rg['ri']); rg_repo_cosmetic($db, $rg['ri']);
1900 1906 //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));
1901 1907
File inc/struct.inc.php changed (mode: 100644) (index 36a5da1..130e9ca)
... ... $rg_sql_struct[46]['other'] = array(
683 683 'repo artifacts size' => 'repo artifacts size' =>
684 684 'ALTER TABLE repos ADD artifacts_mb INT NOT NULL DEFAULT 0', 'ALTER TABLE repos ADD artifacts_mb INT NOT NULL DEFAULT 0',
685 685 'user artifacts size' => 'user artifacts size' =>
686 'ALTER TABLE users ADD artifacts_mb INT NOT NULL DEFAULT 0'
686 'ALTER TABLE users ADD artifacts_mb INT NOT NULL DEFAULT 0',
687 'repo main_branch' =>
688 'ALTER TABLE repos ADD main_branch TEXT NOT NULL DEFAULT \'\''
687 689 ); );
688 690
689 691 // Do not forget to add the new created tables to statistics // Do not forget to add the new created tables to statistics
File inc/user.inc.php changed (mode: 100644) (index a60a9e0..86935c4)
... ... function rg_user_edit_high_level($db, &$rg)
1972 1972
1973 1973 $ui = array(); $ui = array();
1974 1974 $ui['uid'] = $rg['target_ui']['uid']; $ui['uid'] = $rg['target_ui']['uid'];
1975 $ui['username'] = trim(rg_var_str("username"));
1976 $ui['realname'] = trim(rg_var_str("realname"));
1975 $ui['username'] = trim(rg_var_str_nocr("username"));
1976 $ui['realname'] = trim(rg_var_str_nocr("realname"));
1977 1977 $ui['email'] = rg_var_email('email'); $ui['email'] = rg_var_email('email');
1978 1978 $ui['pass'] = rg_var_str("pass"); $ui['pass'] = rg_var_str("pass");
1979 1979 $ui['pass2'] = rg_var_str("pass2"); $ui['pass2'] = rg_var_str("pass2");
File inc/user/repo-page.php changed (mode: 100644) (index 3476efc..78134e4)
... ... function rg_repo_page_source($db, &$rg, &$paras)
226 226 $_subsubop = empty($paras) ? 'log' : array_shift($paras); $_subsubop = empty($paras) ? 'log' : array_shift($paras);
227 227 $rg['source_menu'][$_subsubop] = 1; $rg['source_menu'][$_subsubop] = 1;
228 228
229 $existing_refs = rg_git_refs($rg['repo_path']);
230 rg_log_ml('DEBUG: existing_refs: ' . print_r($existing_refs, TRUE));
231
232 $type_ref = rg_git_parse_ref($paras);
233 rg_log_ml('DEBUG: type_ref=' . print_r($type_ref, TRUE));
234 $ref = $type_ref['ref_path'];
235 if (rg_git_ref_valid($existing_refs, $type_ref['ref_type'], $type_ref['ref_val']) !== TRUE) {
236 rg_log('DEBUG: ref is not valid, force branch+master');
237 $_a = array('branch', 'master');
238 $type_ref = rg_git_parse_ref($_a);
239 $ref = $type_ref['ref_path'];
240 }
241
242 //rg_log_ml('DEBUG: type_ref: ' . print_r($type_ref, TRUE));
243 $rg = array_merge($rg, $type_ref);
244 rg_log('DEBUG: ref=[' . $ref . ']');
245
246 $bt = rg_git_branches_and_tags($existing_refs, $rg['ri']['url_repo'],
247 $type_ref['ref_url']);
248 $rg = array_merge($rg, $bt);
249
250 rg_add_clone_hints($db, $rg, $ref);
251
252 $ret .= rg_template('repo/source.html', $rg, TRUE /*xss*/);
253
254 229 if ($rg['ri']['git_dir_done'] == 0) { if ($rg['ri']['git_dir_done'] == 0) {
255 230 $ret .= rg_template('repo/err/no_git_dir.html', $rg, TRUE /*xss*/); $ret .= rg_template('repo/err/no_git_dir.html', $rg, TRUE /*xss*/);
256 231 break; break;
 
... ... function rg_repo_page_source($db, &$rg, &$paras)
268 243 break; break;
269 244 } }
270 245
246 $existing_refs = rg_git_refs($rg['repo_path']);
247 rg_log_ml('DEBUG: existing_refs: ' . print_r($existing_refs, TRUE));
248
249 $paras2 = array(array_shift($paras), array_shift($paras));
250 rg_log('DEBUG: paras: [' . rg_array2string($paras) . ']');
251 $list = array(
252 $paras2,
253 array('branch', $rg['ri']['main_branch']),
254 array('branch', 'main'),
255 array('branch', 'master')
256 );
257 // Add first existing branch
258 if (!empty($existing_refs['branch']))
259 $list[] = array('branch', $existing_refs['branch'][0]);
260
261 $ok = FALSE;
262 foreach ($list as $a) {
263 rg_log('DEBUG: a=[' . rg_array2string($a) . ']');
264 $type_ref = rg_git_parse_ref($a);
265 if (rg_git_ref_valid($existing_refs,
266 $type_ref['ref_type'], $type_ref['ref_val']) === TRUE) {
267 $ref = $type_ref['ref_path'];
268 $ok = TRUE;
269 break;
270 }
271 }
272 rg_log('DEBUG: paras XXX: ' . rg_array2string($paras));
273 if ($ok) {
274 rg_log('DEBUG: ref=[' . $ref . ']');
275 $rg = array_merge($rg, $type_ref);
276
277 $bt = rg_git_branches_and_tags($existing_refs,
278 $rg['ri']['url_repo'], $type_ref['ref_url']);
279 $rg = array_merge($rg, $bt);
280
281 rg_add_clone_hints($db, $rg, $ref);
282
283 $ret .= rg_template('repo/source.html',
284 $rg, TRUE /*xss*/);
285 }
286
271 287 rg_log('DEBUG: _subsubop=[' . $_subsubop . ']'); rg_log('DEBUG: _subsubop=[' . $_subsubop . ']');
272 288 if (strcmp($_subsubop, 'tree') == 0) { if (strcmp($_subsubop, 'tree') == 0) {
273 289 $type = array_shift($paras); $type = array_shift($paras);
File root/themes/default/repo/add_edit.html changed (mode: 100644) (index a9666ed..45d03d2)
35 35 </select> </select>
36 36 </p> </p>
37 37
38 <p>
39 <label for="main_branch">Main branch name (empty = autodetect)</label><br />
40 <input type="text" name="main_branch" id="main_branch" value="@@ri::main_branch@@" />
41 </p>
42
38 43 <p> <p>
39 44 <label for="template">Bug template</label><br /> <label for="template">Bug template</label><br />
40 45 <textarea name="template" id="template" rows="6">@@ri::template@@</textarea> <textarea name="template" id="template" rows="6">@@ri::template@@</textarea>
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master