about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--cgit.c3
-rw-r--r--cmd.c12
-rw-r--r--cmd.h2
-rw-r--r--ui-shared.c8
-rw-r--r--ui-shared.h3
5 files changed, 26 insertions, 2 deletions
diff --git a/cgit.c b/cgit.c index ed02614..baad1c8 100644 --- a/cgit.c +++ b/cgit.c
@@ -742,6 +742,9 @@ static void process_request(void)
742 if (ctx.repo && prepare_repo_cmd()) 742 if (ctx.repo && prepare_repo_cmd())
743 return; 743 return;
744 744
745 if (cmd->pre)
746 cmd->pre();
747
745 if (cmd->want_layout) { 748 if (cmd->want_layout) {
746 cgit_print_http_headers(); 749 cgit_print_http_headers();
747 cgit_print_docstart(); 750 cgit_print_docstart();
diff --git a/cmd.c b/cmd.c index 188cd56..e86b0ea 100644 --- a/cmd.c +++ b/cmd.c
@@ -44,6 +44,12 @@ static void about_fn(void)
44 cgit_print_site_readme(); 44 cgit_print_site_readme();
45} 45}
46 46
47static void about_pre(void)
48{
49 if (ctx.repo && !ctx.qry.path && ctx.qry.url[strlen(ctx.qry.url) - 1] != '/')
50 cgit_redirect(fmtalloc("%s/", cgit_currenturl()), true);
51}
52
47static void blob_fn(void) 53static void blob_fn(void)
48{ 54{
49 cgit_print_blob(ctx.qry.sha1, ctx.qry.path, ctx.qry.head, 0); 55 cgit_print_blob(ctx.qry.sha1, ctx.qry.path, ctx.qry.head, 0);
@@ -136,15 +142,17 @@ static void tree_fn(void)
136 cgit_print_tree(ctx.qry.sha1, ctx.qry.path); 142 cgit_print_tree(ctx.qry.sha1, ctx.qry.path);
137} 143}
138 144
145#define def_cmp(name, want_repo, want_layout, want_vpath, is_clone) \
146 {#name, name##_fn, name##_pre, want_repo, want_layout, want_vpath, is_clone}
139#define def_cmd(name, want_repo, want_layout, want_vpath, is_clone) \ 147#define def_cmd(name, want_repo, want_layout, want_vpath, is_clone) \
140 {#name, name##_fn, want_repo, want_layout, want_vpath, is_clone} 148 {#name, name##_fn, NULL, want_repo, want_layout, want_vpath, is_clone}
141 149
142struct cgit_cmd *cgit_get_cmd(void) 150struct cgit_cmd *cgit_get_cmd(void)
143{ 151{
144 static struct cgit_cmd cmds[] = { 152 static struct cgit_cmd cmds[] = {
145 def_cmd(HEAD, 1, 0, 0, 1), 153 def_cmd(HEAD, 1, 0, 0, 1),
146 def_cmd(atom, 1, 0, 0, 0), 154 def_cmd(atom, 1, 0, 0, 0),
147 def_cmd(about, 0, 1, 0, 0), 155 def_cmp(about, 0, 1, 0, 0),
148 def_cmd(blob, 1, 0, 0, 0), 156 def_cmd(blob, 1, 0, 0, 0),
149 def_cmd(commit, 1, 1, 1, 0), 157 def_cmd(commit, 1, 1, 1, 0),
150 def_cmd(diff, 1, 1, 1, 0), 158 def_cmd(diff, 1, 1, 1, 0),
diff --git a/cmd.h b/cmd.h index 752f078..2507ca5 100644 --- a/cmd.h +++ b/cmd.h
@@ -2,10 +2,12 @@
2#define CMD_H 2#define CMD_H
3 3
4typedef void (*cgit_cmd_fn)(void); 4typedef void (*cgit_cmd_fn)(void);
5typedef void (*cgit_cmd_pre_fn)(void);
5 6
6struct cgit_cmd { 7struct cgit_cmd {
7 const char *name; 8 const char *name;
8 cgit_cmd_fn fn; 9 cgit_cmd_fn fn;
10 cgit_cmd_pre_fn pre;
9 unsigned int want_repo:1, 11 unsigned int want_repo:1,
10 want_layout:1, 12 want_layout:1,
11 want_vpath:1, 13 want_vpath:1,
diff --git a/ui-shared.c b/ui-shared.c index e755c92..4f84b7c 100644 --- a/ui-shared.c +++ b/ui-shared.c
@@ -689,6 +689,14 @@ void cgit_print_http_headers(void)
689 exit(0); 689 exit(0);
690} 690}
691 691
692void cgit_redirect(const char *url, bool permanent)
693{
694 htmlf("Status: %d %s\n", permanent ? 301 : 302, permanent ? "Moved" : "Found");
695 htmlf("Location: %s\n", url);
696 htmlf("\n");
697 exit(0);
698}
699
692static void print_rel_vcs_link(const char *url) 700static void print_rel_vcs_link(const char *url)
693{ 701{
694 html("<link rel='vcs-git' href='"); 702 html("<link rel='vcs-git' href='");
diff --git a/ui-shared.h b/ui-shared.h index 1b8ecb5..43d0fa6 100644 --- a/ui-shared.h +++ b/ui-shared.h
@@ -1,6 +1,8 @@
1#ifndef UI_SHARED_H 1#ifndef UI_SHARED_H
2#define UI_SHARED_H 2#define UI_SHARED_H
3 3
4#include <stdbool.h>
5
4extern const char *cgit_httpscheme(); 6extern const char *cgit_httpscheme();
5extern const char *cgit_hosturl(); 7extern const char *cgit_hosturl();
6extern const char *cgit_rooturl(); 8extern const char *cgit_rooturl();
@@ -61,6 +63,7 @@ extern void cgit_vprint_error(const char *fmt, va_list ap);
61extern void cgit_print_date(time_t secs, const char *format, int local_time); 63extern void cgit_print_date(time_t secs, const char *format, int local_time);
62extern void cgit_print_age(time_t t, time_t max_relative, const char *format); 64extern void cgit_print_age(time_t t, time_t max_relative, const char *format);
63extern void cgit_print_http_headers(void); 65extern void cgit_print_http_headers(void);
66extern void cgit_redirect(const char *url, bool permanent);
64extern void cgit_print_docstart(void); 67extern void cgit_print_docstart(void);
65extern void cgit_print_docend(); 68extern void cgit_print_docend();
66extern void cgit_print_pageheader(void); 69extern void cgit_print_pageheader(void);