aboutsummaryrefslogtreecommitdiff
diff refs
from: back
to: back
| flip
diff options
context:
space:
mode:
-rw-r--r--cache.c9
-rw-r--r--cgit.c60
-rw-r--r--cgit.h16
-rw-r--r--parsing.c43
-rw-r--r--shared.c5
-rw-r--r--ui-shared.c5
6 files changed, 40 insertions, 98 deletions
diff --git a/cache.c b/cache.c
index 7cdea9b..8df7c26 100644
--- a/cache.c
+++ b/cache.c
@@ -43,18 +43,15 @@ int cache_create_dirs()
if (mkdir(path, S_IRWXU) && errno!=EEXIST)
return 0;
- if (!cgit_repo)
+ if (!cgit_query_repo)
return 0;
- path = fmt("%s/%s", cgit_cache_root,
- cache_safe_filename(cgit_repo->url));
-
+ path = fmt("%s/%s", cgit_cache_root, cgit_query_repo);
if (mkdir(path, S_IRWXU) && errno!=EEXIST)
return 0;
if (cgit_query_page) {
- path = fmt("%s/%s/%s", cgit_cache_root,
- cache_safe_filename(cgit_repo->url),
+ path = fmt("%s/%s/%s", cgit_cache_root, cgit_query_repo,
cgit_query_page);
if (mkdir(path, S_IRWXU) && errno!=EEXIST)
return 0;
diff --git a/cgit.c b/cgit.c
index e5d8fbd..431e8fb 100644
--- a/cgit.c
+++ b/cgit.c
@@ -13,7 +13,13 @@ const char cgit_version[] = CGIT_VERSION;
static int cgit_prepare_cache(struct cacheitem *item)
{
- if (!cgit_repo && cgit_query_repo) {
+ if (!cgit_query_repo) {
+ item->name = xstrdup(fmt("%s/index.html", cgit_cache_root));
+ item->ttl = cgit_cache_root_ttl;
+ return 1;
+ }
+ cgit_repo = cgit_get_repoinfo(cgit_query_repo);
+ if (!cgit_repo) {
char *title = fmt("%s - %s", cgit_root_title, "Bad request");
cgit_print_docstart(title, item);
cgit_print_pageheader(title, 0);
@@ -22,19 +28,13 @@ static int cgit_prepare_cache(struct cacheitem *item)
return 0;
}
- if (!cgit_repo) {
- item->name = xstrdup(fmt("%s/index.html", cgit_cache_root));
- item->ttl = cgit_cache_root_ttl;
- return 1;
- }
-
- if (!cgit_cmd) {
+ if (!cgit_query_page) {
item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root,
- cache_safe_filename(cgit_repo->url)));
+ cgit_repo->url));
item->ttl = cgit_cache_repo_ttl;
} else {
item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root,
- cache_safe_filename(cgit_repo->url), cgit_query_page,
+ cgit_repo->url, cgit_query_page,
cache_safe_filename(cgit_querystring)));
if (cgit_query_has_symref)
item->ttl = cgit_cache_dynamic_ttl;
@@ -68,20 +68,25 @@ static void cgit_print_repo_page(struct cacheitem *item)
show_search = 0;
setenv("GIT_DIR", cgit_repo->path, 1);
- if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) {
+ if (cgit_query_page) {
+ if (cgit_repo->snapshots && !strcmp(cgit_query_page, "snapshot")) {
cgit_print_snapshot(item, cgit_query_sha1, "zip",
cgit_repo->url, cgit_query_name);
return;
+ }
+ if (!strcmp(cgit_query_page, "blob")) {
+ cgit_print_blob(item, cgit_query_sha1, cgit_query_path);
+ return;
+ }
}
- if (cgit_cmd == CMD_BLOB) {
- cgit_print_blob(item, cgit_query_sha1, cgit_query_path);
- return;
- }
+ if (cgit_query_page && !strcmp(cgit_query_page, "log"))
+ show_search = 1;
- show_search = (cgit_cmd == CMD_LOG);
cgit_print_docstart(title, item);
- if (!cgit_cmd) {
+
+
+ if (!cgit_query_page) {
cgit_print_pageheader("summary", show_search);
cgit_print_summary();
cgit_print_docend();
@@ -90,26 +95,20 @@ static void cgit_print_repo_page(struct cacheitem *item)
cgit_print_pageheader(cgit_query_page, show_search);
- switch(cgit_cmd) {
- case CMD_LOG:
+ if (!strcmp(cgit_query_page, "log")) {
cgit_print_log(cgit_query_head, cgit_query_ofs,
cgit_max_commit_count, cgit_query_search,
cgit_query_path);
- break;
- case CMD_TREE:
+ } else if (!strcmp(cgit_query_page, "tree")) {
cgit_print_tree(cgit_query_head, cgit_query_sha1, cgit_query_path);
- break;
- case CMD_COMMIT:
+ } else if (!strcmp(cgit_query_page, "commit")) {
cgit_print_commit(cgit_query_head);
- break;
- case CMD_VIEW:
+ } else if (!strcmp(cgit_query_page, "view")) {
cgit_print_view(cgit_query_sha1, cgit_query_path);
- break;
- case CMD_DIFF:
+ } else if (!strcmp(cgit_query_page, "diff")) {
cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2,
cgit_query_path);
- break;
- default:
+ } else {
cgit_print_error("Invalid request");
}
cgit_print_docend();
@@ -130,7 +129,7 @@ static void cgit_fill_cache(struct cacheitem *item, int use_cache)
chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)");
}
- if (cgit_repo)
+ if (cgit_query_repo)
cgit_print_repo_page(item);
else
cgit_print_repolist(item);
@@ -235,7 +234,6 @@ int main(int argc, const char **argv)
cgit_repolist.repos = NULL;
cgit_read_config(CGIT_CONFIG, cgit_global_config_cb);
- cgit_repo = NULL;
if (getenv("SCRIPT_NAME"))
cgit_script_name = xstrdup(getenv("SCRIPT_NAME"));
if (getenv("QUERY_STRING"))
diff --git a/cgit.h b/cgit.h
index e5b3f5e..f402466 100644
--- a/cgit.h
+++ b/cgit.h
@@ -21,13 +21,13 @@
/*
* The valid cgit repo-commands
*/
-#define CMD_LOG 1
-#define CMD_COMMIT 2
-#define CMD_DIFF 3
-#define CMD_TREE 4
-#define CMD_VIEW 5
-#define CMD_BLOB 6
-#define CMD_SNAPSHOT 7
+#define CMD_LOG = 1;
+#define CMD_COMMIT = 1;
+#define CMD_DIFF = 1;
+#define CMD_TREE = 1;
+#define CMD_VIEW = 1;
+#define CMD_BLOB = 1;
+#define CMD_SNAPSHOT = 1;
typedef void (*configfn)(const char *name, const char *value);
typedef void (*filepair_fn)(struct diff_filepair *pair);
@@ -82,7 +82,6 @@ extern const char cgit_version[];
extern struct repolist cgit_repolist;
extern struct repoinfo *cgit_repo;
-extern int cgit_cmd;
extern char *cgit_root_title;
extern char *cgit_css;
@@ -163,7 +162,6 @@ 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);
diff --git a/parsing.c b/parsing.c
index a028625..36b0f0c 100644
--- a/parsing.c
+++ b/parsing.c
@@ -132,49 +132,6 @@ int cgit_parse_query(char *txt, configfn fn)
return 0;
}
-/*
- * url syntax: [repo ['/' cmd [ '/' path]]]
- * repo: any valid repo url, may contain '/'
- * cmd: log | commit | diff | tree | view | blob | snapshot
- * path: any valid path, may contain '/'
- *
- */
-void cgit_parse_url(const char *url)
-{
- char *cmd, *p;
-
- cgit_repo = NULL;
- if (!url || url[0] == '\0')
- return;
-
- cgit_repo = cgit_get_repoinfo(url);
- if (cgit_repo) {
- cgit_query_repo = cgit_repo->url;
- return;
- }
-
- cmd = strchr(url, '/');
- while (!cgit_repo && cmd) {
- cmd[0] = '\0';
- cgit_repo = cgit_get_repoinfo(url);
- if (cgit_repo == NULL) {
- cmd[0] = '/';
- cmd = strchr(cmd + 1, '/');
- continue;
- }
-
- cgit_query_repo = cgit_repo->url;
- p = strchr(cmd + 1, '/');
- if (p) {
- p[0] = '\0';
- cgit_query_path = xstrdup(p + 1);
- }
- cgit_cmd = cgit_get_cmd_index(cmd + 1);
- cgit_query_page = xstrdup(cmd + 1);
- return;
- }
-}
-
char *substr(const char *head, const char *tail)
{
char *buf;
diff --git a/shared.c b/shared.c
index 0b074da..fb05427 100644
--- a/shared.c
+++ b/shared.c
@@ -10,7 +10,6 @@
struct repolist cgit_repolist;
struct repoinfo *cgit_repo;
-int cgit_cmd;
char *cgit_root_title = "Git repository browser";
char *cgit_css = "/cgit.css";
@@ -185,12 +184,8 @@ void cgit_querystring_cb(const char *name, const char *value)
{
if (!strcmp(name,"r")) {
cgit_query_repo = xstrdup(value);
- cgit_repo = cgit_get_repoinfo(value);
} else if (!strcmp(name, "p")) {
cgit_query_page = xstrdup(value);
- cgit_cmd = cgit_get_cmd_index(value);
- } else if (!strcmp(name, "url")) {
- cgit_parse_url(value);
} else if (!strcmp(name, "q")) {
cgit_query_search = xstrdup(value);
} else if (!strcmp(name, "h")) {
diff --git a/ui-shared.c b/ui-shared.c
index c7fbc5e..6211056 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -68,10 +68,7 @@ char *cgit_pageurl(const char *reponame, const char *pagename,
return fmt("%s/%s/%s/", cgit_virtual_root, reponame,
pagename);
} else {
- if (query)
- return fmt("?r=%s&p=%s&%s", reponame, pagename, query);
- else
- return fmt("?r=%s&p=%s", reponame, pagename);
+ return fmt("?r=%s&p=%s&%s", reponame, pagename, query);
}
}