diff options
context:
space:
mode:
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Remove the language breakdown from the stats page
Diffstat (limited to '')
-rw-r--r--cgitrc.5.txt6
-rw-r--r--custom/cgitrc4
-rw-r--r--source/ui-stats.c178
-rw-r--r--source/ui-stats.h7
-rwxr-xr-xtests/t0112-stats.sh23
5 files changed, 21 insertions, 197 deletions
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 84dcdb6..a5e0f29 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -251,9 +251,9 @@ enable-remote-branches::
"repo.enable-remote-branches".
enable-stats::
- Flag which, when set to "1", enables the statistics page, with the
- language breakdown and the commits-per-author table. Default
- value: "0". See also: "repo.enable-stats", "max-stats".
+ Flag which, when set to "1", enables the statistics page, which
+ holds the commits-per-author table. Default value: "0". See also:
+ "repo.enable-stats", "max-stats".
enable-subject-links::
Flag which, when set to "1", will make cgit use the subject of the
diff --git a/custom/cgitrc b/custom/cgitrc
index c284aca..ba4ab66 100644
--- a/custom/cgitrc
+++ b/custom/cgitrc
@@ -243,8 +243,8 @@ enable-tree-group-dirs=0
# Values are week, month, quarter or year. Default is unset.
#max-stats=week
-# Enable the statistics page, with the repository overview, activity
-# timeline, commit rhythm, language breakdown and commits per author.
+# Enable the statistics page, which counts commits per author over a window
+# of recent weeks, months, quarters or years.
# Values are 0 or 1. Default is 0.
enable-stats=0
diff --git a/source/ui-stats.c b/source/ui-stats.c
index 0ce5ef7..134e4c2 100644
--- a/source/ui-stats.c
+++ b/source/ui-stats.c
@@ -1,11 +1,9 @@
/*
* The statistics page, which counts commits per author across a window of
- * recent weeks, months, quarters or years and breaks the tip of the branch
- * down by the language its files are written in. The window sizes live in one
- * table here, which cgit.c also resolves the max-stats setting against so a
- * repository can refuse the coarser windows. Neither half of the page reads a
- * diff or the contents of a blob, so the whole thing costs about one rev-list
- * plus one tree read.
+ * recent weeks, months, quarters or years. The window sizes live in one table
+ * here, which cgit.c also resolves the max-stats setting against so a
+ * repository can refuse the coarser windows. The page reads no diff and no
+ * blob contents, so the whole thing costs about one rev-list.
*/
#define USE_THE_REPOSITORY_VARIABLE
@@ -18,29 +16,6 @@
#include "ui-stats.h"
#define DEFAULT_AUTHOR_ROWS 10
-#define MAX_LANGUAGE_ROWS 6
-
-static const struct {
- const char *ext;
- const char *label;
-} lang_map[] = {
- {"c", "C"}, {"h", "C"},
- {"cpp", "C++"}, {"cc", "C++"}, {"cxx", "C++"},
- {"hpp", "C++"}, {"hh", "C++"},
- {"js", "JavaScript"}, {"mjs", "JavaScript"},
- {"ts", "TypeScript"}, {"tsx", "TypeScript"},
- {"py", "Python"}, {"lua", "Lua"},
- {"sh", "Shell"}, {"bash", "Shell"},
- {"go", "Go"}, {"rs", "Rust"}, {"zig", "Zig"},
- {"java", "Java"}, {"kt", "Kotlin"}, {"cs", "C#"}, {"swift", "Swift"},
- {"rb", "Ruby"}, {"pl", "Perl"}, {"pm", "Perl"}, {"php", "PHP"},
- {"hs", "Haskell"}, {"el", "Lisp"}, {"ml", "OCaml"},
- {"css", "CSS"}, {"scss", "CSS"},
- {"html", "HTML"}, {"htm", "HTML"}, {"xml", "XML"},
- {"md", "Markdown"}, {"rst", "Text"}, {"txt", "Text"},
- {"json", "JSON"}, {"yml", "YAML"}, {"yaml", "YAML"}, {"toml", "TOML"},
- {"mk", "Make"}, {"tex", "TeX"}, {"sql", "SQL"}, {"vim", "Vimscript"},
-};
/*
* One author's share of the window. periods is keyed by the label of a
@@ -52,15 +27,6 @@ struct authorstat {
struct string_list periods;
};
-/*
- * Bytes at the tip of the branch per language. langs is keyed by the language
- * name, again with the count living in the util field.
- */
-struct lang_sizes {
- struct string_list langs;
- unsigned long total;
-};
-
static void trunc_week(struct tm *tm)
{
time_t t = timegm(tm);
@@ -407,131 +373,6 @@ static void print_authors(struct string_list *authors, int max_rows,
html("</table>\n");
}
-static const char *language_of(const char *pathname)
-{
- const char *ext;
- size_t i;
-
- ext = strrchr(pathname, '.');
- if (ext && ext != pathname && ext[1]) {
- for (i = 0; i < ARRAY_SIZE(lang_map); i++)
- if (!strcasecmp(ext + 1, lang_map[i].ext))
- return lang_map[i].label;
- } else if (!strcmp(pathname, "Makefile")) {
- return "Make";
- }
- return "Other";
-}
-
-static int add_blob_size(const struct object_id *oid, struct strbuf *base,
- const char *pathname, unsigned mode, void *data)
-{
- struct lang_sizes *sizes = data;
- struct string_list_item *lang;
- unsigned long size;
-
- if (S_ISDIR(mode))
- return READ_TREE_RECURSIVE;
- if (!S_ISREG(mode))
- return 0;
- if (odb_read_object_info(the_repository->objects, oid, &size) != OBJ_BLOB
- || !size)
- return 0;
-
- lang = string_list_insert(&sizes->langs, language_of(pathname));
- lang->util = (void *)((uintptr_t)lang->util + size);
- sizes->total += size;
- return 0;
-}
-
-static int cmp_lang_bytes(const void *a, const void *b)
-{
- const struct string_list_item *first = a;
- const struct string_list_item *second = b;
- uintptr_t first_bytes = (uintptr_t)first->util;
- uintptr_t second_bytes = (uintptr_t)second->util;
-
- return first_bytes < second_bytes ? 1 :
- first_bytes > second_bytes ? -1 : 0;
-}
-
-// Leaves the list sorted largest first, which is the order the rows print in
-// and what lets the caller stop naming languages once it reaches the tail.
-static void measure_languages(struct lang_sizes *sizes)
-{
- struct pathspec paths = { .nr = 0 };
- struct object_id oid;
- struct commit *commit;
-
- if (repo_get_oid(the_repository, ctx.qry.head, &oid))
- return;
- commit = lookup_commit_reference(the_repository, &oid);
- if (!commit || repo_parse_commit(the_repository, commit))
- return;
-
- read_tree(the_repository, repo_get_commit_tree(the_repository, commit),
- &paths, add_blob_size, sizes);
- qsort(sizes->langs.items, sizes->langs.nr,
- sizeof(struct string_list_item), cmp_lang_bytes);
-}
-
-static void print_language_row(const char *label, unsigned long bytes,
- unsigned long total)
-{
- struct strbuf size = STRBUF_INIT;
- int tenths;
-
- strbuf_humanise_bytes(&size, bytes);
- html("<tr><td class='left'>");
- html_txt(label);
- html("</td><td>");
- html_txt(size.buf);
- // Printed from integers so a Lua filter switching LC_NUMERIC to a
- // comma-decimal locale cannot change the output.
- tenths = (int)(1000.0 * bytes / total + 0.5);
- htmlf("</td><td>%d.%d%%</td></tr>\n", tenths / 10, tenths % 10);
- strbuf_release(&size);
-}
-
-static void print_languages(const struct lang_sizes *sizes)
-{
- unsigned long other;
- size_t i;
- int shown;
-
- if (!sizes->total)
- return;
-
- // The Other row is printed last whatever its size, so everything past
- // the named languages is summed into it up front.
- other = 0;
- shown = 0;
- for (i = 0; i < sizes->langs.nr; i++) {
- if (shown < MAX_LANGUAGE_ROWS &&
- strcmp(sizes->langs.items[i].string, "Other")) {
- shown++;
- continue;
- }
- other += (uintptr_t)sizes->langs.items[i].util;
- }
-
- html("<h2>Languages</h2>\n");
- html("<table class='stats'>\n");
- html("<tr><th>Language</th><th>Size</th><th>Share</th></tr>\n");
- shown = 0;
- for (i = 0; i < sizes->langs.nr && shown < MAX_LANGUAGE_ROWS; i++) {
- if (!strcmp(sizes->langs.items[i].string, "Other"))
- continue;
- print_language_row(sizes->langs.items[i].string,
- (uintptr_t)sizes->langs.items[i].util,
- sizes->total);
- shown++;
- }
- if (other)
- print_language_row("Other", other, sizes->total);
- html("</table>\n");
-}
-
static void print_options_form(const struct cgit_period *period, int top)
{
int choices, i;
@@ -598,7 +439,6 @@ const char *cgit_find_stats_periodname(int idx)
void cgit_show_stats(void)
{
struct string_list authors, labels;
- struct lang_sizes sizes;
const struct cgit_period *period;
int top, period_index;
const char *code = "w";
@@ -617,13 +457,6 @@ void cgit_show_stats(void)
"Statistics type disabled: %s", period->name);
return;
}
- // The tree has to be measured before the history walk. That walk
- // releases each commit as it goes, which resets the commit's slab
- // index, so a lookup afterwards would read another commit's slot and
- // walk the wrong tree.
- memset(&sizes, 0, sizeof(sizes));
- measure_languages(&sizes);
-
authors = collect_stats(period);
qsort(authors.items, authors.nr, sizeof(struct string_list_item),
cmp_total_commits);
@@ -647,8 +480,5 @@ void cgit_show_stats(void)
print_authors(&authors, top, &labels);
string_list_clear(&labels, 0);
- print_languages(&sizes);
- string_list_clear(&sizes.langs, 0);
-
cgit_print_layout_end();
}
diff --git a/source/ui-stats.h b/source/ui-stats.h
index 718e335..ccb0598 100644
--- a/source/ui-stats.h
+++ b/source/ui-stats.h
@@ -1,9 +1,8 @@
/*
* The statistics page, which counts commits per author over a window of
- * recent weeks, months, quarters or years and sizes the tip of the branch by
- * language. The windows are described here rather than inside the page,
- * because cgit.c resolves a repository's max-stats setting against the same
- * set.
+ * recent weeks, months, quarters or years. The windows are described here
+ * rather than inside the page, because cgit.c resolves a repository's
+ * max-stats setting against the same set.
*/
#ifndef CGIT_UI_STATS_H
diff --git a/tests/t0112-stats.sh b/tests/t0112-stats.sh
index bc9c25b..262932c 100755
--- a/tests/t0112-stats.sh
+++ b/tests/t0112-stats.sh
@@ -1,9 +1,9 @@
#!/bin/sh
# Checks the per repository statistics page, which stays off until a config
-# turns it on and then reports commits per author beside a breakdown of the
-# tree by language. A second config caps the period so that what max-stats
-# takes out of the period selector is covered as well.
+# turns it on and then reports commits per author. A second config caps the
+# period so that what max-stats takes out of the period selector is covered
+# as well.
test_description='Check the statistics page'
. ./setup.sh
@@ -18,10 +18,7 @@ test_expect_success 'stats are off by default' '
'
# The authors table counts only recent periods, so the fixture needs a commit
-# dated now to sit beside the 2005 dates the shared repositories carry. The
-# commit graph is written on purpose, because it sends the language walk down
-# the graph lookup path, which once handed back another commit after the
-# history walk had released its memory.
+# dated now to sit beside the 2005 dates the shared repositories carry.
test_expect_success 'set up a stats config' '
mkrepo repos/pulse 2 &&
(
@@ -55,19 +52,17 @@ test_expect_success 'stats tab appears when enabled' '
grep ">stats</a>" tmp
'
-test_expect_success 'stats page renders both sections' '
+test_expect_success 'stats page renders the authors table' '
statq "url=stat/stats/" >tmp &&
- grep "<h2>Languages" tmp &&
grep "<h2>Commits per author" tmp
'
-test_expect_success 'stat options sit above the content' '
- tr -d "\n" <tmp | sed "s/<h2>Commits per author.*//" | grep "cgit-panel"
+test_expect_success 'no language breakdown is rendered' '
+ ! grep -i "language" tmp
'
-test_expect_success 'extensionless fixture files fold into Other' '
- grep "<th>Language</th><th>Size</th><th>Share</th>" tmp &&
- grep "class=.left.>Other" tmp
+test_expect_success 'stat options sit above the content' '
+ tr -d "\n" <tmp | sed "s/<h2>Commits per author.*//" | grep "cgit-panel"
'
test_expect_success 'stats below a path stay a normal page' '