- if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) {
- cgit_print_snapshot(item, cgit_query_head, cgit_query_sha1,
- cgit_repobasename(cgit_repo->url),
- cgit_query_path,
- cgit_repo->snapshots );
+ 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);