Diffstat (limited to 'parsing.c')
| -rw-r--r-- | parsing.c | 27 |
1 files changed, 13 insertions, 14 deletions
@@ -6,8 +6,6 @@ * (see COPYING for full license text) */ -#define USE_THE_REPOSITORY_VARIABLE - #include "cgit.h" /* @@ -19,25 +17,24 @@ */ void cgit_parse_url(const char *url) { - char *c, *cmd, *p, *buf; + char *c, *cmd, *p; struct cgit_repo *repo; + ctx.repo = NULL; if (!url || url[0] == '\0') return; - ctx.qry.page = NULL; ctx.repo = cgit_get_repoinfo(url); if (ctx.repo) { ctx.qry.repo = ctx.repo->url; return; } - buf = xstrdup(url); cmd = NULL; - c = strchr(buf, '/'); + c = strchr(url, '/'); while (c) { c[0] = '\0'; - repo = cgit_get_repoinfo(buf); + repo = cgit_get_repoinfo(url); if (repo) { ctx.repo = repo; cmd = c; @@ -56,8 +53,8 @@ void cgit_parse_url(const char *url) } if (cmd[1]) ctx.qry.page = xstrdup(cmd + 1); + return; } - free(buf); } static char *substr(const char *head, const char *tail) @@ -67,7 +64,8 @@ static char *substr(const char *head, const char *tail) if (tail < head) return xstrdup(""); buf = xmalloc(tail - head + 1); - strlcpy(buf, head, tail - head + 1); + strncpy(buf, head, tail - head); + buf[tail - head] = '\0'; return buf; } @@ -81,7 +79,7 @@ static void parse_user(const char *t, char **name, char **email, unsigned long * email_len = ident.mail_end - ident.mail_begin; *email = xmalloc(strlen("<") + email_len + strlen(">") + 1); - xsnprintf(*email, email_len + 3, "<%.*s>", email_len, ident.mail_begin); + sprintf(*email, "<%.*s>", email_len, ident.mail_begin); if (ident.date_begin) *date = strtoul(ident.date_begin, NULL, 10); @@ -131,8 +129,9 @@ static int end_of_header(const char *p) struct commitinfo *cgit_parse_commit(struct commit *commit) { + const int sha1hex_len = 40; struct commitinfo *ret; - const char *p = repo_get_commit_buffer(the_repository, commit, NULL); + const char *p = get_cached_commit_buffer(commit, NULL); const char *t; ret = xcalloc(1, sizeof(struct commitinfo)); @@ -143,10 +142,10 @@ struct commitinfo *cgit_parse_commit(struct commit *commit) if (!skip_prefix(p, "tree ", &p)) die("Bad commit: %s", oid_to_hex(&commit->object.oid)); - p += the_hash_algo->hexsz + 1; + p += sha1hex_len + 1; while (skip_prefix(p, "parent ", &p)) - p += the_hash_algo->hexsz + 1; + p += sha1hex_len + 1; if (p && skip_prefix(p, "author ", &p)) { parse_user(p, &ret->author, &ret->author_email, @@ -202,7 +201,7 @@ struct taginfo *cgit_parse_tag(struct tag *tag) const char *p; struct taginfo *ret = NULL; - data = odb_read_object(the_repository->objects, &tag->object.oid, &type, &size); + data = read_sha1_file(tag->object.oid.hash, &type, &size); if (!data || type != OBJ_TAG) goto cleanup; |