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 621b0a317b65d9a751d221908b8e1664d96011fa

Fix repo stats when there is no commit inside.

Author: Catalin(ux) M. BOIE
Author date (UTC): 2015-09-11 04:58
Committer: Catalin(ux) M. BOIE
Commit date (UTC): 2015-09-11 04:58
Tree: 2ccee6c59ff694fe4b8f2040aaf2072d31c955a1
Parents: d8d06816223b52ff1d65df502fc6175f26c15518
File Lines added Lines deleted
TODO 3 1
inc/git.inc.php 3 2
inc/repo.inc.php 24 13
root/themes/default/repo/stats/authors/nodata.html 0 1
root/themes/default/repo/stats/stats.html 3 0
tests/git.php 10 0

File TODO changed (mode: 100644) (index a6b74aa..0af8ec3)
1 1 == Where I stopped last time == == Where I stopped last time ==
2 [ ] Test with an empty commit what happens in rg_git_log with patches == TRUE.
3 2 [ ] [ ]
4 3
5 4 == BEFORE NEXT RELEASE == == BEFORE NEXT RELEASE ==
5 [ ] Test with an empty commit what happens in rg_git_log with patches == TRUE.
6 Can happen? Maybe for a rename?
7 [ ] Add repo stats to ssh repo command.
6 8 [ ] build rg_user_git_stats that will lookup email into stats and resolve them [ ] build rg_user_git_stats that will lookup email into stats and resolve them
7 9 to be rg links? to be rg links?
8 10 [ ] repo:stats: seems the number of commits is limited somehow! [ ] repo:stats: seems the number of commits is limited somehow!

File inc/git.inc.php changed (mode: 100644) (index 5b04442..8aa9f87)
... ... function rg_git_log($path, $max, $from, $to, $also_patch)
694 694 if (!file_exists($path . "/refs/heads/master")) { if (!file_exists($path . "/refs/heads/master")) {
695 695 if (!file_exists($path . "/.git/refs/heads/master")) { if (!file_exists($path . "/.git/refs/heads/master")) {
696 696 rg_log("Repo is empty."); rg_log("Repo is empty.");
697 $ret = array();
697 698 break; break;
698 699 } }
699 700 } }
 
... ... function rg_git_log($path, $max, $from, $to, $also_patch)
739 740 . $from_to; . $from_to;
740 741 $a = rg_exec($cmd); $a = rg_exec($cmd);
741 742 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
742 rg_git_set_error("error on log (" . $a['errmsg'] . ")");
743 rg_internal_error("Could not generate log.");
743 rg_internal_error("error on log (" . $a['errmsg'] . ")");
744 rg_git_set_error("could not generate log; try again later");
744 745 break; break;
745 746 } }
746 747

