- /* favor legacy setting */
- if(atoi(str))
- return 1;
- for(;;) {
- str += strspn(str,delim);
- tl = strcspn(str,delim);
- if(!tl)
- break;
- for(f=0; f<snapshot_archives_len; f++) {
- sat = &snapshot_archives[f];
- sl = strlen(sat->suffix);
- if((tl == sl && !strncmp(sat->suffix, str, tl)) ||
- (tl == sl-1 && !strncmp(sat->suffix+1, str, tl-1))) {
- rv |= sat->bit;
- break;
- }
+ if (get_sha1(snapshot.buf, sha1) == 0)
+ goto out;
+
+ strbuf_insert(&snapshot, 0, "v", 1);
+ if (get_sha1(snapshot.buf, sha1) == 0)
+ goto out;
+
+ result = 0;
+ strbuf_release(&snapshot);
+
+out:
+ 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(&ctx);
+ cgit_print_docstart(&ctx);
+ cgit_print_pageheader(&ctx);
+ 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 snapshots, int dwim)
+{
+ const struct cgit_snapshot_format* f;
+ char *prefix = NULL;
+
+ if (!filename) {
+ show_error("No snapshot name specified");
+ return;
+ }
+
+ f = get_format(filename);
+ if (!f) {
+ show_error("Unsupported snapshot format: %s", filename);
+ return;
+ }
+
+ if (!hex && dwim) {
+ hex = get_ref_from_filename(ctx.repo->url, filename, f);
+ if (hex == NULL) {
+ html_status(404, "Not found", 0);
+ return;