summaryrefslogtreecommitdiffstatshomepage
path: root/ui-shared.h
blob: bff482604428c201e3a3c4c2d07d2642923a23f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef UI_SHARED_H
#define UI_SHARED_H

extern char *cgit_httpscheme();
extern char *cgit_hosturl();
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 void cgit_index_link(char *name, char *title, char *class,
			    char *pattern, int ofs);
extern void cgit_summary_link(char *name, char *title, char *class, char *head);
extern void cgit_tag_link(char *name, char *title, char *class, char *head,
			  char *rev);
extern void cgit_tree_link(char *name, char *title, char *class, char *head,
			   char *rev, char *path);
extern void cgit_plain_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 *grep,
			  char *pattern, int showmsg);
extern void cgit_commit_link(char *name, char *title, char *class, char *head,
			     char *rev);
extern void cgit_patch_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_stats_link(char *name, char *title, char *class, char *head,
			    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, int local_time);
extern void cgit_print_age(time_t t, time_t max_relative, char *format);
extern void cgit_print_http_headers(struct cgit_context *ctx);
extern void cgit_print_docstart(struct cgit_context *ctx);
extern void cgit_print_docend();
extern void cgit_print_pageheader(struct cgit_context *ctx);
extern void cgit_print_filemode(unsigned short mode);
extern void cgit_print_snapshot_links(const char *repo, const char *head,
				      const char *hex, int snapshots);
extern void cgit_add_hidden_formfields(int incl_head, int incl_search,
				       char *page);
#endif /* UI_SHARED_H */
ss="p">] == '/' ? "" : "/"); ctx.page.etag = sha1_to_hex(sha1); cgit_print_http_headers(); htmlf("<html><head><title>%s", slash); html_txt(fullpath); htmlf("</title></head>\n<body>\n<h2>%s", slash); html_txt(fullpath); html("</h2>\n<ul>\n"); len = strlen(fullpath); if (len > 1) { fullpath[len - 1] = 0; slash = strrchr(fullpath, '/'); if (slash) *(slash + 1) = 0; else { free(fullpath); fullpath = NULL; } html("<li>"); cgit_plain_link("../", NULL, NULL, ctx.qry.head, ctx.qry.sha1, fullpath); html("</li>\n"); } free(fullpath); } static void print_dir_entry(const unsigned char *sha1, const char *base, int baselen, const char *path, unsigned mode) { char *fullpath; fullpath = buildpath(base, baselen, path); if (!S_ISDIR(mode) && !S_ISGITLINK(mode)) fullpath[strlen(fullpath) - 1] = 0; html(" <li>"); if (S_ISGITLINK(mode)) { cgit_submodule_link(NULL, fullpath, sha1_to_hex(sha1)); } else cgit_plain_link(path, NULL, NULL, ctx.qry.head, ctx.qry.sha1, fullpath); html("</li>\n"); free(fullpath); } static void print_dir_tail(void) { html(" </ul>\n</body></html>\n"); } static int walk_tree(const unsigned char *sha1, struct strbuf *base, const char *pathname, unsigned mode, int stage, void *cbdata) { struct walk_tree_context *walk_tree_ctx = cbdata; if (base->len == walk_tree_ctx->match_baselen) { if (S_ISREG(mode)) { if (print_object(sha1, pathname)) walk_tree_ctx->match = 1; } else if (S_ISDIR(mode)) { print_dir(sha1, base->buf, base->len, pathname); walk_tree_ctx->match = 2; return READ_TREE_RECURSIVE; } } else if (base->len < INT_MAX && (int)base->len > walk_tree_ctx->match_baselen) { print_dir_entry(sha1, base->buf, base->len, pathname, mode); walk_tree_ctx->match = 2; } else if (S_ISDIR(mode)) { return READ_TREE_RECURSIVE; } return 0; } static int basedir_len(const char *path) { char *p = strrchr(path, '/'); if (p) return p - path + 1; return 0; } void cgit_print_plain(void) { const char *rev = ctx.qry.sha1; struct object_id oid; struct commit *commit; struct pathspec_item path_items = { .match = ctx.qry.path, .len = ctx.qry.path ? strlen(ctx.qry.path) : 0 }; struct pathspec paths = { .nr = 1, .items = &path_items }; struct walk_tree_context walk_tree_ctx = { .match = 0 }; if (!rev) rev = ctx.qry.head; if (get_oid(rev, &oid)) { cgit_print_error_page(404, "Not found", "Not found"); return; } commit = lookup_commit_reference(oid.hash); if (!commit || parse_commit(commit)) { cgit_print_error_page(404, "Not found", "Not found"); return; } if (!path_items.match) { path_items.match = ""; walk_tree_ctx.match_baselen = -1; print_dir(commit->tree->object.oid.hash, "", 0, ""); walk_tree_ctx.match = 2; } else walk_tree_ctx.match_baselen = basedir_len(path_items.match); read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); if (!walk_tree_ctx.match) cgit_print_error_page(404, "Not found", "Not found"); else if (walk_tree_ctx.match == 2) print_dir_tail(); }