File inc/repo.inc.php changed (mode: 100644) (index c27873b..d97d4af)
... ... function rg_repo_discover($db, $op, $rg, $ui)
1732 1732 */ */
1733 1733 function rg_repo_stats($rg) function rg_repo_stats($rg)
1734 1734 { {
1735 if ($rg['ri']['git_dir_done'] == 0)
1736 return rg_template('repo/no_git_dir.html', $rg, TRUE /*xss*/);
1735 rg_log_enter('repo_start');
1737 1736
1738 $path = rg_repo_path_by_id($rg['ri']['uid'], $rg['ri']['repo_id']);
1739 $log = rg_git_log($path, 0 /*max*/, '', '', FALSE);
1740 if ($log === FALSE)
1741 return rg_template('internal_err.html', $rg, TRUE /*xss*/);
1737 while (1) {
1738 if ($rg['ri']['git_dir_done'] == 0) {
1739 $ret = rg_template('repo/no_git_dir.html', $rg, TRUE /*xss*/);
1740 break;
1741 }
1742
1743 $path = rg_repo_path_by_id($rg['ri']['uid'], $rg['ri']['repo_id']);
1744 $log = rg_git_log($path, 0 /*max*/, '', '', FALSE);
1745 if ($log === FALSE) {
1746 $ret = rg_template('internal_err.html', $rg, TRUE /*xss*/);
1747 break;
1748 }
1742 1749
1743 $s = rg_git_stats($log);
1744 // TODO: can this return error?
1745 rg_log_ml('DEBUG: stats: ' . print_r($s, TRUE));
1746 $rg['ri']['stats'] = $s['global'];
1750 $s = rg_git_stats($log);
1751 //rg_log_ml('DEBUG: stats: ' . print_r($s, TRUE));
1752 $rg['ri']['stats'] = $s['global'];
1747 1753
1748 $rg['ri']['HTML:authors'] = rg_template_table('repo/stats/authors',
1749 $s['authors'], $rg);
1754 $rg['ri']['HTML:authors'] = rg_template_table('repo/stats/authors',
1755 $s['authors'], $rg);
1750 1756
1751 return rg_template('repo/stats/stats.html', $rg, TRUE /*xss*/);
1757 $ret = rg_template('repo/stats/stats.html', $rg, TRUE /*xss*/);
1758 break;
1759 }
1760
1761 rg_log_exit();
1762 return $ret;
1752 1763 } }
1753 1764
1754 1765 ?> ?>

File root/themes/default/repo/stats/authors/nodata.html changed (mode: 100644) (index e25f181..e69de29)
1 y

File root/themes/default/repo/stats/stats.html changed (mode: 100644) (index 65dada6..c89d41f)
1 1 Added on this site on <b>@@ri::itime_nice@@</b>.<br /> Added on this site on <b>@@ri::itime_nice@@</b>.<br />
2 2 Disk space used: <b>@@ri::disk_used_mb@@ MiB</b>.<br /> Disk space used: <b>@@ri::disk_used_mb@@ MiB</b>.<br />
3 3 Bugs reported: <b>@@ri::last_bug_id@@</b>.<br /> Bugs reported: <b>@@ri::last_bug_id@@</b>.<br />
4
5 @@if("@@ri::stats::start_date@@" != ""){{
4 6 <br /> <br />
5 7 Project started on <b>@@ri::stats::start_date@@</b> by <b>@@ri::stats::start_author@@</b>.<br /> Project started on <b>@@ri::stats::start_date@@</b> by <b>@@ri::stats::start_author@@</b>.<br />
6 8 Last commit on <b>@@ri::stats::last_date@@</b> by <b>@@ri::stats::last_author@@</b>.<br /> Last commit on <b>@@ri::stats::last_date@@</b> by <b>@@ri::stats::last_author@@</b>.<br />
 
... ... Number of lines added: @@ri::stats::lines_add@@.
9 11 Number of lines deleted: <b>@@ri::stats::lines_del@@</b>.<br /> Number of lines deleted: <b>@@ri::stats::lines_del@@</b>.<br />
10 12
11 13 @@ri::authors@@ @@ri::authors@@
14 }}

File tests/git.php changed (mode: 100644) (index ecef385..d8f39cd)
... ... require_once("common.php");
14 14
15 15
16 16 rg_log(''); rg_log('');
17 rg_log("Testing rg_git_log with a rename");
18 system("git init git_rename; cd git_rename;"
19 . " touch a; git add a; git commit -a -m \"aaa\";"
20 . " git mv a b; git commit -a -m \"bbb\"");
21 $r = rg_git_log('git_rename/.git', 1, '', '', TRUE);
22 // we do not test here nothing, we will let err- files "speak"
23 system("rm -rf git_rename");
24
25
26 rg_log('');
17 27 rg_log("Testing rg_git_log for binary files"); rg_log("Testing rg_git_log for binary files");
18 28 system("git init git_bin; cd git_bin;" system("git init git_bin; cd git_bin;"
19 29 . " echo -e \x01\x02 > a; git add a; git commit -a -m \"aaa\";" . " echo -e \x01\x02 > a; git add a; git commit -a -m \"aaa\";"
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