blob: feee7411fb8540817313535c2ff62adbd4f21d29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * The statistics page, which counts commits per author over a window of
 * 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
#define CGIT_UI_STATS_H

#include "cgit.h"

struct cgit_period {
	const char code;
	const char *name;

	// How many periods a page shows side by side.
	int count;

	// Move a tm back to the first day of the period it falls in.
	void (*trunc)(struct tm *tm);

	// Step a truncated tm one whole period back or forward.
	void (*dec)(struct tm *tm);
	void (*inc)(struct tm *tm);

	// Label the period a tm falls in. The buffer is reused, so a caller
	// that keeps a label copies it.
	char *(*pretty)(struct tm *tm);
};

/*
 * Look a period up by its one letter code or by its full name, storing the
 * match through period when that is not NULL. The return is a one based index
 * into the table of periods, or 0 when nothing matches, and because that
 * table runs from the finest window to the coarsest, the index is what
 * max-stats is compared against.
 */
extern int cgit_find_stats_period(const char *expr, const struct cgit_period **period);

// The name of the period at a one based index, or an empty string when the
// index names no period.
extern const char *cgit_find_stats_periodname(int idx);

extern void cgit_show_stats(void);

#endif // CGIT_UI_STATS_H