summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c4
-rw-r--r--cgit.css5
-rw-r--r--cgit.h4
-rw-r--r--html.c10
-rw-r--r--shared.c3
-rw-r--r--ui-repolist.c2
-rw-r--r--ui-shared.c28
7 files changed, 51 insertions, 5 deletions
diff --git a/cgit.c b/cgit.c
index ac43441..277b849 100644
--- a/cgit.c
+++ b/cgit.c
@@ -13,22 +13,22 @@ const char cgit_version[] = CGIT_VERSION;
static void cgit_print_repo_page(struct cacheitem *item)
{
if (chdir(fmt("%s/%s", cgit_root, cgit_query_repo)) ||
cgit_read_config("info/cgit", cgit_repo_config_cb)) {
char *title = fmt("%s - %s", cgit_root_title, "Bad request");
cgit_print_docstart(title, item);
- cgit_print_pageheader(title);
+ cgit_print_pageheader(title, 0);
cgit_print_error(fmt("Unable to scan repository: %s",
strerror(errno)));
cgit_print_docend();
return;
}
setenv("GIT_DIR", fmt("%s/%s", cgit_root, cgit_query_repo), 1);
char *title = fmt("%s - %s", cgit_repo_name, cgit_repo_desc);
cgit_print_docstart(title, item);
- cgit_print_pageheader(title);
+ cgit_print_pageheader(title, 0);
if (!cgit_query_page) {
cgit_print_summary();
} else if (!strcmp(cgit_query_page, "log")) {
cgit_print_log(cgit_query_head, cgit_query_ofs, 100);
} else if (!strcmp(cgit_query_page, "tree")) {
cgit_print_tree(cgit_query_sha1);
diff --git a/cgit.css b/cgit.css
index 459dca7..9112bfe 100644
--- a/cgit.css
+++ b/cgit.css
@@ -58,12 +58,17 @@ div#header {
vertical-align: middle;
margin-bottom: 2em;
}
div#header img#logo {
float: right;
}
+
+div#header input {
+ float: right;
+ margin: 0.25em 1em;
+}
div#header a {
color: black;
}
div#content {
margin: 0.5em 0.5em;
diff --git a/cgit.h b/cgit.h
index 362b435..e114a50 100644
--- a/cgit.h
+++ b/cgit.h
@@ -52,12 +52,13 @@ extern char *cgit_repo_owner;
extern int cgit_query_has_symref;
extern int cgit_query_has_sha1;
extern char *cgit_querystring;
extern char *cgit_query_repo;
extern char *cgit_query_page;
+extern char *cgit_query_search;
extern char *cgit_query_head;
extern char *cgit_query_sha1;
extern char *cgit_query_sha2;
extern int cgit_query_ofs;
extern int htmlfd;
@@ -72,12 +73,13 @@ 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_link_open(char *url, char *title, char *class);
extern void html_link_close(void);
extern void html_filemode(unsigned short mode);
extern int cgit_read_config(const char *filename, configfn fn);
extern int cgit_parse_query(char *txt, configfn fn);
@@ -95,13 +97,13 @@ extern char *cgit_pageurl(const char *reponame, const char *pagename,
const char *query);
extern void cgit_print_error(char *msg);
extern void cgit_print_date(unsigned long secs);
extern void cgit_print_docstart(char *title, struct cacheitem *item);
extern void cgit_print_docend();
-extern void cgit_print_pageheader(char *title);
+extern void cgit_print_pageheader(char *title, int show_search);
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);
extern void cgit_print_view(const char *hex);
extern void cgit_print_tree(const char *hex);
diff --git a/html.c b/html.c
index 3a5d28d..c0b2ed4 100644
--- a/html.c
+++ b/html.c
@@ -114,12 +114,21 @@ void html_attr(char *txt)
t++;
}
if (t!=txt)
html(txt);
}
+void html_hidden(char *name, char *value)
+{
+ html("<input type='hidden' name='");
+ html_attr(name);
+ html("' value='");
+ html_attr(value);
+ html("'/>");
+}
+
void html_link_open(char *url, char *title, char *class)
{
html("<a href='");
html_attr(url);
if (title) {
html("' title='");
@@ -152,6 +161,7 @@ void html_filemode(unsigned short mode)
else
html("-");
html_fileperm(mode >> 6);
html_fileperm(mode >> 3);
html_fileperm(mode);
}
+
diff --git a/shared.c b/shared.c
index 18b795b..7def51a 100644
--- a/shared.c
+++ b/shared.c
@@ -33,12 +33,13 @@ int cgit_query_has_symref = 0;
int cgit_query_has_sha1 = 0;
char *cgit_querystring = NULL;
char *cgit_query_repo = NULL;
char *cgit_query_page = NULL;
char *cgit_query_head = NULL;
+char *cgit_query_search = NULL;
char *cgit_query_sha1 = NULL;
char *cgit_query_sha2 = NULL;
int cgit_query_ofs = 0;
int htmlfd = 0;
@@ -83,12 +84,14 @@ void cgit_repo_config_cb(const char *name, const char *value)
void cgit_querystring_cb(const char *name, const char *value)
{
if (!strcmp(name,"r")) {
cgit_query_repo = xstrdup(value);
} else if (!strcmp(name, "p")) {
cgit_query_page = xstrdup(value);
+ } else if (!strcmp(name, "q")) {
+ cgit_query_search = xstrdup(value);
} else if (!strcmp(name, "h")) {
cgit_query_head = xstrdup(value);
cgit_query_has_symref = 1;
} else if (!strcmp(name, "id")) {
cgit_query_sha1 = xstrdup(value);
cgit_query_has_sha1 = 1;
diff --git a/ui-repolist.c b/ui-repolist.c
index 7090c12..9f12b18 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -14,13 +14,13 @@ void cgit_print_repolist(struct cacheitem *item)
struct dirent *de;
struct stat st;
char *name;
chdir(cgit_root);
cgit_print_docstart(cgit_root_title, item);
- cgit_print_pageheader(cgit_root_title);
+ cgit_print_pageheader(cgit_root_title, 0);
if (!(d = opendir("."))) {
cgit_print_error(fmt("Unable to scan repository directory: %s",
strerror(errno)));
cgit_print_docend();
return;
diff --git a/ui-shared.c b/ui-shared.c
index 9ec4be8..b9c1243 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -57,12 +57,24 @@ char *cgit_pageurl(const char *reponame, const char *pagename,
pagename, query);
} else {
return fmt("?r=%s&p=%s&%s", reponame, pagename, query);
}
}
+char *cgit_currurl()
+{
+ if (!cgit_virtual_root)
+ return "./cgit.cgi";
+ else if (cgit_query_page)
+ return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page);
+ else if (cgit_query_repo)
+ return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo);
+ else
+ return fmt("%s/", cgit_virtual_root);
+}
+
void cgit_print_date(unsigned long secs)
{
char buf[32];
struct tm *time;
@@ -95,18 +107,32 @@ void cgit_print_docstart(char *title, struct cacheitem *item)
void cgit_print_docend()
{
html("</body>\n</html>\n");
}
-void cgit_print_pageheader(char *title)
+void cgit_print_pageheader(char *title, int show_search)
{
html("<div id='header'>");
htmlf("<a href='%s'>", cgit_logo_link);
htmlf("<img id='logo' src='%s'/>\n", cgit_logo);
htmlf("</a>");
+ if (show_search) {
+ html("<form method='get' href='");
+ html_attr(cgit_currurl());
+ html("'>");
+ if (cgit_query_head)
+ 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);
+ html("<input type='text' name='q' value='");
+ html_attr(cgit_query_search);
+ html("'/></form>");
+ }
if (cgit_query_repo)
htmlf("<a href='%s'>", cgit_repourl(cgit_query_repo));
html_txt(title);
if (cgit_query_repo)
html("</a>");
html("</div>");