- setenv("GIT_DIR", cgit_repo->path, 1);
- if (cgit_query_page && !strcmp(cgit_query_page, "log"))
- show_search = 1;
- cgit_print_docstart(title, item);
- cgit_print_pageheader(title, show_search);
- if (!cgit_query_page) {
+
+ if (!ctx.qry.head) {
+ ctx.qry.head = xstrdup(find_default_branch(ctx.repo));
+ ctx.repo->defbranch = ctx.qry.head;
+ }
+
+ if (!ctx.qry.head) {
+ cgit_print_http_headers(&ctx);
+ cgit_print_docstart(&ctx);
+ cgit_print_pageheader(&ctx);
+ cgit_print_error("Repository seems to be empty");
+ cgit_print_docend();
+ return;
+ }
+
+ if (get_sha1(ctx.qry.head, sha1)) {
+ tmp = xstrdup(ctx.qry.head);
+ ctx.qry.head = ctx.repo->defbranch;
+ cgit_print_http_headers(&ctx);
+ cgit_print_docstart(&ctx);
+ cgit_print_pageheader(&ctx);
+ cgit_print_error(fmt("Invalid branch: %s", tmp));
+ cgit_print_docend();
+ return;
+ }
+
+ if ((cgit_cmd == CMD_SNAPSHOT) && ctx.repo->snapshots) {
+ cgit_print_snapshot(item, ctx.qry.head, ctx.qry.sha1,
+ cgit_repobasename(ctx.repo->url),
+ ctx.qry.path,
+ ctx.repo->snapshots );
+ return;
+ }
+
+ if (cgit_cmd == CMD_PATCH) {
+ cgit_print_patch(ctx.qry.sha1, item);
+ return;
+ }
+
+ if (cgit_cmd == CMD_BLOB) {
+ cgit_print_blob(item, ctx.qry.sha1, ctx.qry.path);
+ return;
+ }
+
+ show_search = (cgit_cmd == CMD_LOG);
+ cgit_print_http_headers(&ctx);
+ cgit_print_docstart(&ctx);
+ if (!cgit_cmd) {
+ cgit_print_pageheader(&ctx);