summaryrefslogtreecommitdiffabout
authorJohan Herland <johan@herland.net>2010-11-15 17:39:48 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2010-11-16 05:56:54 (UTC)
commit17596459fe9a43428a261e66f65b227d15bf7ee5 (patch) (unidiff)
treeea30f9af3e534a2d2400ece912939475f84211da
parent7618cac1ee3bf83424d9237c3c362a43c5b246e9 (diff)
downloadcgit-17596459fe9a43428a261e66f65b227d15bf7ee5.zip
cgit-17596459fe9a43428a261e66f65b227d15bf7ee5.tar.gz
cgit-17596459fe9a43428a261e66f65b227d15bf7ee5.tar.bz2
ui-stats: Remove unnecessary #include
<string-list.h> is already #included from cgit.h Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ui-stats.c2
1 files changed, 0 insertions, 2 deletions
diff --git a/ui-stats.c b/ui-stats.c
index 946a6ea..2a0c174 100644
--- a/ui-stats.c
+++ b/ui-stats.c
@@ -1,194 +1,192 @@
1#include <string-list.h>
2
3#include "cgit.h" 1#include "cgit.h"
4#include "html.h" 2#include "html.h"
5#include "ui-shared.h" 3#include "ui-shared.h"
6#include "ui-stats.h" 4#include "ui-stats.h"
7 5
8#ifdef NO_C99_FORMAT 6#ifdef NO_C99_FORMAT
9#define SZ_FMT "%u" 7#define SZ_FMT "%u"
10#else 8#else
11#define SZ_FMT "%zu" 9#define SZ_FMT "%zu"
12#endif 10#endif
13 11
14#define MONTHS 6 12#define MONTHS 6
15 13
16struct authorstat { 14struct authorstat {
17 long total; 15 long total;
18 struct string_list list; 16 struct string_list list;
19}; 17};
20 18
21#define DAY_SECS (60 * 60 * 24) 19#define DAY_SECS (60 * 60 * 24)
22#define WEEK_SECS (DAY_SECS * 7) 20#define WEEK_SECS (DAY_SECS * 7)
23 21
24static void trunc_week(struct tm *tm) 22static void trunc_week(struct tm *tm)
25{ 23{
26 time_t t = timegm(tm); 24 time_t t = timegm(tm);
27 t -= ((tm->tm_wday + 6) % 7) * DAY_SECS; 25 t -= ((tm->tm_wday + 6) % 7) * DAY_SECS;
28 gmtime_r(&t, tm); 26 gmtime_r(&t, tm);
29} 27}
30 28
31static void dec_week(struct tm *tm) 29static void dec_week(struct tm *tm)
32{ 30{
33 time_t t = timegm(tm); 31 time_t t = timegm(tm);
34 t -= WEEK_SECS; 32 t -= WEEK_SECS;
35 gmtime_r(&t, tm); 33 gmtime_r(&t, tm);
36} 34}
37 35
38static void inc_week(struct tm *tm) 36static void inc_week(struct tm *tm)
39{ 37{
40 time_t t = timegm(tm); 38 time_t t = timegm(tm);
41 t += WEEK_SECS; 39 t += WEEK_SECS;
42 gmtime_r(&t, tm); 40 gmtime_r(&t, tm);
43} 41}
44 42
45static char *pretty_week(struct tm *tm) 43static char *pretty_week(struct tm *tm)
46{ 44{
47 static char buf[10]; 45 static char buf[10];
48 46
49 strftime(buf, sizeof(buf), "W%V %G", tm); 47 strftime(buf, sizeof(buf), "W%V %G", tm);
50 return buf; 48 return buf;
51} 49}
52 50
53static void trunc_month(struct tm *tm) 51static void trunc_month(struct tm *tm)
54{ 52{
55 tm->tm_mday = 1; 53 tm->tm_mday = 1;
56} 54}
57 55
58static void dec_month(struct tm *tm) 56static void dec_month(struct tm *tm)
59{ 57{
60 tm->tm_mon--; 58 tm->tm_mon--;
61 if (tm->tm_mon < 0) { 59 if (tm->tm_mon < 0) {
62 tm->tm_year--; 60 tm->tm_year--;
63 tm->tm_mon = 11; 61 tm->tm_mon = 11;
64 } 62 }
65} 63}
66 64
67static void inc_month(struct tm *tm) 65static void inc_month(struct tm *tm)
68{ 66{
69 tm->tm_mon++; 67 tm->tm_mon++;
70 if (tm->tm_mon > 11) { 68 if (tm->tm_mon > 11) {
71 tm->tm_year++; 69 tm->tm_year++;
72 tm->tm_mon = 0; 70 tm->tm_mon = 0;
73 } 71 }
74} 72}
75 73
76static char *pretty_month(struct tm *tm) 74static char *pretty_month(struct tm *tm)
77{ 75{
78 static const char *months[] = { 76 static const char *months[] = {
79 "Jan", "Feb", "Mar", "Apr", "May", "Jun", 77 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
80 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" 78 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
81 }; 79 };
82 return fmt("%s %d", months[tm->tm_mon], tm->tm_year + 1900); 80 return fmt("%s %d", months[tm->tm_mon], tm->tm_year + 1900);
83} 81}
84 82
85static void trunc_quarter(struct tm *tm) 83static void trunc_quarter(struct tm *tm)
86{ 84{
87 trunc_month(tm); 85 trunc_month(tm);
88 while(tm->tm_mon % 3 != 0) 86 while(tm->tm_mon % 3 != 0)
89 dec_month(tm); 87 dec_month(tm);
90} 88}
91 89
92static void dec_quarter(struct tm *tm) 90static void dec_quarter(struct tm *tm)
93{ 91{
94 dec_month(tm); 92 dec_month(tm);
95 dec_month(tm); 93 dec_month(tm);
96 dec_month(tm); 94 dec_month(tm);
97} 95}
98 96
99static void inc_quarter(struct tm *tm) 97static void inc_quarter(struct tm *tm)
100{ 98{
101 inc_month(tm); 99 inc_month(tm);
102 inc_month(tm); 100 inc_month(tm);
103 inc_month(tm); 101 inc_month(tm);
104} 102}
105 103
106static char *pretty_quarter(struct tm *tm) 104static char *pretty_quarter(struct tm *tm)
107{ 105{
108 return fmt("Q%d %d", tm->tm_mon / 3 + 1, tm->tm_year + 1900); 106 return fmt("Q%d %d", tm->tm_mon / 3 + 1, tm->tm_year + 1900);
109} 107}
110 108
111static void trunc_year(struct tm *tm) 109static void trunc_year(struct tm *tm)
112{ 110{
113 trunc_month(tm); 111 trunc_month(tm);
114 tm->tm_mon = 0; 112 tm->tm_mon = 0;
115} 113}
116 114
117static void dec_year(struct tm *tm) 115static void dec_year(struct tm *tm)
118{ 116{
119 tm->tm_year--; 117 tm->tm_year--;
120} 118}
121 119
122static void inc_year(struct tm *tm) 120static void inc_year(struct tm *tm)
123{ 121{
124 tm->tm_year++; 122 tm->tm_year++;
125} 123}
126 124
127static char *pretty_year(struct tm *tm) 125static char *pretty_year(struct tm *tm)
128{ 126{
129 return fmt("%d", tm->tm_year + 1900); 127 return fmt("%d", tm->tm_year + 1900);
130} 128}
131 129
132struct cgit_period periods[] = { 130struct cgit_period periods[] = {
133 {'w', "week", 12, 4, trunc_week, dec_week, inc_week, pretty_week}, 131 {'w', "week", 12, 4, trunc_week, dec_week, inc_week, pretty_week},
134 {'m', "month", 12, 4, trunc_month, dec_month, inc_month, pretty_month}, 132 {'m', "month", 12, 4, trunc_month, dec_month, inc_month, pretty_month},
135 {'q', "quarter", 12, 4, trunc_quarter, dec_quarter, inc_quarter, pretty_quarter}, 133 {'q', "quarter", 12, 4, trunc_quarter, dec_quarter, inc_quarter, pretty_quarter},
136 {'y', "year", 12, 4, trunc_year, dec_year, inc_year, pretty_year}, 134 {'y', "year", 12, 4, trunc_year, dec_year, inc_year, pretty_year},
137}; 135};
138 136
139/* Given a period code or name, return a period index (1, 2, 3 or 4) 137/* Given a period code or name, return a period index (1, 2, 3 or 4)
140 * and update the period pointer to the correcsponding struct. 138 * and update the period pointer to the correcsponding struct.
141 * If no matching code is found, return 0. 139 * If no matching code is found, return 0.
142 */ 140 */
143int cgit_find_stats_period(const char *expr, struct cgit_period **period) 141int cgit_find_stats_period(const char *expr, struct cgit_period **period)
144{ 142{
145 int i; 143 int i;
146 char code = '\0'; 144 char code = '\0';
147 145
148 if (!expr) 146 if (!expr)
149 return 0; 147 return 0;
150 148
151 if (strlen(expr) == 1) 149 if (strlen(expr) == 1)
152 code = expr[0]; 150 code = expr[0];
153 151
154 for (i = 0; i < sizeof(periods) / sizeof(periods[0]); i++) 152 for (i = 0; i < sizeof(periods) / sizeof(periods[0]); i++)
155 if (periods[i].code == code || !strcmp(periods[i].name, expr)) { 153 if (periods[i].code == code || !strcmp(periods[i].name, expr)) {
156 if (period) 154 if (period)
157 *period = &periods[i]; 155 *period = &periods[i];
158 return i+1; 156 return i+1;
159 } 157 }
160 return 0; 158 return 0;
161} 159}
162 160
163const char *cgit_find_stats_periodname(int idx) 161const char *cgit_find_stats_periodname(int idx)
164{ 162{
165 if (idx > 0 && idx < 4) 163 if (idx > 0 && idx < 4)
166 return periods[idx - 1].name; 164 return periods[idx - 1].name;
167 else 165 else
168 return ""; 166 return "";
169} 167}
170 168
171static void add_commit(struct string_list *authors, struct commit *commit, 169static void add_commit(struct string_list *authors, struct commit *commit,
172 struct cgit_period *period) 170 struct cgit_period *period)
173{ 171{
174 struct commitinfo *info; 172 struct commitinfo *info;
175 struct string_list_item *author, *item; 173 struct string_list_item *author, *item;
176 struct authorstat *authorstat; 174 struct authorstat *authorstat;
177 struct string_list *items; 175 struct string_list *items;
178 char *tmp; 176 char *tmp;
179 struct tm *date; 177 struct tm *date;
180 time_t t; 178 time_t t;
181 179
182 info = cgit_parse_commit(commit); 180 info = cgit_parse_commit(commit);
183 tmp = xstrdup(info->author); 181 tmp = xstrdup(info->author);
184 author = string_list_insert(authors, tmp); 182 author = string_list_insert(authors, tmp);
185 if (!author->util) 183 if (!author->util)
186 author->util = xcalloc(1, sizeof(struct authorstat)); 184 author->util = xcalloc(1, sizeof(struct authorstat));
187 else 185 else
188 free(tmp); 186 free(tmp);
189 authorstat = author->util; 187 authorstat = author->util;
190 items = &authorstat->list; 188 items = &authorstat->list;
191 t = info->committer_date; 189 t = info->committer_date;
192 date = gmtime(&t); 190 date = gmtime(&t);
193 period->trunc(date); 191 period->trunc(date);
194 tmp = xstrdup(period->pretty(date)); 192 tmp = xstrdup(period->pretty(date));