1 /* ui-clone.c: functions for http cloning, based on
2 * git's http-backend.c by Shawn O. Pearce
4 * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
6 * Licensed under GNU General Public License v2
7 * (see COPYING for full license text)
13 #include "ui-shared.h"
15 static int print_ref_info(const char *refname, const unsigned char *sha1,
16 int flags, void *cb_data)
20 if (!(obj = parse_object(sha1)))
23 htmlf("%s\t%s\n", sha1_to_hex(sha1), refname);
24 if (obj->type == OBJ_TAG) {
25 if (!(obj = deref_tag(obj, refname, 0)))
27 htmlf("%s\t%s^{}\n", sha1_to_hex(obj->sha1), refname);
32 static void print_pack_info(struct cgit_context *ctx)
34 struct packed_git *pack;
37 ctx->page.mimetype = "text/plain";
38 ctx->page.filename = "objects/info/packs";
39 cgit_print_http_headers(ctx);
40 ofs = strlen(ctx->repo->path) + strlen("/objects/pack/");
42 for (pack = packed_git; pack; pack = pack->next)
44 htmlf("P %s\n", pack->pack_name + ofs);
47 static void send_file(struct cgit_context *ctx, char *path)
51 if (stat(path, &st)) {
54 html_status(404, "Not found", 0);
57 html_status(403, "Forbidden", 0);
60 html_status(400, "Bad request", 0);
64 ctx->page.mimetype = "application/octet-stream";
65 ctx->page.filename = path;
66 if (prefixcmp(ctx->repo->path, path))
67 ctx->page.filename += strlen(ctx->repo->path) + 1;
68 cgit_print_http_headers(ctx);
72 void cgit_clone_info(struct cgit_context *ctx)
74 if (!ctx->qry.path || strcmp(ctx->qry.path, "refs"))
77 ctx->page.mimetype = "text/plain";
78 ctx->page.filename = "info/refs";
79 cgit_print_http_headers(ctx);
80 for_each_ref(print_ref_info, ctx);
83 void cgit_clone_objects(struct cgit_context *ctx)
86 html_status(400, "Bad request", 0);
90 if (!strcmp(ctx->qry.path, "info/packs")) {
95 send_file(ctx, git_path("objects/%s", ctx->qry.path));
98 void cgit_clone_head(struct cgit_context *ctx)
100 send_file(ctx, git_path("%s", "HEAD"));