summaryrefslogtreecommitdiffabout
path: root/shared.c
Unidiff
Diffstat (limited to 'shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--shared.c2
1 files changed, 0 insertions, 2 deletions
diff --git a/shared.c b/shared.c
index cd60da5..48002ac 100644
--- a/shared.c
+++ b/shared.c
@@ -1,112 +1,110 @@
1/* shared.c: global vars + some callback functions 1/* shared.c: global vars + some callback functions
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10 10
11struct cgit_repolist cgit_repolist; 11struct cgit_repolist cgit_repolist;
12struct cgit_context ctx; 12struct cgit_context ctx;
13int cgit_cmd; 13int cgit_cmd;
14 14
15const char *cgit_version = CGIT_VERSION;
16
17int chk_zero(int result, char *msg) 15int chk_zero(int result, char *msg)
18{ 16{
19 if (result != 0) 17 if (result != 0)
20 die("%s: %s", msg, strerror(errno)); 18 die("%s: %s", msg, strerror(errno));
21 return result; 19 return result;
22} 20}
23 21
24int chk_positive(int result, char *msg) 22int chk_positive(int result, char *msg)
25{ 23{
26 if (result <= 0) 24 if (result <= 0)
27 die("%s: %s", msg, strerror(errno)); 25 die("%s: %s", msg, strerror(errno));
28 return result; 26 return result;
29} 27}
30 28
31int chk_non_negative(int result, char *msg) 29int chk_non_negative(int result, char *msg)
32{ 30{
33 if (result < 0) 31 if (result < 0)
34 die("%s: %s",msg, strerror(errno)); 32 die("%s: %s",msg, strerror(errno));
35 return result; 33 return result;
36} 34}
37 35
38struct cgit_repo *cgit_add_repo(const char *url) 36struct cgit_repo *cgit_add_repo(const char *url)
39{ 37{
40 struct cgit_repo *ret; 38 struct cgit_repo *ret;
41 39
42 if (++cgit_repolist.count > cgit_repolist.length) { 40 if (++cgit_repolist.count > cgit_repolist.length) {
43 if (cgit_repolist.length == 0) 41 if (cgit_repolist.length == 0)
44 cgit_repolist.length = 8; 42 cgit_repolist.length = 8;
45 else 43 else
46 cgit_repolist.length *= 2; 44 cgit_repolist.length *= 2;
47 cgit_repolist.repos = xrealloc(cgit_repolist.repos, 45 cgit_repolist.repos = xrealloc(cgit_repolist.repos,
48 cgit_repolist.length * 46 cgit_repolist.length *
49 sizeof(struct cgit_repo)); 47 sizeof(struct cgit_repo));
50 } 48 }
51 49
52 ret = &cgit_repolist.repos[cgit_repolist.count-1]; 50 ret = &cgit_repolist.repos[cgit_repolist.count-1];
53 ret->url = trim_end(url, '/'); 51 ret->url = trim_end(url, '/');
54 ret->name = ret->url; 52 ret->name = ret->url;
55 ret->path = NULL; 53 ret->path = NULL;
56 ret->desc = "[no description]"; 54 ret->desc = "[no description]";
57 ret->owner = NULL; 55 ret->owner = NULL;
58 ret->group = ctx.cfg.repo_group; 56 ret->group = ctx.cfg.repo_group;
59 ret->defbranch = "master"; 57 ret->defbranch = "master";
60 ret->snapshots = ctx.cfg.snapshots; 58 ret->snapshots = ctx.cfg.snapshots;
61 ret->enable_log_filecount = ctx.cfg.enable_log_filecount; 59 ret->enable_log_filecount = ctx.cfg.enable_log_filecount;
62 ret->enable_log_linecount = ctx.cfg.enable_log_linecount; 60 ret->enable_log_linecount = ctx.cfg.enable_log_linecount;
63 ret->module_link = ctx.cfg.module_link; 61 ret->module_link = ctx.cfg.module_link;
64 ret->readme = NULL; 62 ret->readme = NULL;
65 return ret; 63 return ret;
66} 64}
67 65
68struct cgit_repo *cgit_get_repoinfo(const char *url) 66struct cgit_repo *cgit_get_repoinfo(const char *url)
69{ 67{
70 int i; 68 int i;
71 struct cgit_repo *repo; 69 struct cgit_repo *repo;
72 70
73 for (i=0; i<cgit_repolist.count; i++) { 71 for (i=0; i<cgit_repolist.count; i++) {
74 repo = &cgit_repolist.repos[i]; 72 repo = &cgit_repolist.repos[i];
75 if (!strcmp(repo->url, url)) 73 if (!strcmp(repo->url, url))
76 return repo; 74 return repo;
77 } 75 }
78 return NULL; 76 return NULL;
79} 77}
80 78
81void *cgit_free_commitinfo(struct commitinfo *info) 79void *cgit_free_commitinfo(struct commitinfo *info)
82{ 80{
83 free(info->author); 81 free(info->author);
84 free(info->author_email); 82 free(info->author_email);
85 free(info->committer); 83 free(info->committer);
86 free(info->committer_email); 84 free(info->committer_email);
87 free(info->subject); 85 free(info->subject);
88 free(info->msg); 86 free(info->msg);
89 free(info->msg_encoding); 87 free(info->msg_encoding);
90 free(info); 88 free(info);
91 return NULL; 89 return NULL;
92} 90}
93 91
94int hextoint(char c) 92int hextoint(char c)
95{ 93{
96 if (c >= 'a' && c <= 'f') 94 if (c >= 'a' && c <= 'f')
97 return 10 + c - 'a'; 95 return 10 + c - 'a';
98 else if (c >= 'A' && c <= 'F') 96 else if (c >= 'A' && c <= 'F')
99 return 10 + c - 'A'; 97 return 10 + c - 'A';
100 else if (c >= '0' && c <= '9') 98 else if (c >= '0' && c <= '9')
101 return c - '0'; 99 return c - '0';
102 else 100 else
103 return -1; 101 return -1;
104} 102}
105 103
106char *trim_end(const char *str, char c) 104char *trim_end(const char *str, char c)
107{ 105{
108 int len; 106 int len;
109 char *s, *t; 107 char *s, *t;
110 108
111 if (str == NULL) 109 if (str == NULL)
112 return NULL; 110 return NULL;