-rw-r--r-- | cmd.c | 3 | ||||
-rw-r--r-- | ui-snapshot.c | 14 | ||||
-rw-r--r-- | ui-snapshot.h | 3 |
3 files changed, 14 insertions, 6 deletions
@@ -95,26 +95,25 @@ static void patch_fn(struct cgit_context *ctx) | |||
95 | static void plain_fn(struct cgit_context *ctx) | 95 | static void plain_fn(struct cgit_context *ctx) |
96 | { | 96 | { |
97 | cgit_print_plain(ctx); | 97 | cgit_print_plain(ctx); |
98 | } | 98 | } |
99 | 99 | ||
100 | static void refs_fn(struct cgit_context *ctx) | 100 | static void refs_fn(struct cgit_context *ctx) |
101 | { | 101 | { |
102 | cgit_print_refs(); | 102 | cgit_print_refs(); |
103 | } | 103 | } |
104 | 104 | ||
105 | static void snapshot_fn(struct cgit_context *ctx) | 105 | static void snapshot_fn(struct cgit_context *ctx) |
106 | { | 106 | { |
107 | cgit_print_snapshot(ctx->qry.head, ctx->qry.sha1, | 107 | cgit_print_snapshot(ctx->qry.head, ctx->qry.sha1, ctx->qry.path, |
108 | cgit_repobasename(ctx->repo->url), ctx->qry.path, | ||
109 | ctx->repo->snapshots, ctx->qry.nohead); | 108 | ctx->repo->snapshots, ctx->qry.nohead); |
110 | } | 109 | } |
111 | 110 | ||
112 | static void summary_fn(struct cgit_context *ctx) | 111 | static void summary_fn(struct cgit_context *ctx) |
113 | { | 112 | { |
114 | cgit_print_summary(); | 113 | cgit_print_summary(); |
115 | } | 114 | } |
116 | 115 | ||
117 | static void tag_fn(struct cgit_context *ctx) | 116 | static void tag_fn(struct cgit_context *ctx) |
118 | { | 117 | { |
119 | cgit_print_tag(ctx->qry.sha1); | 118 | cgit_print_tag(ctx->qry.sha1); |
120 | } | 119 | } |
diff --git a/ui-snapshot.c b/ui-snapshot.c index 9c4d086..76457d6 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c | |||
@@ -153,36 +153,46 @@ static const char *get_ref_from_filename(const char *url, const char *filename, | |||
153 | fprintf(stderr, "reponame=%s, filename=%s\n", reponame, filename); | 153 | fprintf(stderr, "reponame=%s, filename=%s\n", reponame, filename); |
154 | if (prefixcmp(filename, reponame)) | 154 | if (prefixcmp(filename, reponame)) |
155 | return NULL; | 155 | return NULL; |
156 | filename += strlen(reponame); | 156 | filename += strlen(reponame); |
157 | while (filename && (*filename == '-' || *filename == '_')) | 157 | while (filename && (*filename == '-' || *filename == '_')) |
158 | filename++; | 158 | filename++; |
159 | dwim_filename = xstrdup(filename); | 159 | dwim_filename = xstrdup(filename); |
160 | dwim_filename[strlen(filename) - strlen(fmt->suffix)] = '\0'; | 160 | dwim_filename[strlen(filename) - strlen(fmt->suffix)] = '\0'; |
161 | for_each_tag_ref(ref_cb, NULL); | 161 | for_each_tag_ref(ref_cb, NULL); |
162 | return dwim_refname; | 162 | return dwim_refname; |
163 | } | 163 | } |
164 | 164 | ||
165 | void cgit_print_snapshot(const char *head, const char *hex, const char *prefix, | 165 | void cgit_print_snapshot(const char *head, const char *hex, |
166 | const char *filename, int snapshots, int dwim) | 166 | const char *filename, int snapshots, int dwim) |
167 | { | 167 | { |
168 | const struct cgit_snapshot_format* f; | 168 | const struct cgit_snapshot_format* f; |
169 | char *prefix = NULL; | ||
169 | 170 | ||
170 | f = get_format(filename); | 171 | f = get_format(filename); |
171 | if (!f) { | 172 | if (!f) { |
172 | ctx.page.mimetype = "text/html"; | 173 | ctx.page.mimetype = "text/html"; |
173 | cgit_print_http_headers(&ctx); | 174 | cgit_print_http_headers(&ctx); |
174 | cgit_print_docstart(&ctx); | 175 | cgit_print_docstart(&ctx); |
175 | cgit_print_pageheader(&ctx); | 176 | cgit_print_pageheader(&ctx); |
176 | cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); | 177 | cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); |
177 | cgit_print_docend(); | 178 | cgit_print_docend(); |
178 | return; | 179 | return; |
179 | } | 180 | } |
180 | 181 | ||
181 | if (!hex && dwim) | 182 | if (!hex && dwim) { |
182 | hex = get_ref_from_filename(ctx.repo->url, filename, f); | 183 | hex = get_ref_from_filename(ctx.repo->url, filename, f); |
184 | if (hex != NULL) { | ||
185 | prefix = xstrdup(filename); | ||
186 | prefix[strlen(filename) - strlen(f->suffix)] = '\0'; | ||
187 | } | ||
188 | } | ||
183 | 189 | ||
184 | if (!hex) | 190 | if (!hex) |
185 | hex = head; | 191 | hex = head; |
186 | 192 | ||
193 | if (!prefix) | ||
194 | prefix = xstrdup(cgit_repobasename(ctx.repo->url)); | ||
195 | |||
187 | make_snapshot(f, hex, prefix, filename); | 196 | make_snapshot(f, hex, prefix, filename); |
197 | free(prefix); | ||
188 | } | 198 | } |
diff --git a/ui-snapshot.h b/ui-snapshot.h index 3540303..b6ede52 100644 --- a/ui-snapshot.h +++ b/ui-snapshot.h | |||
@@ -1,8 +1,7 @@ | |||
1 | #ifndef UI_SNAPSHOT_H | 1 | #ifndef UI_SNAPSHOT_H |
2 | #define UI_SNAPSHOT_H | 2 | #define UI_SNAPSHOT_H |
3 | 3 | ||
4 | extern void cgit_print_snapshot(const char *head, const char *hex, | 4 | extern void cgit_print_snapshot(const char *head, const char *hex, |
5 | const char *prefix, const char *filename, | 5 | const char *filename, int snapshot, int dwim); |
6 | int snapshot, int dwim); | ||
7 | 6 | ||
8 | #endif /* UI_SNAPSHOT_H */ | 7 | #endif /* UI_SNAPSHOT_H */ |