diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/ui-stats.c178
-rw-r--r--source/ui-stats.h7
2 files changed, 7 insertions, 178 deletions
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