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 #include "object-store.h"
17 static int print_ref_info(const char *refname, const struct object_id *oid,
18 int flags, void *cb_data)
22 if (!(obj = parse_object(oid)))
25 htmlf("%s\t%s\n", oid_to_hex(oid), refname);
26 if (obj->type == OBJ_TAG) {
27 if (!(obj = deref_tag(obj, refname, 0)))
29 htmlf("%s\t%s^{}\n", oid_to_hex(&obj->oid), refname);
34 static void print_pack_info(void)
36 struct packed_git *pack;
39 ctx.page.mimetype = "text/plain";
40 ctx.page.filename = "objects/info/packs";
41 cgit_print_http_headers();
42 reprepare_packed_git(the_repository);
43 for (pack = get_packed_git(the_repository); pack; pack = pack->next) {
44 if (pack->pack_local) {
45 offset = strrchr(pack->pack_name, '/');
46 if (offset && offset[1] != '\0')
49 offset = pack->pack_name;
50 htmlf("P %s\n", offset);
55 static void send_file(const char *path)
59 if (stat(path, &st)) {
62 cgit_print_error_page(404, "Not found", "Not found");
65 cgit_print_error_page(403, "Forbidden", "Forbidden");
68 cgit_print_error_page(400, "Bad request", "Bad request");
72 ctx.page.mimetype = "application/octet-stream";
73 ctx.page.filename = path;
74 skip_prefix(path, ctx.repo->path, &ctx.page.filename);
75 skip_prefix(ctx.page.filename, "/", &ctx.page.filename);
76 cgit_print_http_headers();
80 void cgit_clone_info(void)
82 if (!ctx.qry.path || strcmp(ctx.qry.path, "refs")) {
83 cgit_print_error_page(400, "Bad request", "Bad request");
87 ctx.page.mimetype = "text/plain";
88 ctx.page.filename = "info/refs";
89 cgit_print_http_headers();
90 for_each_ref(print_ref_info, NULL);
93 void cgit_clone_objects(void)
96 cgit_print_error_page(400, "Bad request", "Bad request");
100 if (!strcmp(ctx.qry.path, "info/packs")) {
105 send_file(git_path("objects/%s", ctx.qry.path));
108 void cgit_clone_head(void)
110 send_file(git_path("%s", "HEAD"));