diff options
Diffstat (limited to 'ui-shared.c')
-rw-r--r-- | ui-shared.c | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c index e39d004..05b613e 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -349,13 +349,61 @@ void cgit_log_link(const char *name, const char *title, const char *class, void cgit_commit_link(char *name, const char *title, const char *class, const char *head, const char *rev, const char *path) { + cgit_commit_link2(name, title, class, head, rev, path, false); +} + +void cgit_commit_link2(char *name, const char *title, const char *class, + const char *head, const char *rev, const char *path, bool checkForIssueLink) +{ if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { name[ctx.cfg.max_msg_len] = '\0'; name[ctx.cfg.max_msg_len - 1] = '.'; name[ctx.cfg.max_msg_len - 2] = '.'; name[ctx.cfg.max_msg_len - 3] = '.'; } + if (checkForIssueLink) { + int last_match = 0; + int offset = 0; + for (;;) { + const char* sub = strstr(name + last_match + offset, ISSUE_MARKER); + if (sub) { + int found_pos = (sub - (name + last_match)); + sub += STRLEN_ISSUE_MARKER; + int numbercount = 0; + while (*sub >= '0' && *sub <= '9') { + numbercount++; + sub++; + } + if (!numbercount) { + offset = found_pos + STRLEN_ISSUE_MARKER; + continue; + } else { + offset = 0; + } + if (found_pos > 0) { + char* left_part = sub_str(name, last_match, last_match + found_pos); + cgit_commit_link3(left_part, title, class, head, rev, path); + free(left_part); + } + char* issue_part = sub_str(name, last_match + found_pos, last_match + found_pos + STRLEN_ISSUE_MARKER + numbercount); + cgit_issue_link(issue_part, "FS-link"); + free(issue_part); + last_match += found_pos + STRLEN_ISSUE_MARKER + numbercount; + } else { + if (strlen(name + last_match)) { + cgit_commit_link3(name + last_match, title, class, head, rev, path); + } + break; + } + } + } else { + cgit_commit_link3(name, title, class, head, rev, path); + } +} +void cgit_commit_link3(char *name, const char *title, const char *class, + const char *head, const char *rev, const char *path) +{ char *delim; delim = repolink(title, class, "commit", head, path); @@ -1109,3 +1157,73 @@ void cgit_print_snapshot_links(const char *repo, const char *head, } strbuf_release(&filename); } + +extern void cgit_author_link(const char *author, const char *head) +{ + char *delim; + + delim = repolink(NULL, NULL, "log", head ? head : ctx.qry.head, NULL); + html(delim); + html("qt=author&q="); + html_url_arg(author); + html("'>"); + html_txt(author); + html("</a>"); +} + +extern void cgit_check_text_for_issue_link(const char* text) +{ + int last_match = 0; + int offset = 0; + for (;;) { + const char* sub = strstr(text + last_match + offset, ISSUE_MARKER); + if(sub) { + int found_pos = (sub - (text + last_match)); + sub += STRLEN_ISSUE_MARKER; + int numbercount = 0; + while (*sub >= '0' && *sub <= '9') { + numbercount++; + sub++; + } + if (!numbercount) { + offset = found_pos + STRLEN_ISSUE_MARKER; + continue; + } else { + offset = 0; + } + if (found_pos > 0) { + char* left_part = sub_str(text, last_match, last_match + found_pos); + html_txt(left_part); + free(left_part); + } + char* issue_part = sub_str(text, last_match + found_pos, last_match + found_pos + STRLEN_ISSUE_MARKER + numbercount); + cgit_issue_link(issue_part, NULL); + free(issue_part); + last_match += found_pos + STRLEN_ISSUE_MARKER + numbercount; + } else { + if (strlen(text + last_match)) { + html_txt(text + last_match); + } + break; + } + } +} + +extern void cgit_issue_link(const char* issue, const char* class) +{ + html("<a href='"); + htmlf(ctx.cfg.issue_link); + if (strlen(issue) > 3) { + html(issue + 3); + } + html("'"); + if (class) { + html(" class='"); + html(class); + html("'"); + } + html(" target='_blank'"); + html(">"); + html_txt(issue); + html("</a>"); +} |