/* argv_array guarantees a trailing NULL entry. */
memcpy(nargv, argv.argv, sizeof(char *) * (argv.argc + 1));
- result = write_archive(argv.argc, nargv, NULL, 1, NULL, 0);
+ result = write_archive(argv.argc, nargv, NULL, NULL, 0);
argv_array_clear(&argv);
free(nargv);
return result;
const char *hex, const char *prefix,
const char *filename)
{
- unsigned char sha1[20];
+ struct object_id oid;
- if (get_sha1(hex, sha1)) {
- cgit_print_error("Bad object id: %s", hex);
+ if (get_oid(hex, &oid)) {
+ cgit_print_error_page(404, "Not found",
+ "Bad object id: %s", hex);
return 1;
}
- if (!lookup_commit_reference(sha1)) {
- cgit_print_error("Not a commit reference: %s", hex);
+ if (!lookup_commit_reference(&oid)) {
+ cgit_print_error_page(400, "Bad request",
+ "Not a commit reference: %s", hex);
return 1;
}
- ctx.page.etag = sha1_to_hex(sha1);
+ ctx.page.etag = oid_to_hex(&oid);
ctx.page.mimetype = xstrdup(format->mimetype);
ctx.page.filename = xstrdup(filename);
cgit_print_http_headers();
const struct cgit_snapshot_format *format)
{
const char *reponame;
- unsigned char sha1[20];
+ struct object_id oid;
struct strbuf snapshot = STRBUF_INIT;
int result = 1;
strbuf_addstr(&snapshot, filename);
strbuf_setlen(&snapshot, snapshot.len - strlen(format->suffix));
- if (get_sha1(snapshot.buf, sha1) == 0)
+ if (get_oid(snapshot.buf, &oid) == 0)
goto out;
reponame = cgit_repobasename(url);
strbuf_splice(&snapshot, 0, new_start - snapshot.buf, "", 0);
}
- if (get_sha1(snapshot.buf, sha1) == 0)
+ if (get_oid(snapshot.buf, &oid) == 0)
goto out;
strbuf_insert(&snapshot, 0, "v", 1);
- if (get_sha1(snapshot.buf, sha1) == 0)
+ if (get_oid(snapshot.buf, &oid) == 0)
goto out;
strbuf_splice(&snapshot, 0, 1, "V", 1);
- if (get_sha1(snapshot.buf, sha1) == 0)
+ if (get_oid(snapshot.buf, &oid) == 0)
goto out;
result = 0;
return result ? strbuf_detach(&snapshot, NULL) : NULL;
}
-__attribute__((format (printf, 1, 2)))
-static void show_error(char *fmt, ...)
-{
- va_list ap;
-
- ctx.page.mimetype = "text/html";
- cgit_print_http_headers();
- cgit_print_docstart();
- cgit_print_pageheader();
- va_start(ap, fmt);
- cgit_vprint_error(fmt, ap);
- va_end(ap);
- cgit_print_docend();
-}
-
void cgit_print_snapshot(const char *head, const char *hex,
const char *filename, int dwim)
{
char *prefix = NULL;
if (!filename) {
- show_error("No snapshot name specified");
+ cgit_print_error_page(400, "Bad request",
+ "No snapshot name specified");
return;
}
f = get_format(filename);
if (!f) {
- show_error("Unsupported snapshot format: %s", filename);
+ cgit_print_error_page(400, "Bad request",
+ "Unsupported snapshot format: %s", filename);
return;
}