Merge branch 'wip'
@@ -18,7 +18,7 @@ #include "scan-tree.h"
const char *cgit_version = CGIT_VERSION; -void add_mimetype(const char *name, const char *value) +static void add_mimetype(const char *name, const char *value) { struct string_list_item *item;@@ -26,7 +26,7 @@ item = string_list_insert(&ctx.cfg.mimetypes, xstrdup(name));
item->util = xstrdup(value); } -struct cgit_filter *new_filter(const char *cmd, filter_type filtertype) +static struct cgit_filter *new_filter(const char *cmd, filter_type filtertype) { struct cgit_filter *f; int args_size = 0;@@ -58,7 +58,7 @@ }
static void process_cached_repolist(const char *path); -void repo_config(struct cgit_repo *repo, const char *name, const char *value) +static void repo_config(struct cgit_repo *repo, const char *name, const char *value) { struct string_list_item *item;@@ -114,7 +114,7 @@ repo->source_filter = new_filter(value, SOURCE);
} } -void config_cb(const char *name, const char *value) +static void config_cb(const char *name, const char *value) { if (!strcmp(name, "section") || !strcmp(name, "repo.group")) ctx.cfg.section = xstrdup(value);@@ -333,7 +333,7 @@ ctx.qry.ignorews = atoi(value);
} } -char *xstrdupn(const char *str) +static char *xstrdupn(const char *str) { return (str ? xstrdup(str) : NULL); }@@ -414,8 +414,8 @@ char *first_ref;
int match; }; -int find_current_ref(const char *refname, const unsigned char *sha1, - int flags, void *cb_data) +static int find_current_ref(const char *refname, const unsigned char *sha1, + int flags, void *cb_data) { struct refmatch *info;@@ -427,7 +427,13 @@ info->first_ref = xstrdup(refname);
return info->match; } -char *find_default_branch(struct cgit_repo *repo) +static void free_refmatch_inner(struct refmatch *info) +{ + if (info->first_ref) + free(info->first_ref); +} + +static char *find_default_branch(struct cgit_repo *repo) { struct refmatch info; char *ref;@@ -442,6 +448,8 @@ else
ref = info.first_ref; if (ref) ref = xstrdup(ref); + free_refmatch_inner(&info); + return ref; }@@ -569,13 +577,13 @@ if (cmd->want_layout)
cgit_print_docend(); } -int cmp_repos(const void *a, const void *b) +static int cmp_repos(const void *a, const void *b) { const struct cgit_repo *ra = a, *rb = b; return strcmp(ra->url, rb->url); } -char *build_snapshot_setting(int bitmap) +static char *build_snapshot_setting(int bitmap) { const struct cgit_snapshot_format *f; char *result = xstrdup("");@@ -595,7 +603,7 @@ result[len - 1] = '\0';
return result; } -char *get_first_line(char *txt) +static char *get_first_line(char *txt) { char *t = xstrdup(txt); char *p = strchr(t, '\n');@@ -604,7 +612,7 @@ *p = '\0';
return t; } -void print_repo(FILE *f, struct cgit_repo *repo) +static void print_repo(FILE *f, struct cgit_repo *repo) { fprintf(f, "repo.url=%s\n", repo->url); fprintf(f, "repo.name=%s\n", repo->name);@@ -649,7 +657,7 @@ cgit_find_stats_periodname(repo->max_stats));
fprintf(f, "\n"); } -void print_repolist(FILE *f, struct cgit_repolist *list, int start) +static void print_repolist(FILE *f, struct cgit_repolist *list, int start) { int i;
@@ -304,6 +304,7 @@ extern char *strlpart(char *txt, int maxlen);
extern char *strrpart(char *txt, int maxlen); extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); +extern void cgit_free_reflist_inner(struct reflist *list); extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, int flags, void *cb_data);
@@ -10,7 +10,7 @@ #include <ctype.h>
#include <stdio.h> #include "configfile.h" -int next_char(FILE *f) +static int next_char(FILE *f) { int c = fgetc(f); if (c == '\r') {@@ -23,7 +23,7 @@ }
return c; } -void skip_line(FILE *f) +static void skip_line(FILE *f) { int c;@@ -31,7 +31,7 @@ while ((c = next_char(f)) && c != '\n' && c != EOF)
; } -int read_config_line(FILE *f, char *line, const char **value, int bufsize) +static int read_config_line(FILE *f, char *line, const char **value, int bufsize) { int i = 0, isname = 0;
@@ -39,7 +39,7 @@ "%f4", "%f5", "%f6", "%f7", "%f8", "%f9", "%fa", "%fb", "%fc", "%fd",
"%fe", "%ff" }; -int htmlfd = STDOUT_FILENO; +static int htmlfd = STDOUT_FILENO; char *fmt(const char *format, ...) {@@ -266,7 +266,7 @@ fclose(f);
return 0; } -int hextoint(char c) +static int hextoint(char c) { if (c >= 'a' && c <= 'f') return 10 + c - 'a';@@ -278,7 +278,7 @@ else
return -1; } -char *convert_query_hexchar(char *txt) +static char *convert_query_hexchar(char *txt) { int d1, d2, n; n = strlen(txt);
@@ -52,7 +52,7 @@ return;
} } -char *substr(const char *head, const char *tail) +static char *substr(const char *head, const char *tail) { char *buf;@@ -64,7 +64,7 @@ buf[tail - head] = '\0';
return buf; } -char *parse_user(char *t, char **name, char **email, unsigned long *date) +static char *parse_user(char *t, char **name, char **email, unsigned long *date) { char *p = t; int mode = 1;@@ -101,7 +101,7 @@
#ifdef NO_ICONV #define reencode(a, b, c) #else -const char *reencode(char **txt, const char *src_enc, const char *dst_enc) +static const char *reencode(char **txt, const char *src_enc, const char *dst_enc) { char *tmp;
@@ -74,6 +74,7 @@ if (prefix) {
html(" /"); cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix); } + free(tmp); html("</td></tr>\n"); for (p = commit->parents; p; p = p->next) { parent = lookup_commit_reference(p->item->object.sha1);
@@ -166,8 +166,9 @@ total_adds += lines_added;
total_rems += lines_removed; } -void cgit_print_diffstat(const unsigned char *old_sha1, - const unsigned char *new_sha1, const char *prefix) +static void cgit_print_diffstat(const unsigned char *old_sha1, + const unsigned char *new_sha1, + const char *prefix) { int i;
@@ -28,7 +28,7 @@ };
#define COLUMN_COLORS_HTML_MAX (ARRAY_SIZE(column_colors_html) - 1) -void count_lines(char *line, int size) +static void count_lines(char *line, int size) { if (size <= 0) return;@@ -40,7 +40,7 @@ else if (line[0] == '-')
rem_lines++; } -void inspect_files(struct diff_filepair *pair) +static void inspect_files(struct diff_filepair *pair) { unsigned long old_size = 0; unsigned long new_size = 0;@@ -95,7 +95,7 @@ deco = deco->next;
} } -void print_commit(struct commit *commit, struct rev_info *revs) +static void print_commit(struct commit *commit, struct rev_info *revs) { struct commitinfo *info; int cols = revs->graph ? 3 : 2;
@@ -103,6 +103,7 @@ {
const struct cgit_snapshot_format* f; char *filename; const char *basename; + int free_ref = 0; if (!ref || strlen(ref) < 2) return;@@ -111,8 +112,10 @@ basename = cgit_repobasename(repo->url);
if (prefixcmp(ref, basename) != 0) { if ((ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1])) ref++; - if (isdigit(ref[0])) + if (isdigit(ref[0])) { ref = xstrdup(fmt("%s-%s", basename, ref)); + free_ref = 1; + } } for (f = cgit_snapshot_formats; f->suffix; f++) {@@ -122,6 +125,9 @@ filename = fmt("%s%s", ref, f->suffix);
cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename); html(" "); } + + if (free_ref) + free((char *)ref); } static int print_tag(struct refinfo *ref) {@@ -205,6 +211,8 @@ print_branch(list.refs[i]);
if (maxcount < list.count) print_refs_link("heads"); + + cgit_free_reflist_inner(&list); } void cgit_print_tags(int maxcount)@@ -229,6 +237,8 @@ print_tag(list.refs[i]);
if (maxcount < list.count) print_refs_link("tags"); + + cgit_free_reflist_inner(&list); } void cgit_print_refs()
@@ -12,7 +12,7 @@ #include "html.h"
#include "ui-shared.h" #include <strings.h> -time_t read_agefile(char *path) +static time_t read_agefile(char *path) { time_t result; size_t size;@@ -76,7 +76,7 @@ if (get_repo_modtime(repo, &t))
cgit_print_age(t, -1, NULL); } -int is_match(struct cgit_repo *repo) +static int is_match(struct cgit_repo *repo) { if (!ctx.qry.search) return 1;@@ -91,7 +91,7 @@ return 1;
return 0; } -int is_in_url(struct cgit_repo *repo) +static int is_in_url(struct cgit_repo *repo) { if (!ctx.qry.url) return 1;@@ -100,7 +100,7 @@ return 1;
return 0; } -void print_sort_header(const char *title, const char *sort) +static void print_sort_header(const char *title, const char *sort) { htmlf("<th class='left'><a href='%s?s=%s", cgit_rooturl(), sort); if (ctx.qry.search) {@@ -110,7 +110,7 @@ }
htmlf("'>%s</a></th>", title); } -void print_header() +static void print_header() { html("<tr class='nohover'>"); print_sort_header("Name", "name");@@ -124,7 +124,7 @@ html("</tr>\n");
} -void print_pager(int items, int pagelen, char *search, char *sort) +static void print_pager(int items, int pagelen, char *search, char *sort) { int i, ofs; char *class = NULL;@@ -223,7 +223,7 @@ {"idle", sort_idle},
{NULL, NULL} }; -int sort_repolist(char *field) +static int sort_repolist(char *field) { struct sortcolumn *column;
@@ -153,7 +153,7 @@
return NULL; } -void show_error(char *msg) +static void show_error(char *msg) { ctx.page.mimetype = "text/html"; cgit_print_http_headers(&ctx);
@@ -211,8 +211,8 @@
/* Walk the commit DAG and collect number of commits per author per * timeperiod into a nested string_list collection. */ -struct string_list collect_stats(struct cgit_context *ctx, - struct cgit_period *period) +static struct string_list collect_stats(struct cgit_context *ctx, + struct cgit_period *period) { struct string_list authors; struct rev_info rev;@@ -253,9 +253,12 @@ }
return authors; } -void print_combined_authorrow(struct string_list *authors, int from, int to, - const char *name, const char *leftclass, const char *centerclass, - const char *rightclass, struct cgit_period *period) +static void print_combined_authorrow(struct string_list *authors, int from, + int to, const char *name, + const char *leftclass, + const char *centerclass, + const char *rightclass, + struct cgit_period *period) { struct string_list_item *author; struct authorstat *authorstat;@@ -293,8 +296,8 @@ }
htmlf("<td class='%s'>%ld</td></tr>", rightclass, total); } -void print_authors(struct string_list *authors, int top, - struct cgit_period *period) +static void print_authors(struct string_list *authors, int top, + struct cgit_period *period) { struct string_list_item *author; struct authorstat *authorstat;
@@ -271,7 +271,6 @@
if (!rev) rev = ctx.qry.head; - walk_tree_ctx.curr_rev = xstrdup(rev); if (get_sha1(rev, sha1)) { cgit_print_error(fmt("Invalid revision name: %s", rev)); return;@@ -282,12 +281,17 @@ cgit_print_error(fmt("Invalid commit reference: %s", rev));
return; } + walk_tree_ctx.curr_rev = xstrdup(rev); + if (path == NULL) { ls_tree(commit->tree->object.sha1, NULL, &walk_tree_ctx); - return; + goto cleanup; } read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); if (walk_tree_ctx.state == 1) ls_tail(); + +cleanup: + free(walk_tree_ctx.curr_rev); }