- char *filename;
- int f;
- for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) {
- const struct snapshot_archive_t* sat = &snapshot_archives[f];
- filename = fmt("%s-%s%s",repo,hex,sat->suffix);
- htmlf("<a href='%s'>%s</a><br/>",
- cgit_fileurl(repo,"snapshot",filename,
- fmt("id=%s&name=%s",hex,filename)), filename);
+ const char *reponame;
+ unsigned char sha1[20];
+ 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)
+ goto out;
+
+ reponame = cgit_repobasename(url);
+ if (prefixcmp(snapshot.buf, reponame) == 0) {
+ const char *new_start = snapshot.buf;
+ new_start += strlen(reponame);
+ while (new_start && (*new_start == '-' || *new_start == '_'))
+ new_start++;
+ strbuf_splice(&snapshot, 0, new_start - snapshot.buf, "", 0);
+ }
+
+ if (get_sha1(snapshot.buf, sha1) == 0)
+ goto out;
+
+ strbuf_insert(&snapshot, 0, "v", 1);
+ if (get_sha1(snapshot.buf, sha1) == 0)
+ goto out;
+
+ strbuf_splice(&snapshot, 0, 1, "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;