author | Lars Hjemli <hjemli@gmail.com> | 2007-02-08 12:53:13 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-02-08 12:58:58 (UTC) |
commit | ab2ab95f09994560f62fd631f07d3b6e3577aa6e (patch) (unidiff) | |
tree | 846763c1bcb78bd27dc37c99e5f6d703ca5ab179 /cgit.c | |
parent | 14d360df60f059b9b5b045fc6df1eec6f0966d9a (diff) | |
download | cgit-ab2ab95f09994560f62fd631f07d3b6e3577aa6e.zip cgit-ab2ab95f09994560f62fd631f07d3b6e3577aa6e.tar.gz cgit-ab2ab95f09994560f62fd631f07d3b6e3577aa6e.tar.bz2 |
Add support for snapshots
Make a link from the commit viewer to a snapshot of the corresponding tree.
Currently only zip-format is supported.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 39 |
1 files changed, 32 insertions, 7 deletions
@@ -80,2 +80,9 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
80 | setenv("GIT_DIR", cgit_repo->path, 1); | 80 | setenv("GIT_DIR", cgit_repo->path, 1); |
81 | |||
82 | if (cgit_query_page && !strcmp(cgit_query_page, "snapshot")) { | ||
83 | cgit_print_snapshot(item, cgit_query_sha1, "zip", | ||
84 | cgit_repo->url, cgit_query_name); | ||
85 | return; | ||
86 | } | ||
87 | |||
81 | if (cgit_query_page && !strcmp(cgit_query_page, "log")) | 88 | if (cgit_query_page && !strcmp(cgit_query_page, "log")) |
@@ -87,3 +94,4 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
87 | } else if (!strcmp(cgit_query_page, "log")) { | 94 | } else if (!strcmp(cgit_query_page, "log")) { |
88 | cgit_print_log(cgit_query_head, cgit_query_ofs, 100, cgit_query_search); | 95 | cgit_print_log(cgit_query_head, cgit_query_ofs, 100, |
96 | cgit_query_search); | ||
89 | } else if (!strcmp(cgit_query_page, "tree")) { | 97 | } else if (!strcmp(cgit_query_page, "tree")) { |
@@ -96,2 +104,4 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
96 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2); | 104 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2); |
105 | } else { | ||
106 | cgit_print_error("Invalid request"); | ||
97 | } | 107 | } |
@@ -100,9 +110,17 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
100 | 110 | ||
101 | static void cgit_fill_cache(struct cacheitem *item) | 111 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
102 | { | 112 | { |
103 | static char buf[PATH_MAX]; | 113 | static char buf[PATH_MAX]; |
114 | int stdout2; | ||
104 | 115 | ||
105 | getcwd(buf, sizeof(buf)); | 116 | getcwd(buf, sizeof(buf)); |
106 | htmlfd = item->fd; | ||
107 | item->st.st_mtime = time(NULL); | 117 | item->st.st_mtime = time(NULL); |
118 | |||
119 | if (use_cache) { | ||
120 | stdout2 = chk_positive(dup(STDOUT_FILENO), | ||
121 | "Preserving STDOUT"); | ||
122 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); | ||
123 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); | ||
124 | } | ||
125 | |||
108 | if (cgit_query_repo) | 126 | if (cgit_query_repo) |
@@ -111,2 +129,10 @@ static void cgit_fill_cache(struct cacheitem *item) | |||
111 | cgit_print_repolist(item); | 129 | cgit_print_repolist(item); |
130 | |||
131 | if (use_cache) { | ||
132 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); | ||
133 | chk_positive(dup2(stdout2, STDOUT_FILENO), | ||
134 | "Restoring original STDOUT"); | ||
135 | chk_zero(close(stdout2), "Closing temporary STDOUT"); | ||
136 | } | ||
137 | |||
112 | chdir(buf); | 138 | chdir(buf); |
@@ -129,3 +155,3 @@ static void cgit_check_cache(struct cacheitem *item) | |||
129 | if (!cache_exist(item)) { | 155 | if (!cache_exist(item)) { |
130 | cgit_fill_cache(item); | 156 | cgit_fill_cache(item, 1); |
131 | cache_unlock(item); | 157 | cache_unlock(item); |
@@ -136,3 +162,3 @@ static void cgit_check_cache(struct cacheitem *item) | |||
136 | if (cache_expired(item)) { | 162 | if (cache_expired(item)) { |
137 | cgit_fill_cache(item); | 163 | cgit_fill_cache(item, 1); |
138 | cache_unlock(item); | 164 | cache_unlock(item); |
@@ -211,4 +237,3 @@ int main(int argc, const char **argv) | |||
211 | if (cgit_nocache) { | 237 | if (cgit_nocache) { |
212 | item.fd = STDOUT_FILENO; | 238 | cgit_fill_cache(&item, 0); |
213 | cgit_fill_cache(&item); | ||
214 | } else { | 239 | } else { |