author | Lars Hjemli <hjemli@gmail.com> | 2007-11-03 09:42:37 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-11-03 09:42:37 (UTC) |
commit | 51140311bb3b0d4d0e859d5045ffe4c74478f5fe (patch) (side-by-side diff) | |
tree | 6575f174e32abd5f5d1f481e5f7f5978525ae416 | |
parent | df203a293e3ac19245f8761cf7c5808f8735f917 (diff) | |
download | cgit-51140311bb3b0d4d0e859d5045ffe4c74478f5fe.zip cgit-51140311bb3b0d4d0e859d5045ffe4c74478f5fe.tar.gz cgit-51140311bb3b0d4d0e859d5045ffe4c74478f5fe.tar.bz2 |
Add search parameters to cgit_log_link
This makes the [prev] and [next] links work correctly on search results.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.h | 3 | ||||
-rw-r--r-- | ui-log.c | 6 | ||||
-rw-r--r-- | ui-repolist.c | 3 | ||||
-rw-r--r-- | ui-shared.c | 13 | ||||
-rw-r--r-- | ui-summary.c | 2 | ||||
-rw-r--r-- | ui-tree.c | 2 |
6 files changed, 21 insertions, 8 deletions
@@ -193,90 +193,91 @@ extern void *cgit_free_commitinfo(struct commitinfo *info); extern int cgit_diff_files(const unsigned char *old_sha1, const unsigned char *new_sha1, linediff_fn fn); extern void cgit_diff_tree(const unsigned char *old_sha1, const unsigned char *new_sha1, filepair_fn fn, const char *prefix); extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); extern char *fmt(const char *format,...); extern void html(const char *txt); extern void htmlf(const char *format,...); extern void html_txt(char *txt); extern void html_ntxt(int len, char *txt); extern void html_attr(char *txt); extern void html_hidden(char *name, char *value); extern void html_option(char *value, char *text, char *selected_value); extern void html_link_open(char *url, char *title, char *class); extern void html_link_close(void); extern void html_filemode(unsigned short mode); extern int html_include(const char *filename); 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 void cgit_parse_url(const char *url); extern char *cache_safe_filename(const char *unsafe); extern int cache_lock(struct cacheitem *item); extern int cache_unlock(struct cacheitem *item); extern int cache_cancel_lock(struct cacheitem *item); extern int cache_exist(struct cacheitem *item); extern int cache_expired(struct cacheitem *item); extern char *cgit_repourl(const char *reponame); extern char *cgit_fileurl(const char *reponame, const char *pagename, const char *filename, const char *query); extern char *cgit_pageurl(const char *reponame, const char *pagename, const char *query); extern const char *cgit_repobasename(const char *reponame); extern void cgit_tree_link(char *name, char *title, char *class, char *head, char *rev, char *path); extern void cgit_log_link(char *name, char *title, char *class, char *head, - char *rev, char *path, int ofs); + char *rev, char *path, int ofs, char *grep, + char *pattern); extern void cgit_commit_link(char *name, char *title, char *class, char *head, char *rev); extern void cgit_refs_link(char *name, char *title, char *class, char *head, char *rev, char *path); extern void cgit_snapshot_link(char *name, char *title, char *class, char *head, char *rev, char *archivename); extern void cgit_diff_link(char *name, char *title, char *class, char *head, char *new_rev, char *old_rev, char *path); extern void cgit_object_link(struct object *obj); extern void cgit_print_error(char *msg); extern void cgit_print_date(time_t secs, char *format); extern void cgit_print_age(time_t t, time_t max_relative, char *format); extern void cgit_print_docstart(char *title, struct cacheitem *item); extern void cgit_print_docend(); extern void cgit_print_pageheader(char *title, int show_search); extern void cgit_print_snapshot_start(const char *mimetype, const char *filename, struct cacheitem *item); extern void cgit_print_branches(int maxcount); extern void cgit_print_tags(int maxcount); extern void cgit_print_repolist(struct cacheitem *item); extern void cgit_print_summary(); extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, char *path, int pager); extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); extern void cgit_print_tree(const char *rev, char *path); extern void cgit_print_commit(char *hex); extern void cgit_print_refs(); extern void cgit_print_tag(char *revname); extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix); extern void cgit_print_snapshot(struct cacheitem *item, const char *head, const char *hex, const char *prefix, const char *filename, int snapshot); extern void cgit_print_snapshot_links(const char *repo, const char *head, const char *hex, int snapshots); extern int cgit_parse_snapshots_mask(const char *str); #endif /* CGIT_H */ @@ -73,59 +73,61 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern } init_revisions(&rev, NULL); rev.abbrev = DEFAULT_ABBREV; rev.commit_format = CMIT_FMT_DEFAULT; rev.verbose_header = 1; rev.show_root_diff = 0; setup_revisions(argc, argv, &rev, NULL); if (rev.grep_filter) { rev.grep_filter->regflags |= REG_ICASE; compile_grep_patterns(rev.grep_filter); } prepare_revision_walk(&rev); html("<table class='list nowrap'>"); html("<tr class='nohover'><th class='left'>Age</th>" "<th class='left'>Message</th>"); if (cgit_repo->enable_log_filecount) { html("<th class='left'>Files</th>"); if (cgit_repo->enable_log_linecount) html("<th class='left'>Lines</th>"); } html("<th class='left'>Author</th></tr>\n"); if (ofs<0) ofs = 0; for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { free(commit->buffer); commit->buffer = NULL; free_commit_list(commit->parents); commit->parents = NULL; } for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { print_commit(commit); free(commit->buffer); commit->buffer = NULL; free_commit_list(commit->parents); commit->parents = NULL; } html("</table>\n"); if (pager) { html("<div class='pager'>"); if (ofs > 0) { cgit_log_link("[prev]", NULL, NULL, cgit_query_head, cgit_query_sha1, cgit_query_path, - ofs - cnt); + ofs - cnt, cgit_query_grep, + cgit_query_search); html(" "); } if ((commit = get_revision(&rev)) != NULL) { cgit_log_link("[next]", NULL, NULL, cgit_query_head, cgit_query_sha1, cgit_query_path, - ofs + cnt); + ofs + cnt, cgit_query_grep, + cgit_query_search); } html("</div>"); } } diff --git a/ui-repolist.c b/ui-repolist.c index 4c86543..9aa5c1e 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -53,57 +53,58 @@ void cgit_print_repolist(struct cacheitem *item) cgit_print_docstart(cgit_root_title, item); cgit_print_pageheader(cgit_root_title, 0); html("<table class='list nowrap'>"); if (cgit_index_header) { htmlf("<tr class='nohover'><td colspan='%d' class='include-block'>", columns); html_include(cgit_index_header); html("</td></tr>"); } html("<tr class='nohover'>" "<th class='left'>Name</th>" "<th class='left'>Description</th>" "<th class='left'>Owner</th>" "<th class='left'>Idle</th>"); if (cgit_enable_index_links) html("<th>Links</th>"); html("</tr>\n"); for (i=0; i<cgit_repolist.count; i++) { cgit_repo = &cgit_repolist.repos[i]; if ((last_group == NULL && cgit_repo->group != NULL) || (last_group != NULL && cgit_repo->group == NULL) || (last_group != NULL && cgit_repo->group != NULL && strcmp(cgit_repo->group, last_group))) { htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>", columns); html_txt(cgit_repo->group); html("</td></tr>"); last_group = cgit_repo->group; } htmlf("<tr><td class='%s'>", cgit_repo->group ? "sublevel-repo" : "toplevel-repo"); html_link_open(cgit_repourl(cgit_repo->url), NULL, NULL); html_txt(cgit_repo->name); html_link_close(); html("</td><td>"); html_ntxt(cgit_max_repodesc_len, cgit_repo->desc); html("</td><td>"); html_txt(cgit_repo->owner); html("</td><td>"); print_modtime(cgit_repo); html("</td>"); if (cgit_enable_index_links) { html("<td>"); html_link_open(cgit_repourl(cgit_repo->url), NULL, "button"); html("summary</a>"); - cgit_log_link("log", NULL, "button", NULL, NULL, NULL, 0); + cgit_log_link("log", NULL, "button", NULL, NULL, NULL, + 0, NULL, NULL); cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL); html("</td>"); } html("</tr>\n"); } html("</table>"); cgit_print_docend(); } diff --git a/ui-shared.c b/ui-shared.c index 1d66940..a03661a 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -149,107 +149,116 @@ static char *repolink(char *title, char *class, char *page, char *head, html_attr(path); } } else { html(cgit_script_name); html("?url="); html_attr(cgit_repo->url); if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') html("/"); if (page) { html(page); html("/"); if (path) html_attr(path); } delim = "&"; } if (head && strcmp(head, cgit_repo->defbranch)) { html(delim); html("h="); html_attr(head); delim = "&"; } return fmt("%s", delim); } static void reporevlink(char *page, char *name, char *title, char *class, char *head, char *rev, char *path) { char *delim; delim = repolink(title, class, page, head, path); if (rev && strcmp(rev, cgit_query_head)) { html(delim); html("id="); html_attr(rev); } html("'>"); html_txt(name); html("</a>"); } void cgit_tree_link(char *name, char *title, char *class, char *head, char *rev, char *path) { reporevlink("tree", name, title, class, head, rev, path); } void cgit_log_link(char *name, char *title, char *class, char *head, - char *rev, char *path, int ofs) + char *rev, char *path, int ofs, char *grep, char *pattern) { char *delim; delim = repolink(title, class, "log", head, path); if (rev && strcmp(rev, cgit_query_head)) { html(delim); html("id="); html_attr(rev); delim = "&"; } + if (grep && pattern) { + html(delim); + html("qt="); + html_attr(grep); + delim = "&"; + html(delim); + html("q="); + html_attr(pattern); + } if (ofs > 0) { html(delim); html("ofs="); htmlf("%d", ofs); } html("'>"); html_txt(name); html("</a>"); } void cgit_commit_link(char *name, char *title, char *class, char *head, char *rev) { if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { name[cgit_max_msg_len] = '\0'; name[cgit_max_msg_len - 1] = '.'; name[cgit_max_msg_len - 2] = '.'; name[cgit_max_msg_len - 3] = '.'; } reporevlink("commit", name, title, class, head, rev, NULL); } void cgit_refs_link(char *name, char *title, char *class, char *head, char *rev, char *path) { reporevlink("refs", name, title, class, head, rev, path); } void cgit_snapshot_link(char *name, char *title, char *class, char *head, char *rev, char *archivename) { reporevlink("snapshot", name, title, class, head, rev, archivename); } void cgit_diff_link(char *name, char *title, char *class, char *head, char *new_rev, char *old_rev, char *path) { char *delim; delim = repolink(title, class, "diff", head, path); if (new_rev && strcmp(new_rev, cgit_query_head)) { html(delim); html("id="); html_attr(new_rev); delim = "&"; } if (old_rev) { html(delim); @@ -416,97 +425,97 @@ void add_hidden_formfields(int incl_head, int incl_search) { if (!cgit_virtual_root) { if (cgit_query_repo) html_hidden("r", cgit_query_repo); if (cgit_query_page) html_hidden("p", cgit_query_page); } if (incl_head && strcmp(cgit_query_head, cgit_repo->defbranch)) html_hidden("h", cgit_query_head); if (cgit_query_sha1) html_hidden("id", cgit_query_sha1); if (cgit_query_sha2) html_hidden("id2", cgit_query_sha2); if (incl_search) { if (cgit_query_grep) html_hidden("qt", cgit_query_grep); if (cgit_query_search) html_hidden("q", cgit_query_search); } } void cgit_print_pageheader(char *title, int show_search) { static const char *default_info = "This is cgit, a fast webinterface for git repositories"; int header = 0; html("<div id='sidebar'>\n"); html("<a href='"); html_attr(cgit_rooturl()); htmlf("'><div id='logo'><img src='%s' alt='cgit'/></div></a>\n", cgit_logo); html("<div class='infobox'>"); if (cgit_query_repo) { html("<h1>"); html_txt(strrpart(cgit_repo->name, 20)); html("</h1>\n"); html_txt(cgit_repo->desc); if (cgit_repo->owner) { html("<p>\n<h1>owner</h1>\n"); html_txt(cgit_repo->owner); } html("<p>\n<h1>navigate</h1>\n"); reporevlink(NULL, "summary", NULL, "menu", cgit_query_head, NULL, NULL); cgit_log_link("log", NULL, "menu", cgit_query_head, - cgit_query_sha1, cgit_query_path, 0); + cgit_query_sha1, cgit_query_path, 0, NULL, NULL); cgit_tree_link("tree", NULL, "menu", cgit_query_head, cgit_query_sha1, NULL); cgit_commit_link("commit", NULL, "menu", cgit_query_head, cgit_query_sha1); cgit_diff_link("diff", NULL, "menu", cgit_query_head, cgit_query_sha1, cgit_query_sha2, cgit_query_path); for_each_ref(print_archive_ref, &header); html("<p>\n<h1>branch</h1>\n"); html("<form method='get' action=''>\n"); add_hidden_formfields(0, 1); html("<select name='h' onchange='this.form.submit();'>\n"); for_each_branch_ref(print_branch_option, cgit_query_head); html("</select>\n"); html("</form>\n"); html("<p>\n<h1>search</h1>\n"); html("<form method='get' action='"); html_attr(cgit_pageurl(cgit_query_repo, "log", NULL)); html("'>\n"); add_hidden_formfields(1, 0); html("<select name='qt'>\n"); html_option("grep", "log msg", cgit_query_grep); html_option("author", "author", cgit_query_grep); html_option("committer", "committer", cgit_query_grep); html("</select>\n"); html("<input class='txt' type='text' name='q' value='"); html_attr(cgit_query_search); html("'/>\n"); html("</form>\n"); } else { if (!cgit_index_info || html_include(cgit_index_info)) html(default_info); } html("</div>\n"); html("</div>\n<table class='grid'><tr><td id='content'>\n"); } void cgit_print_snapshot_start(const char *mimetype, const char *filename, struct cacheitem *item) { htmlf("Content-Type: %s\n", mimetype); htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); diff --git a/ui-summary.c b/ui-summary.c index 39fe330..c856793 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -11,97 +11,97 @@ static int header; static int cmp_age(int age1, int age2) { if (age1 != 0 && age2 != 0) return age2 - age1; if (age1 == 0 && age2 == 0) return 0; if (age1 == 0) return +1; return -1; } static int cmp_ref_name(const void *a, const void *b) { struct refinfo *r1 = *(struct refinfo **)a; struct refinfo *r2 = *(struct refinfo **)b; return strcmp(r1->refname, r2->refname); } static int cmp_branch_age(const void *a, const void *b) { struct refinfo *r1 = *(struct refinfo **)a; struct refinfo *r2 = *(struct refinfo **)b; return cmp_age(r1->commit->committer_date, r2->commit->committer_date); } static int cmp_tag_age(const void *a, const void *b) { struct refinfo *r1 = *(struct refinfo **)a; struct refinfo *r2 = *(struct refinfo **)b; return cmp_age(r1->tag->tagger_date, r2->tag->tagger_date); } static int print_branch(struct refinfo *ref) { struct commitinfo *info = ref->commit; char *name = (char *)ref->refname; if (!info) return 1; html("<tr><td>"); - cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0); + cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0, NULL, NULL); html("</td><td>"); if (ref->object->type == OBJ_COMMIT) { cgit_print_age(info->commit->date, -1, NULL); html("</td><td>"); html_txt(info->author); html("</td><td>"); cgit_commit_link(info->subject, NULL, NULL, name, NULL); } else { html("</td><td></td><td>"); cgit_object_link(ref->object); } html("</td></tr>\n"); return 0; } static void print_tag_header() { html("<tr class='nohover'><th class='left'>Tag</th>" "<th class='left'>Age</th>" "<th class='left'>Author</th>" "<th class='left'>Reference</th></tr>\n"); header = 1; } static int print_tag(struct refinfo *ref) { struct tag *tag; struct taginfo *info; char *url, *name = (char *)ref->refname; if (ref->object->type == OBJ_TAG) { tag = (struct tag *)ref->object; info = ref->tag; if (!tag || !info) return 1; html("<tr><td>"); url = cgit_pageurl(cgit_query_repo, "tag", fmt("id=%s", name)); html_link_open(url, NULL, NULL); html_txt(name); html_link_close(); html("</td><td>"); if (info->tagger_date > 0) cgit_print_age(info->tagger_date, -1, NULL); html("</td><td>"); if (info->tagger) html(info->tagger); @@ -55,97 +55,97 @@ static void print_object(const unsigned char *sha1, char *path) html_txt(buf + start); html("</td></tr>\n"); html("</table>\n"); } static int ls_item(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned int mode, int stage) { char *name; char *fullpath; enum object_type type; unsigned long size = 0; name = xstrdup(pathname); fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "", cgit_query_path ? "/" : "", name); type = sha1_object_info(sha1, &size); if (type == OBJ_BAD && !S_ISGITLINK(mode)) { htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", name, sha1_to_hex(sha1)); return 0; } html("<tr><td class='ls-mode'>"); html_filemode(mode); html("</td><td>"); if (S_ISGITLINK(mode)) { htmlf("<a class='ls-mod' href='"); html_attr(fmt(cgit_repo->module_link, name, sha1_to_hex(sha1))); html("'>"); html_txt(name); html("</a>"); } else if (S_ISDIR(mode)) { cgit_tree_link(name, NULL, "ls-dir", cgit_query_head, curr_rev, fullpath); } else { cgit_tree_link(name, NULL, "ls-blob", cgit_query_head, curr_rev, fullpath); } htmlf("</td><td class='ls-size'>%li</td>", size); html("<td>"); cgit_log_link("log", NULL, "button", cgit_query_head, curr_rev, - fullpath, 0); + fullpath, 0, NULL, NULL); html("</td></tr>\n"); free(name); return 0; } static void ls_head() { html("<table class='list'>\n"); html("<tr class='nohover'>"); html("<th class='left'>Mode</th>"); html("<th class='left'>Name</th>"); html("<th class='right'>Size</th>"); html("<th/>"); html("</tr>\n"); header = 1; } static void ls_tail() { if (!header) return; html("</table>\n"); header = 0; } static void ls_tree(const unsigned char *sha1, char *path) { struct tree *tree; tree = parse_tree_indirect(sha1); if (!tree) { cgit_print_error(fmt("Not a tree object: %s", sha1_to_hex(sha1))); return; } ls_head(); read_tree_recursive(tree, "", 0, 1, NULL, ls_item); ls_tail(); } static int walk_tree(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage) { static int state; static char buffer[PATH_MAX]; char *url; |