diff options
| author | 2006-12-12 01:04:19 (JST) | |
|---|---|---|
| committer | 2006-12-12 01:04:19 (JST) | |
| commit | d14c5f6d3ac827e7b46831c4151638ab4b638ae1 (patch) | |
| tree | d6592747d098d2fb2ca7a0e653984256ac9ac1a5 /ui-log.c | |
| parent | 1418034e642fee67c981b31e4c3eb6e8ae14e303 (diff) | |
| download | cgit-d14c5f6d3ac827e7b46831c4151638ab4b638ae1.zip cgit-d14c5f6d3ac827e7b46831c4151638ab4b638ae1.tar.gz | |
Move log-functions into ui-log.c
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'ui-log.c')
| -rw-r--r-- | ui-log.c | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/ui-log.c b/ui-log.c new file mode 100644 index 0000000..701c392 --- /dev/null +++ b/ui-log.c | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | /* ui-log.c: functions for log output | ||
| 2 | * | ||
| 3 | * Copyright (C) 2006 Lars Hjemli | ||
| 4 | * | ||
| 5 | * Licensed under GNU General Public License v2 | ||
| 6 | * (see COPYING for full license text) | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include "cgit.h" | ||
| 10 | |||
| 11 | static int get_one_line(char *txt) | ||
| 12 | { | ||
| 13 | char *t; | ||
| 14 | |||
| 15 | for(t=txt; *t != '\n' && t != '\0'; t++) | ||
| 16 | ; | ||
| 17 | *t = '\0'; | ||
| 18 | return t-txt-1; | ||
| 19 | } | ||
| 20 | |||
| 21 | static void cgit_print_commit_shortlog(struct commit *commit) | ||
| 22 | { | ||
| 23 | char *h, *t, *p; | ||
| 24 | char *tree = NULL, *author = NULL, *subject = NULL; | ||
| 25 | int len; | ||
| 26 | time_t sec; | ||
| 27 | struct tm *time; | ||
| 28 | char buf[32]; | ||
| 29 | |||
| 30 | h = t = commit->buffer; | ||
| 31 | |||
| 32 | if (strncmp(h, "tree ", 5)) | ||
| 33 | die("Bad commit format: %s", | ||
| 34 | sha1_to_hex(commit->object.sha1)); | ||
| 35 | |||
| 36 | len = get_one_line(h); | ||
| 37 | tree = h+5; | ||
| 38 | h += len + 2; | ||
| 39 | |||
| 40 | while (!strncmp(h, "parent ", 7)) | ||
| 41 | h += get_one_line(h) + 2; | ||
| 42 | |||
| 43 | if (!strncmp(h, "author ", 7)) { | ||
| 44 | author = h+7; | ||
| 45 | h += get_one_line(h) + 2; | ||
| 46 | t = author; | ||
| 47 | while(t!=h && *t!='<') | ||
| 48 | t++; | ||
| 49 | *t='\0'; | ||
| 50 | p = t; | ||
| 51 | while(--t!=author && *t==' ') | ||
| 52 | *t='\0'; | ||
| 53 | while(++p!=h && *p!='>') | ||
| 54 | ; | ||
| 55 | while(++p!=h && !isdigit(*p)) | ||
| 56 | ; | ||
| 57 | |||
| 58 | t = p; | ||
| 59 | while(++p && isdigit(*p)) | ||
| 60 | ; | ||
| 61 | *p = '\0'; | ||
| 62 | sec = atoi(t); | ||
| 63 | time = gmtime(&sec); | ||
| 64 | } | ||
| 65 | |||
| 66 | while((len = get_one_line(h)) > 0) | ||
| 67 | h += len+2; | ||
| 68 | |||
| 69 | h++; | ||
| 70 | len = get_one_line(h); | ||
| 71 | |||
| 72 | subject = h; | ||
| 73 | |||
| 74 | html("<tr><td>"); | ||
| 75 | strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", time); | ||
| 76 | html_txt(buf); | ||
| 77 | html("</td><td>"); | ||
| 78 | char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1)); | ||
| 79 | char *url = cgit_pageurl(cgit_query_repo, "view", qry); | ||
| 80 | html_link_open(url, NULL, NULL); | ||
| 81 | html_txt(subject); | ||
| 82 | html_link_close(); | ||
| 83 | html("</td><td>"); | ||
| 84 | html_txt(author); | ||
| 85 | html("</td></tr>\n"); | ||
| 86 | } | ||
| 87 | |||
| 88 | void cgit_print_log(const char *tip, int ofs, int cnt) | ||
| 89 | { | ||
| 90 | struct rev_info rev; | ||
| 91 | struct commit *commit; | ||
| 92 | const char *argv[2] = {NULL, tip}; | ||
| 93 | int n = 0; | ||
| 94 | |||
| 95 | init_revisions(&rev, NULL); | ||
| 96 | rev.abbrev = DEFAULT_ABBREV; | ||
| 97 | rev.commit_format = CMIT_FMT_DEFAULT; | ||
| 98 | rev.verbose_header = 1; | ||
| 99 | rev.show_root_diff = 0; | ||
| 100 | setup_revisions(2, argv, &rev, NULL); | ||
| 101 | prepare_revision_walk(&rev); | ||
| 102 | |||
| 103 | html("<h2>Log</h2>"); | ||
| 104 | html("<table class='list'>"); | ||
| 105 | html("<tr><th>Date</th><th>Message</th><th>Author</th></tr>\n"); | ||
| 106 | while ((commit = get_revision(&rev)) != NULL && n++ < 100) { | ||
| 107 | cgit_print_commit_shortlog(commit); | ||
| 108 | free(commit->buffer); | ||
| 109 | commit->buffer = NULL; | ||
| 110 | free_commit_list(commit->parents); | ||
| 111 | commit->parents = NULL; | ||
| 112 | } | ||
| 113 | html("</table>\n"); | ||
| 114 | } | ||
| 115 | |||
