Author: Lars Hjemli <hjemli@gmail.com>
Add function cgit_parse_tag() Teach cgit how to extract author info from a tag. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
cgit.h | 8 ++++++++ parsing.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
diff --git a/cgit.h b/cgit.h index 5e19b117b3fd5c42da99d3e938f37fd53db2fc98..9b517a78d58a85be86373267f3dbcdf291f81391 100644 --- a/cgit.h +++ b/cgit.h @@ -27,6 +27,13 @@ char *subject; char *msg; }; +struct taginfo { + char *tagger; + char *tagger_email; + int tagger_date; + char *msg; +}; + extern const char cgit_version[]; extern char *cgit_root; @@ -87,6 +94,7 @@ extern int cgit_read_config(const char *filename, configfn fn); extern int cgit_parse_query(char *txt, configfn fn); extern struct commitinfo *cgit_parse_commit(struct commit *commit); +extern struct taginfo *cgit_parse_tag(struct tag *tag); extern char *cache_safe_filename(const char *unsafe); extern int cache_lock(struct cacheitem *item); diff --git a/parsing.c b/parsing.c index 4412dee7fcf398945a3161b5d98f733d1282b491..8aad1dd39ee531713a19fb902dbcacf2a77ccfa9 100644 --- a/parsing.c +++ b/parsing.c @@ -196,3 +196,50 @@ ret->msg = p; } return ret; } + + +struct taginfo *cgit_parse_tag(struct tag *tag) +{ + void *data; + char type[20]; + unsigned long size; + char *p, *t; + struct taginfo *ret; + + data = read_sha1_file(tag->object.sha1, type, &size); + if (!data || strcmp(type, tag_type)) { + free(data); + return 0; + } + + ret = xmalloc(sizeof(*ret)); + ret->tagger = NULL; + ret->tagger_email = NULL; + ret->tagger_date = 0; + ret->msg = NULL; + + p = data; + + while (p) { + if (*p == '\n') + break; + + if (!strncmp(p, "tagger ", 7)) { + p += 7; + t = strchr(p, '<') - 1; + ret->tagger = substr(p, t); + p = t; + t = strchr(t, '>') + 1; + ret->tagger_email = substr(p, t); + ret->tagger_date = atol(++t); + } + p = strchr(p, '\n') + 1; + } + + while (p && (*p == '\n')) + p = strchr(p, '\n') + 1; + if (p) + ret->msg = xstrdup(p); + free(data); + return ret; +}