author | Lars Hjemli <hjemli@gmail.com> | 2007-07-22 22:11:15 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-07-22 22:27:32 (UTC) |
commit | eb45342e735818b3c68cbab9b61b23e79ae74418 (patch) (side-by-side diff) | |
tree | 43fed08927a2118a22cf686ee58b8d464233cd5d | |
parent | 1d4aaff696ee1b9085dda0f0f3d84d9d20d96db0 (diff) | |
download | cgit-eb45342e735818b3c68cbab9b61b23e79ae74418.zip cgit-eb45342e735818b3c68cbab9b61b23e79ae74418.tar.gz cgit-eb45342e735818b3c68cbab9b61b23e79ae74418.tar.bz2 |
cgit_print_snapshot_links: use url to specify snapshot name
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 4 | ||||
-rw-r--r-- | cgit.h | 11 | ||||
-rw-r--r-- | ui-commit.c | 3 | ||||
-rw-r--r-- | ui-shared.c | 6 | ||||
-rw-r--r-- | ui-snapshot.c | 38 |
5 files changed, 41 insertions, 21 deletions
@@ -39,67 +39,67 @@ static int cgit_prepare_cache(struct cacheitem *item) item->ttl = cgit_cache_dynamic_ttl; else if (cgit_query_has_sha1) item->ttl = cgit_cache_static_ttl; else item->ttl = cgit_cache_repo_ttl; } return 1; } static void cgit_print_repo_page(struct cacheitem *item) { char *title; int show_search; if (!cgit_query_head) cgit_query_head = cgit_repo->defbranch; if (chdir(cgit_repo->path)) { title = fmt("%s - %s", cgit_root_title, "Bad request"); cgit_print_docstart(title, item); cgit_print_pageheader(title, 0); cgit_print_error(fmt("Unable to scan repository: %s", strerror(errno))); cgit_print_docend(); return; } title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); show_search = 0; setenv("GIT_DIR", cgit_repo->path, 1); if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { - cgit_print_snapshot(item, cgit_query_sha1, + cgit_print_snapshot(item, cgit_query_head, cgit_query_sha1, cgit_repobasename(cgit_repo->url), - cgit_query_name, + cgit_query_path, cgit_repo->snapshots ); return; } if (cgit_cmd == CMD_BLOB) { cgit_print_blob(item, cgit_query_sha1, cgit_query_path); return; } show_search = (cgit_cmd == CMD_LOG); cgit_print_docstart(title, item); if (!cgit_cmd) { cgit_print_pageheader("summary", show_search); cgit_print_summary(); cgit_print_docend(); return; } cgit_print_pageheader(cgit_query_page, show_search); switch(cgit_cmd) { case CMD_LOG: cgit_print_log(cgit_query_sha1, cgit_query_ofs, cgit_max_commit_count, cgit_query_search, cgit_query_path, 1); break; case CMD_TREE: cgit_print_tree(cgit_query_sha1, cgit_query_path); break; case CMD_COMMIT: cgit_print_commit(cgit_query_sha1); break; @@ -185,62 +185,65 @@ extern void html_hidden(char *name, char *value); extern void html_link_open(char *url, char *title, char *class); extern void html_link_close(void); extern void html_filemode(unsigned short mode); extern int html_include(const char *filename); extern int cgit_read_config(const char *filename, configfn fn); extern int cgit_parse_query(char *txt, configfn fn); extern struct commitinfo *cgit_parse_commit(struct commit *commit); extern struct taginfo *cgit_parse_tag(struct tag *tag); extern void cgit_parse_url(const char *url); extern char *cache_safe_filename(const char *unsafe); extern int cache_lock(struct cacheitem *item); extern int cache_unlock(struct cacheitem *item); extern int cache_cancel_lock(struct cacheitem *item); extern int cache_exist(struct cacheitem *item); extern int cache_expired(struct cacheitem *item); extern char *cgit_repourl(const char *reponame); extern char *cgit_fileurl(const char *reponame, const char *pagename, const char *filename, const char *query); extern char *cgit_pageurl(const char *reponame, const char *pagename, const char *query); extern const char *cgit_repobasename(const char *reponame); extern void cgit_tree_link(char *name, char *title, char *class, char *head, char *rev, char *path); extern void cgit_log_link(char *name, char *title, char *class, char *head, char *rev, char *path, int ofs); extern void cgit_commit_link(char *name, char *title, char *class, char *head, char *rev); +extern void cgit_snapshot_link(char *name, char *title, char *class, + char *head, char *rev, char *archivename); extern void cgit_diff_link(char *name, char *title, char *class, char *head, char *new_rev, char *old_rev, char *path); extern void cgit_object_link(struct object *obj); extern void cgit_print_error(char *msg); extern void cgit_print_date(time_t secs, char *format); extern void cgit_print_age(time_t t, time_t max_relative, char *format); extern void cgit_print_docstart(char *title, struct cacheitem *item); extern void cgit_print_docend(); extern void cgit_print_pageheader(char *title, int show_search); extern void cgit_print_snapshot_start(const char *mimetype, const char *filename, struct cacheitem *item); extern void cgit_print_repolist(struct cacheitem *item); extern void cgit_print_summary(); extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); extern void cgit_print_tree(const char *rev, char *path); extern void cgit_print_commit(char *hex); extern void cgit_print_tag(char *revname); extern void cgit_print_diff(const char *new_hex, const char *old_hex); -extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, - const char *prefix, const char *filename, - int snapshot); -extern void cgit_print_snapshot_links(const char *repo, const char *hex,int snapshots); +extern void cgit_print_snapshot(struct cacheitem *item, const char *head, + const char *hex, const char *prefix, + const char *filename, int snapshot); +extern void cgit_print_snapshot_links(const char *repo, const char *head, + const char *hex, int snapshots); extern int cgit_parse_snapshots_mask(const char *str); #endif /* CGIT_H */ diff --git a/ui-commit.c b/ui-commit.c index 50e9e11..90e09ed 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -167,59 +167,60 @@ void cgit_print_commit(char *hex) html("</td></tr>\n"); html("<tr><th>committer</th><td>"); html_txt(info->committer); html(" "); html_txt(info->committer_email); html("</td><td class='right'>"); cgit_print_date(info->committer_date, FMT_LONGDATE); html("</td></tr>\n"); html("<tr><th>tree</th><td colspan='2' class='sha1'>"); tmp = xstrdup(hex); cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, cgit_query_head, tmp, NULL); html("</td></tr>\n"); for (p = commit->parents; p ; p = p->next) { parent = lookup_commit_reference(p->item->object.sha1); if (!parent) { html("<tr><td colspan='3'>"); cgit_print_error("Error reading parent commit"); html("</td></tr>"); continue; } html("<tr><th>parent</th>" "<td colspan='2' class='sha1'>"); cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, cgit_query_head, sha1_to_hex(p->item->object.sha1)); html(" ("); cgit_diff_link("diff", NULL, NULL, cgit_query_head, hex, sha1_to_hex(p->item->object.sha1), NULL); html(")</td></tr>"); } if (cgit_repo->snapshots) { html("<tr><th>download</th><td colspan='2' class='sha1'>"); - cgit_print_snapshot_links(cgit_query_repo,hex,cgit_repo->snapshots); + cgit_print_snapshot_links(cgit_query_repo, cgit_query_head, + hex, cgit_repo->snapshots); html("</td></tr>"); } html("</table>\n"); html("<div class='commit-subject'>"); html_txt(info->subject); html("</div>"); html("<div class='commit-msg'>"); html_txt(info->msg); html("</div>"); if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { html("<div class='diffstat-header'>Diffstat</div>"); html("<table class='diffstat'>"); max_changes = 0; cgit_diff_commit(commit, inspect_filepair); for(i = 0; i<files; i++) print_fileinfo(&items[i]); html("</table>"); html("<div class='diffstat-summary'>"); htmlf("%d files changed, %d insertions, %d deletions (", files, total_adds, total_rems); cgit_diff_link("show diff", NULL, NULL, cgit_query_head, hex, NULL, NULL); html(")</div>"); } cgit_free_commitinfo(info); } diff --git a/ui-shared.c b/ui-shared.c index ca2ee82..5c5bcf3 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -198,64 +198,70 @@ void cgit_log_link(char *name, char *title, char *class, char *head, { char *delim; delim = repolink(title, class, "log", head, path); if (rev && strcmp(rev, cgit_query_head)) { html(delim); html("id="); html_attr(rev); delim = "&"; } if (ofs > 0) { html(delim); html("ofs="); htmlf("%d", ofs); } html("'>"); html_txt(name); html("</a>"); } void cgit_commit_link(char *name, char *title, char *class, char *head, char *rev) { if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { name[cgit_max_msg_len] = '\0'; name[cgit_max_msg_len - 1] = '.'; name[cgit_max_msg_len - 2] = '.'; name[cgit_max_msg_len - 3] = '.'; } reporevlink("commit", name, title, class, head, rev, NULL); } +void cgit_snapshot_link(char *name, char *title, char *class, char *head, + char *rev, char *archivename) +{ + reporevlink("snapshot", name, title, class, head, rev, archivename); +} + void cgit_diff_link(char *name, char *title, char *class, char *head, char *new_rev, char *old_rev, char *path) { char *delim; delim = repolink(title, class, "diff", head, path); if (new_rev && strcmp(new_rev, cgit_query_head)) { html(delim); html("id="); html_attr(new_rev); delim = "&"; } if (old_rev) { html(delim); html("id2="); html_attr(old_rev); } html("'>"); html_txt(name); html("</a>"); } void cgit_object_link(struct object *obj) { char *page, *arg, *url; if (obj->type == OBJ_COMMIT) { cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, cgit_query_head, sha1_to_hex(obj->sha1)); return; } else if (obj->type == OBJ_TREE) { page = "tree"; diff --git a/ui-snapshot.c b/ui-snapshot.c index d6be55b..f9879ed 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -36,110 +36,120 @@ static int write_compressed_tar_archive(struct archiver_args *args,const char *f chk_zero(close(STDOUT_FILENO), "Closing STDOUT redirected to compressor"); chk_non_negative(dup2(stdout2,STDOUT_FILENO), "Restoring uncompressed STDOUT"); chk_zero(close(stdout2), "Closing uncompressed STDOUT"); chk_zero(close(rw[1]), "Closing write end of pipe in parent"); chk_positive(waitpid(gzpid,&status,0), "Waiting on compressor process"); if(! ( WIFEXITED(status) && WEXITSTATUS(status)==0 ) ) cgit_print_error("Failed to compress archive"); return rv; } static int write_tar_gzip_archive(struct archiver_args *args) { return write_compressed_tar_archive(args,"gzip"); } static int write_tar_bzip2_archive(struct archiver_args *args) { return write_compressed_tar_archive(args,"bzip2"); } static const struct snapshot_archive_t { const char *suffix; const char *mimetype; write_archive_fn_t write_func; int bit; } snapshot_archives[] = { { ".zip", "application/x-zip", write_zip_archive, 0x1 }, { ".tar.gz", "application/x-tar", write_tar_gzip_archive, 0x2 }, { ".tar.bz2", "application/x-tar", write_tar_bzip2_archive, 0x4 }, { ".tar", "application/x-tar", write_tar_archive, 0x8 } }; -void cgit_print_snapshot(struct cacheitem *item, const char *hex, - const char *prefix, const char *filename, - int snapshots) +void cgit_print_snapshot(struct cacheitem *item, const char *head, + const char *hex, const char *prefix, + const char *filename, int snapshots) { int fnl = strlen(filename); - int f; - for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { + int f, n; + + n = sizeof(snapshot_archives) / sizeof(*snapshot_archives); + for(f=0; f<n; f++) { const struct snapshot_archive_t* sat = &snapshot_archives[f]; int sl; - if(!(snapshots&sat->bit)) continue; + if(!(snapshots & sat->bit)) + continue; sl = strlen(sat->suffix); if(fnl<sl || strcmp(&filename[fnl-sl],sat->suffix)) continue; struct archiver_args args; struct commit *commit; unsigned char sha1[20]; + if (!hex) + hex = head; if(get_sha1(hex, sha1)) { cgit_print_error(fmt("Bad object id: %s", hex)); return; } commit = lookup_commit_reference(sha1); if(!commit) { cgit_print_error(fmt("Not a commit reference: %s", hex)); return;; } memset(&args,0,sizeof(args)); args.base = fmt("%s/", prefix); args.tree = commit->tree; cgit_print_snapshot_start(sat->mimetype, filename, item); (*sat->write_func)(&args); return; } cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); } -void cgit_print_snapshot_links(const char *repo,const char *hex,int snapshots) +void cgit_print_snapshot_links(const char *repo, const char *head, + const char *hex, int snapshots) { char *filename; - int f; - for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { + int f, n; + + n = sizeof(snapshot_archives) / sizeof(*snapshot_archives); + for(f=0; f<n ;f++) { const struct snapshot_archive_t* sat = &snapshot_archives[f]; - if(!(snapshots&sat->bit)) continue; - filename = fmt("%s-%s%s",cgit_repobasename(repo),hex,sat->suffix); - htmlf("<a href='%s'>%s</a><br/>", - cgit_fileurl(repo,"snapshot",filename, - fmt("id=%s&name=%s",hex,filename)), filename); + if(!(snapshots & sat->bit)) + continue; + filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, + sat->suffix); + cgit_snapshot_link(filename, NULL, NULL, (char *)head, + (char *)hex, filename); + html("<br/>"); } } int cgit_parse_snapshots_mask(const char *str) { static const char *delim = " \t,:/|;"; int f, tl, rv = 0; /* favor legacy setting */ if(atoi(str)) return 1; for(;;) { str += strspn(str,delim); tl = strcspn(str,delim); if(!tl) break; for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { const struct snapshot_archive_t* sat = &snapshot_archives[f]; if(! ( strncmp(sat->suffix,str,tl) && strncmp(sat->suffix+1,str,tl-1) ) ) { rv |= sat->bit; break; } } str += tl; } return rv; } /* vim:set sw=8: */ |