author | Lars Hjemli <hjemli@gmail.com> | 2007-02-08 12:53:13 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-02-08 12:58:58 (UTC) |
commit | ab2ab95f09994560f62fd631f07d3b6e3577aa6e (patch) (unidiff) | |
tree | 846763c1bcb78bd27dc37c99e5f6d703ca5ab179 /shared.c | |
parent | 14d360df60f059b9b5b045fc6df1eec6f0966d9a (diff) | |
download | cgit-ab2ab95f09994560f62fd631f07d3b6e3577aa6e.zip cgit-ab2ab95f09994560f62fd631f07d3b6e3577aa6e.tar.gz cgit-ab2ab95f09994560f62fd631f07d3b6e3577aa6e.tar.bz2 |
Add support for snapshots
Make a link from the commit viewer to a snapshot of the corresponding tree.
Currently only zip-format is supported.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | shared.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -1,168 +1,185 @@ | |||
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 | ||
11 | struct repolist cgit_repolist; | 11 | struct repolist cgit_repolist; |
12 | struct repoinfo *cgit_repo; | 12 | struct repoinfo *cgit_repo; |
13 | 13 | ||
14 | char *cgit_root_title = "Git repository browser"; | 14 | char *cgit_root_title = "Git repository browser"; |
15 | char *cgit_css = "/cgit.css"; | 15 | char *cgit_css = "/cgit.css"; |
16 | char *cgit_logo = "/git-logo.png"; | 16 | char *cgit_logo = "/git-logo.png"; |
17 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; | 17 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; |
18 | char *cgit_virtual_root = NULL; | 18 | char *cgit_virtual_root = NULL; |
19 | 19 | ||
20 | char *cgit_cache_root = "/var/cache/cgit"; | 20 | char *cgit_cache_root = "/var/cache/cgit"; |
21 | 21 | ||
22 | int cgit_nocache = 0; | 22 | int cgit_nocache = 0; |
23 | int cgit_max_lock_attempts = 5; | 23 | int cgit_max_lock_attempts = 5; |
24 | int cgit_cache_root_ttl = 5; | 24 | int cgit_cache_root_ttl = 5; |
25 | int cgit_cache_repo_ttl = 5; | 25 | int cgit_cache_repo_ttl = 5; |
26 | int cgit_cache_dynamic_ttl = 5; | 26 | int cgit_cache_dynamic_ttl = 5; |
27 | int cgit_cache_static_ttl = -1; | 27 | int cgit_cache_static_ttl = -1; |
28 | int cgit_cache_max_create_time = 5; | 28 | int cgit_cache_max_create_time = 5; |
29 | 29 | ||
30 | int cgit_max_msg_len = 60; | 30 | int cgit_max_msg_len = 60; |
31 | 31 | ||
32 | char *cgit_repo_name = NULL; | 32 | char *cgit_repo_name = NULL; |
33 | char *cgit_repo_desc = NULL; | 33 | char *cgit_repo_desc = NULL; |
34 | char *cgit_repo_owner = NULL; | 34 | char *cgit_repo_owner = NULL; |
35 | 35 | ||
36 | int cgit_query_has_symref = 0; | 36 | int cgit_query_has_symref = 0; |
37 | int cgit_query_has_sha1 = 0; | 37 | int cgit_query_has_sha1 = 0; |
38 | 38 | ||
39 | char *cgit_querystring = NULL; | 39 | char *cgit_querystring = NULL; |
40 | char *cgit_query_repo = NULL; | 40 | char *cgit_query_repo = NULL; |
41 | char *cgit_query_page = NULL; | 41 | char *cgit_query_page = NULL; |
42 | char *cgit_query_head = NULL; | 42 | char *cgit_query_head = NULL; |
43 | char *cgit_query_search = NULL; | 43 | char *cgit_query_search = NULL; |
44 | char *cgit_query_sha1 = NULL; | 44 | char *cgit_query_sha1 = NULL; |
45 | char *cgit_query_sha2 = NULL; | 45 | char *cgit_query_sha2 = NULL; |
46 | char *cgit_query_path = NULL; | 46 | char *cgit_query_path = NULL; |
47 | char *cgit_query_name = NULL; | ||
47 | int cgit_query_ofs = 0; | 48 | int cgit_query_ofs = 0; |
48 | 49 | ||
49 | int htmlfd = 0; | 50 | int htmlfd = 0; |
50 | 51 | ||
52 | int chk_zero(int result, char *msg) | ||
53 | { | ||
54 | if (result != 0) | ||
55 | die("%s: %s", msg, strerror(errno)); | ||
56 | return result; | ||
57 | } | ||
58 | |||
59 | int chk_positive(int result, char *msg) | ||
60 | { | ||
61 | if (result <= 0) | ||
62 | die("%s: %s", msg, strerror(errno)); | ||
63 | return result; | ||
64 | } | ||
65 | |||
51 | struct repoinfo *add_repo(const char *url) | 66 | struct repoinfo *add_repo(const char *url) |
52 | { | 67 | { |
53 | struct repoinfo *ret; | 68 | struct repoinfo *ret; |
54 | 69 | ||
55 | if (++cgit_repolist.count > cgit_repolist.length) { | 70 | if (++cgit_repolist.count > cgit_repolist.length) { |
56 | if (cgit_repolist.length == 0) | 71 | if (cgit_repolist.length == 0) |
57 | cgit_repolist.length = 8; | 72 | cgit_repolist.length = 8; |
58 | else | 73 | else |
59 | cgit_repolist.length *= 2; | 74 | cgit_repolist.length *= 2; |
60 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, | 75 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, |
61 | cgit_repolist.length * | 76 | cgit_repolist.length * |
62 | sizeof(struct repoinfo)); | 77 | sizeof(struct repoinfo)); |
63 | } | 78 | } |
64 | 79 | ||
65 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; | 80 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; |
66 | ret->url = xstrdup(url); | 81 | ret->url = xstrdup(url); |
67 | ret->name = ret->url; | 82 | ret->name = ret->url; |
68 | ret->path = NULL; | 83 | ret->path = NULL; |
69 | ret->desc = NULL; | 84 | ret->desc = NULL; |
70 | ret->owner = NULL; | 85 | ret->owner = NULL; |
71 | return ret; | 86 | return ret; |
72 | } | 87 | } |
73 | 88 | ||
74 | void cgit_global_config_cb(const char *name, const char *value) | 89 | void cgit_global_config_cb(const char *name, const char *value) |
75 | { | 90 | { |
76 | if (!strcmp(name, "root-title")) | 91 | if (!strcmp(name, "root-title")) |
77 | cgit_root_title = xstrdup(value); | 92 | cgit_root_title = xstrdup(value); |
78 | else if (!strcmp(name, "css")) | 93 | else if (!strcmp(name, "css")) |
79 | cgit_css = xstrdup(value); | 94 | cgit_css = xstrdup(value); |
80 | else if (!strcmp(name, "logo")) | 95 | else if (!strcmp(name, "logo")) |
81 | cgit_logo = xstrdup(value); | 96 | cgit_logo = xstrdup(value); |
82 | else if (!strcmp(name, "logo-link")) | 97 | else if (!strcmp(name, "logo-link")) |
83 | cgit_logo_link = xstrdup(value); | 98 | cgit_logo_link = xstrdup(value); |
84 | else if (!strcmp(name, "virtual-root")) | 99 | else if (!strcmp(name, "virtual-root")) |
85 | cgit_virtual_root = xstrdup(value); | 100 | cgit_virtual_root = xstrdup(value); |
86 | else if (!strcmp(name, "nocache")) | 101 | else if (!strcmp(name, "nocache")) |
87 | cgit_nocache = atoi(value); | 102 | cgit_nocache = atoi(value); |
88 | else if (!strcmp(name, "cache-root")) | 103 | else if (!strcmp(name, "cache-root")) |
89 | cgit_cache_root = xstrdup(value); | 104 | cgit_cache_root = xstrdup(value); |
90 | else if (!strcmp(name, "cache-root-ttl")) | 105 | else if (!strcmp(name, "cache-root-ttl")) |
91 | cgit_cache_root_ttl = atoi(value); | 106 | cgit_cache_root_ttl = atoi(value); |
92 | else if (!strcmp(name, "cache-repo-ttl")) | 107 | else if (!strcmp(name, "cache-repo-ttl")) |
93 | cgit_cache_repo_ttl = atoi(value); | 108 | cgit_cache_repo_ttl = atoi(value); |
94 | else if (!strcmp(name, "cache-static-ttl")) | 109 | else if (!strcmp(name, "cache-static-ttl")) |
95 | cgit_cache_static_ttl = atoi(value); | 110 | cgit_cache_static_ttl = atoi(value); |
96 | else if (!strcmp(name, "cache-dynamic-ttl")) | 111 | else if (!strcmp(name, "cache-dynamic-ttl")) |
97 | cgit_cache_dynamic_ttl = atoi(value); | 112 | cgit_cache_dynamic_ttl = atoi(value); |
98 | else if (!strcmp(name, "max-message-length")) | 113 | else if (!strcmp(name, "max-message-length")) |
99 | cgit_max_msg_len = atoi(value); | 114 | cgit_max_msg_len = atoi(value); |
100 | else if (!strcmp(name, "repo.url")) | 115 | else if (!strcmp(name, "repo.url")) |
101 | cgit_repo = add_repo(value); | 116 | cgit_repo = add_repo(value); |
102 | else if (!strcmp(name, "repo.name")) | 117 | else if (!strcmp(name, "repo.name")) |
103 | cgit_repo->name = xstrdup(value); | 118 | cgit_repo->name = xstrdup(value); |
104 | else if (cgit_repo && !strcmp(name, "repo.path")) | 119 | else if (cgit_repo && !strcmp(name, "repo.path")) |
105 | cgit_repo->path = xstrdup(value); | 120 | cgit_repo->path = xstrdup(value); |
106 | else if (cgit_repo && !strcmp(name, "repo.desc")) | 121 | else if (cgit_repo && !strcmp(name, "repo.desc")) |
107 | cgit_repo->desc = xstrdup(value); | 122 | cgit_repo->desc = xstrdup(value); |
108 | else if (cgit_repo && !strcmp(name, "repo.owner")) | 123 | else if (cgit_repo && !strcmp(name, "repo.owner")) |
109 | cgit_repo->owner = xstrdup(value); | 124 | cgit_repo->owner = xstrdup(value); |
110 | } | 125 | } |
111 | 126 | ||
112 | void cgit_repo_config_cb(const char *name, const char *value) | 127 | void cgit_repo_config_cb(const char *name, const char *value) |
113 | { | 128 | { |
114 | if (!strcmp(name, "name")) | 129 | if (!strcmp(name, "name")) |
115 | cgit_repo_name = xstrdup(value); | 130 | cgit_repo_name = xstrdup(value); |
116 | else if (!strcmp(name, "desc")) | 131 | else if (!strcmp(name, "desc")) |
117 | cgit_repo_desc = xstrdup(value); | 132 | cgit_repo_desc = xstrdup(value); |
118 | else if (!strcmp(name, "owner")) | 133 | else if (!strcmp(name, "owner")) |
119 | cgit_repo_owner = xstrdup(value); | 134 | cgit_repo_owner = xstrdup(value); |
120 | } | 135 | } |
121 | 136 | ||
122 | void cgit_querystring_cb(const char *name, const char *value) | 137 | void cgit_querystring_cb(const char *name, const char *value) |
123 | { | 138 | { |
124 | if (!strcmp(name,"r")) { | 139 | if (!strcmp(name,"r")) { |
125 | cgit_query_repo = xstrdup(value); | 140 | cgit_query_repo = xstrdup(value); |
126 | } else if (!strcmp(name, "p")) { | 141 | } else if (!strcmp(name, "p")) { |
127 | cgit_query_page = xstrdup(value); | 142 | cgit_query_page = xstrdup(value); |
128 | } else if (!strcmp(name, "q")) { | 143 | } else if (!strcmp(name, "q")) { |
129 | cgit_query_search = xstrdup(value); | 144 | cgit_query_search = xstrdup(value); |
130 | } else if (!strcmp(name, "h")) { | 145 | } else if (!strcmp(name, "h")) { |
131 | cgit_query_head = xstrdup(value); | 146 | cgit_query_head = xstrdup(value); |
132 | cgit_query_has_symref = 1; | 147 | cgit_query_has_symref = 1; |
133 | } else if (!strcmp(name, "id")) { | 148 | } else if (!strcmp(name, "id")) { |
134 | cgit_query_sha1 = xstrdup(value); | 149 | cgit_query_sha1 = xstrdup(value); |
135 | cgit_query_has_sha1 = 1; | 150 | cgit_query_has_sha1 = 1; |
136 | } else if (!strcmp(name, "id2")) { | 151 | } else if (!strcmp(name, "id2")) { |
137 | cgit_query_sha2 = xstrdup(value); | 152 | cgit_query_sha2 = xstrdup(value); |
138 | cgit_query_has_sha1 = 1; | 153 | cgit_query_has_sha1 = 1; |
139 | } else if (!strcmp(name, "ofs")) { | 154 | } else if (!strcmp(name, "ofs")) { |
140 | cgit_query_ofs = atoi(value); | 155 | cgit_query_ofs = atoi(value); |
141 | } else if (!strcmp(name, "path")) { | 156 | } else if (!strcmp(name, "path")) { |
142 | cgit_query_path = xstrdup(value); | 157 | cgit_query_path = xstrdup(value); |
158 | } else if (!strcmp(name, "name")) { | ||
159 | cgit_query_name = xstrdup(value); | ||
143 | } | 160 | } |
144 | } | 161 | } |
145 | 162 | ||
146 | void *cgit_free_commitinfo(struct commitinfo *info) | 163 | void *cgit_free_commitinfo(struct commitinfo *info) |
147 | { | 164 | { |
148 | free(info->author); | 165 | free(info->author); |
149 | free(info->author_email); | 166 | free(info->author_email); |
150 | free(info->committer); | 167 | free(info->committer); |
151 | free(info->committer_email); | 168 | free(info->committer_email); |
152 | free(info->subject); | 169 | free(info->subject); |
153 | free(info); | 170 | free(info); |
154 | return NULL; | 171 | return NULL; |
155 | } | 172 | } |
156 | 173 | ||
157 | int hextoint(char c) | 174 | int hextoint(char c) |
158 | { | 175 | { |
159 | if (c >= 'a' && c <= 'f') | 176 | if (c >= 'a' && c <= 'f') |
160 | return 10 + c - 'a'; | 177 | return 10 + c - 'a'; |
161 | else if (c >= 'A' && c <= 'F') | 178 | else if (c >= 'A' && c <= 'F') |
162 | return 10 + c - 'A'; | 179 | return 10 + c - 'A'; |
163 | else if (c >= '0' && c <= '9') | 180 | else if (c >= '0' && c <= '9') |
164 | return c - '0'; | 181 | return c - '0'; |
165 | else | 182 | else |
166 | return -1; | 183 | return -1; |
167 | } | 184 | } |
168 | 185 | ||