author | Ondrej Jirman <ondrej.jirman@zonio.net> | 2007-05-26 00:19:38 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-05-31 08:21:50 (UTC) |
commit | 3ce6fc16ef4670c535c6e35d48c7f980ff8a5532 (patch) (unidiff) | |
tree | 7a3359b2e2488f0eaf350ba6a5e7865bbbabc969 | |
parent | 1a63cfcc3d83919e790e7e279eb35fc75adb0e3c (diff) | |
download | cgit-3ce6fc16ef4670c535c6e35d48c7f980ff8a5532.zip cgit-3ce6fc16ef4670c535c6e35d48c7f980ff8a5532.tar.gz cgit-3ce6fc16ef4670c535c6e35d48c7f980ff8a5532.tar.bz2 |
Handle single-line and empty commit subjects
If commit object ends with \0 after subject line, then info->subject
was not set.
This commit fixes this and also sets subject to ** empty ** if it
would otherwise be empty, so that there is something to click on.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | parsing.c | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -189,104 +189,109 @@ char *substr(const char *head, const char *tail) | |||
189 | struct commitinfo *cgit_parse_commit(struct commit *commit) | 189 | struct commitinfo *cgit_parse_commit(struct commit *commit) |
190 | { | 190 | { |
191 | struct commitinfo *ret; | 191 | struct commitinfo *ret; |
192 | char *p = commit->buffer, *t = commit->buffer; | 192 | char *p = commit->buffer, *t = commit->buffer; |
193 | 193 | ||
194 | ret = xmalloc(sizeof(*ret)); | 194 | ret = xmalloc(sizeof(*ret)); |
195 | ret->commit = commit; | 195 | ret->commit = commit; |
196 | ret->author = NULL; | 196 | ret->author = NULL; |
197 | ret->author_email = NULL; | 197 | ret->author_email = NULL; |
198 | ret->committer = NULL; | 198 | ret->committer = NULL; |
199 | ret->committer_email = NULL; | 199 | ret->committer_email = NULL; |
200 | ret->subject = NULL; | 200 | ret->subject = NULL; |
201 | ret->msg = NULL; | 201 | ret->msg = NULL; |
202 | 202 | ||
203 | if (strncmp(p, "tree ", 5)) | 203 | if (strncmp(p, "tree ", 5)) |
204 | die("Bad commit: %s", sha1_to_hex(commit->object.sha1)); | 204 | die("Bad commit: %s", sha1_to_hex(commit->object.sha1)); |
205 | else | 205 | else |
206 | p += 46; // "tree " + hex[40] + "\n" | 206 | p += 46; // "tree " + hex[40] + "\n" |
207 | 207 | ||
208 | while (!strncmp(p, "parent ", 7)) | 208 | while (!strncmp(p, "parent ", 7)) |
209 | p += 48; // "parent " + hex[40] + "\n" | 209 | p += 48; // "parent " + hex[40] + "\n" |
210 | 210 | ||
211 | if (!strncmp(p, "author ", 7)) { | 211 | if (!strncmp(p, "author ", 7)) { |
212 | p += 7; | 212 | p += 7; |
213 | t = strchr(p, '<') - 1; | 213 | t = strchr(p, '<') - 1; |
214 | ret->author = substr(p, t); | 214 | ret->author = substr(p, t); |
215 | p = t; | 215 | p = t; |
216 | t = strchr(t, '>') + 1; | 216 | t = strchr(t, '>') + 1; |
217 | ret->author_email = substr(p, t); | 217 | ret->author_email = substr(p, t); |
218 | ret->author_date = atol(++t); | 218 | ret->author_date = atol(++t); |
219 | p = strchr(t, '\n') + 1; | 219 | p = strchr(t, '\n') + 1; |
220 | } | 220 | } |
221 | 221 | ||
222 | if (!strncmp(p, "committer ", 9)) { | 222 | if (!strncmp(p, "committer ", 9)) { |
223 | p += 9; | 223 | p += 9; |
224 | t = strchr(p, '<') - 1; | 224 | t = strchr(p, '<') - 1; |
225 | ret->committer = substr(p, t); | 225 | ret->committer = substr(p, t); |
226 | p = t; | 226 | p = t; |
227 | t = strchr(t, '>') + 1; | 227 | t = strchr(t, '>') + 1; |
228 | ret->committer_email = substr(p, t); | 228 | ret->committer_email = substr(p, t); |
229 | ret->committer_date = atol(++t); | 229 | ret->committer_date = atol(++t); |
230 | p = strchr(t, '\n') + 1; | 230 | p = strchr(t, '\n') + 1; |
231 | } | 231 | } |
232 | 232 | ||
233 | while (*p == '\n') | 233 | while (*p == '\n') |
234 | p = strchr(p, '\n') + 1; | 234 | p = strchr(p, '\n') + 1; |
235 | 235 | ||
236 | t = strchr(p, '\n'); | 236 | t = strchr(p, '\n'); |
237 | if (t && *t) { | 237 | if (t) { |
238 | ret->subject = substr(p, t); | 238 | if (*t == '\0') |
239 | ret->subject = strdup("** empty **"); | ||
240 | else | ||
241 | ret->subject = substr(p, t); | ||
239 | p = t + 1; | 242 | p = t + 1; |
240 | 243 | ||
241 | while (*p == '\n') | 244 | while (*p == '\n') |
242 | p = strchr(p, '\n') + 1; | 245 | p = strchr(p, '\n') + 1; |
243 | ret->msg = p; | 246 | ret->msg = p; |
244 | } | 247 | } else |
248 | ret->subject = substr(p, p+strlen(p)); | ||
249 | |||
245 | return ret; | 250 | return ret; |
246 | } | 251 | } |
247 | 252 | ||
248 | 253 | ||
249 | struct taginfo *cgit_parse_tag(struct tag *tag) | 254 | struct taginfo *cgit_parse_tag(struct tag *tag) |
250 | { | 255 | { |
251 | void *data; | 256 | void *data; |
252 | enum object_type type; | 257 | enum object_type type; |
253 | unsigned long size; | 258 | unsigned long size; |
254 | char *p, *t; | 259 | char *p, *t; |
255 | struct taginfo *ret; | 260 | struct taginfo *ret; |
256 | 261 | ||
257 | data = read_sha1_file(tag->object.sha1, &type, &size); | 262 | data = read_sha1_file(tag->object.sha1, &type, &size); |
258 | if (!data || type != OBJ_TAG) { | 263 | if (!data || type != OBJ_TAG) { |
259 | free(data); | 264 | free(data); |
260 | return 0; | 265 | return 0; |
261 | } | 266 | } |
262 | 267 | ||
263 | ret = xmalloc(sizeof(*ret)); | 268 | ret = xmalloc(sizeof(*ret)); |
264 | ret->tagger = NULL; | 269 | ret->tagger = NULL; |
265 | ret->tagger_email = NULL; | 270 | ret->tagger_email = NULL; |
266 | ret->tagger_date = 0; | 271 | ret->tagger_date = 0; |
267 | ret->msg = NULL; | 272 | ret->msg = NULL; |
268 | 273 | ||
269 | p = data; | 274 | p = data; |
270 | 275 | ||
271 | while (p && *p) { | 276 | while (p && *p) { |
272 | if (*p == '\n') | 277 | if (*p == '\n') |
273 | break; | 278 | break; |
274 | 279 | ||
275 | if (!strncmp(p, "tagger ", 7)) { | 280 | if (!strncmp(p, "tagger ", 7)) { |
276 | p += 7; | 281 | p += 7; |
277 | t = strchr(p, '<') - 1; | 282 | t = strchr(p, '<') - 1; |
278 | ret->tagger = substr(p, t); | 283 | ret->tagger = substr(p, t); |
279 | p = t; | 284 | p = t; |
280 | t = strchr(t, '>') + 1; | 285 | t = strchr(t, '>') + 1; |
281 | ret->tagger_email = substr(p, t); | 286 | ret->tagger_email = substr(p, t); |
282 | ret->tagger_date = atol(++t); | 287 | ret->tagger_date = atol(++t); |
283 | } | 288 | } |
284 | p = strchr(p, '\n') + 1; | 289 | p = strchr(p, '\n') + 1; |
285 | } | 290 | } |
286 | 291 | ||
287 | while (p && (*p == '\n')) | 292 | while (p && (*p == '\n')) |
288 | p = strchr(p, '\n') + 1; | 293 | p = strchr(p, '\n') + 1; |
289 | if (p && *p) | 294 | if (p && *p) |
290 | ret->msg = xstrdup(p); | 295 | ret->msg = xstrdup(p); |
291 | free(data); | 296 | free(data); |
292 | return ret; | 297 | return ret; |