+
+ if (get_oid(snapshot.buf, &oid) == 0)
+ goto out;
+
+ strbuf_insert(&snapshot, 0, "v", 1);
+ if (get_oid(snapshot.buf, &oid) == 0)
+ goto out;
+
+ strbuf_splice(&snapshot, 0, 1, "V", 1);
+ if (get_oid(snapshot.buf, &oid) == 0)
+ goto out;
+
+ result = 0;
+ strbuf_release(&snapshot);
+
+out:
+ return result ? strbuf_detach(&snapshot, NULL) : NULL;
+}
+
+void cgit_print_snapshot(const char *head, const char *hex,
+ const char *filename, int dwim)
+{
+ const struct cgit_snapshot_format* f;
+ char *prefix = NULL;
+
+ if (!filename) {
+ cgit_print_error_page(400, "Bad request",
+ "No snapshot name specified");
+ return;
+ }
+
+ f = get_format(filename);
+ if (!f) {
+ cgit_print_error_page(400, "Bad request",
+ "Unsupported snapshot format: %s", filename);
+ return;
+ }
+
+ if (!hex && dwim) {
+ hex = get_ref_from_filename(ctx.repo->url, filename, f);
+ if (hex == NULL) {
+ cgit_print_error_page(404, "Not found", "Not found");
+ return;
+ }
+ prefix = xstrdup(filename);
+ prefix[strlen(filename) - strlen(f->suffix)] = '\0';
+ }
+
+ if (!hex)
+ hex = head;
+
+ if (!prefix)
+ prefix = xstrdup(cgit_repobasename(ctx.repo->url));
+
+ make_snapshot(f, hex, prefix, filename);
+ free(prefix);