summaryrefslogtreecommitdiffabout
path: root/cgit.c
Unidiff
Diffstat (limited to 'cgit.c') (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/cgit.c b/cgit.c
index 7b7afba..fedf355 100644
--- a/cgit.c
+++ b/cgit.c
@@ -43,101 +43,110 @@ static int cgit_prepare_cache(struct cacheitem *item)
43 } 43 }
44 44
45 if (!cgit_query_page) { 45 if (!cgit_query_page) {
46 item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root, 46 item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root,
47 cgit_repo->url)); 47 cgit_repo->url));
48 item->ttl = cgit_cache_repo_ttl; 48 item->ttl = cgit_cache_repo_ttl;
49 } else { 49 } else {
50 item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, 50 item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root,
51 cgit_repo->url, cgit_query_page, 51 cgit_repo->url, cgit_query_page,
52 cache_safe_filename(cgit_querystring))); 52 cache_safe_filename(cgit_querystring)));
53 if (cgit_query_has_symref) 53 if (cgit_query_has_symref)
54 item->ttl = cgit_cache_dynamic_ttl; 54 item->ttl = cgit_cache_dynamic_ttl;
55 else if (cgit_query_has_sha1) 55 else if (cgit_query_has_sha1)
56 item->ttl = cgit_cache_static_ttl; 56 item->ttl = cgit_cache_static_ttl;
57 else 57 else
58 item->ttl = cgit_cache_repo_ttl; 58 item->ttl = cgit_cache_repo_ttl;
59 } 59 }
60 return 1; 60 return 1;
61} 61}
62 62
63static void cgit_print_repo_page(struct cacheitem *item) 63static void cgit_print_repo_page(struct cacheitem *item)
64{ 64{
65 char *title; 65 char *title;
66 int show_search; 66 int show_search;
67 67
68 if (chdir(cgit_repo->path)) { 68 if (chdir(cgit_repo->path)) {
69 title = fmt("%s - %s", cgit_root_title, "Bad request"); 69 title = fmt("%s - %s", cgit_root_title, "Bad request");
70 cgit_print_docstart(title, item); 70 cgit_print_docstart(title, item);
71 cgit_print_pageheader(title, 0); 71 cgit_print_pageheader(title, 0);
72 cgit_print_error(fmt("Unable to scan repository: %s", 72 cgit_print_error(fmt("Unable to scan repository: %s",
73 strerror(errno))); 73 strerror(errno)));
74 cgit_print_docend(); 74 cgit_print_docend();
75 return; 75 return;
76 } 76 }
77 77
78 title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); 78 title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc);
79 show_search = 0; 79 show_search = 0;
80 setenv("GIT_DIR", cgit_repo->path, 1); 80 setenv("GIT_DIR", cgit_repo->path, 1);
81 81
82 if (cgit_repo->snapshots && cgit_query_page && 82 if (cgit_repo->snapshots && cgit_query_page &&
83 !strcmp(cgit_query_page, "snapshot")) { 83 !strcmp(cgit_query_page, "snapshot")) {
84 cgit_print_snapshot(item, cgit_query_sha1, "zip", 84 cgit_print_snapshot(item, cgit_query_sha1, "zip",
85 cgit_repo->url, cgit_query_name); 85 cgit_repo->url, cgit_query_name);
86 return; 86 return;
87 } 87 }
88 88
89 if (cgit_query_page && !strcmp(cgit_query_page, "log")) 89 if (cgit_query_page && !strcmp(cgit_query_page, "log"))
90 show_search = 1; 90 show_search = 1;
91
91 cgit_print_docstart(title, item); 92 cgit_print_docstart(title, item);
92 cgit_print_pageheader(title, show_search); 93
94
93 if (!cgit_query_page) { 95 if (!cgit_query_page) {
96 cgit_print_pageheader("summary", show_search);
94 cgit_print_summary(); 97 cgit_print_summary();
95 } else if (!strcmp(cgit_query_page, "log")) { 98 cgit_print_docend();
99 return;
100 }
101
102 cgit_print_pageheader(cgit_query_page, show_search);
103
104 if (!strcmp(cgit_query_page, "log")) {
96 cgit_print_log(cgit_query_head, cgit_query_ofs, 100, 105 cgit_print_log(cgit_query_head, cgit_query_ofs, 100,
97 cgit_query_search); 106 cgit_query_search);
98 } else if (!strcmp(cgit_query_page, "tree")) { 107 } else if (!strcmp(cgit_query_page, "tree")) {
99 cgit_print_tree(cgit_query_sha1, cgit_query_path); 108 cgit_print_tree(cgit_query_sha1, cgit_query_path);
100 } else if (!strcmp(cgit_query_page, "commit")) { 109 } else if (!strcmp(cgit_query_page, "commit")) {
101 cgit_print_commit(cgit_query_sha1); 110 cgit_print_commit(cgit_query_sha1);
102 } else if (!strcmp(cgit_query_page, "view")) { 111 } else if (!strcmp(cgit_query_page, "view")) {
103 cgit_print_view(cgit_query_sha1); 112 cgit_print_view(cgit_query_sha1);
104 } else if (!strcmp(cgit_query_page, "diff")) { 113 } else if (!strcmp(cgit_query_page, "diff")) {
105 cgit_print_diff(cgit_query_sha1, cgit_query_sha2); 114 cgit_print_diff(cgit_query_sha1, cgit_query_sha2);
106 } else { 115 } else {
107 cgit_print_error("Invalid request"); 116 cgit_print_error("Invalid request");
108 } 117 }
109 cgit_print_docend(); 118 cgit_print_docend();
110} 119}
111 120
112static void cgit_fill_cache(struct cacheitem *item, int use_cache) 121static void cgit_fill_cache(struct cacheitem *item, int use_cache)
113{ 122{
114 static char buf[PATH_MAX]; 123 static char buf[PATH_MAX];
115 int stdout2; 124 int stdout2;
116 125
117 getcwd(buf, sizeof(buf)); 126 getcwd(buf, sizeof(buf));
118 item->st.st_mtime = time(NULL); 127 item->st.st_mtime = time(NULL);
119 128
120 if (use_cache) { 129 if (use_cache) {
121 stdout2 = chk_positive(dup(STDOUT_FILENO), 130 stdout2 = chk_positive(dup(STDOUT_FILENO),
122 "Preserving STDOUT"); 131 "Preserving STDOUT");
123 chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); 132 chk_zero(close(STDOUT_FILENO), "Closing STDOUT");
124 chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); 133 chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)");
125 } 134 }
126 135
127 if (cgit_query_repo) 136 if (cgit_query_repo)
128 cgit_print_repo_page(item); 137 cgit_print_repo_page(item);
129 else 138 else
130 cgit_print_repolist(item); 139 cgit_print_repolist(item);
131 140
132 if (use_cache) { 141 if (use_cache) {
133 chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); 142 chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT");
134 chk_positive(dup2(stdout2, STDOUT_FILENO), 143 chk_positive(dup2(stdout2, STDOUT_FILENO),
135 "Restoring original STDOUT"); 144 "Restoring original STDOUT");
136 chk_zero(close(stdout2), "Closing temporary STDOUT"); 145 chk_zero(close(stdout2), "Closing temporary STDOUT");
137 } 146 }
138 147
139 chdir(buf); 148 chdir(buf);
140} 149}
141 150
142static void cgit_check_cache(struct cacheitem *item) 151static void cgit_check_cache(struct cacheitem *item)
143{ 152{