author | Lars Hjemli <hjemli@gmail.com> | 2007-10-01 09:46:38 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-10-01 09:46:38 (UTC) |
commit | 1a6025b7a515a23ab4c83f4a5da468e00e4f0a38 (patch) (unidiff) | |
tree | 897fb29bf0d48a6c472221d6a2a32188dfcf8df9 /cgit.c | |
parent | f527a57c8a55f5fd315e1bc1cb338f5f4a9b20ae (diff) | |
download | cgit-1a6025b7a515a23ab4c83f4a5da468e00e4f0a38.zip cgit-1a6025b7a515a23ab4c83f4a5da468e00e4f0a38.tar.gz cgit-1a6025b7a515a23ab4c83f4a5da468e00e4f0a38.tar.bz2 |
Add prefix parameter to cgit_print_diff()
This allows a diff to be restricted to the path prefix specified in the url.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -46,129 +46,129 @@ static int cgit_prepare_cache(struct cacheitem *item) | |||
46 | } | 46 | } |
47 | 47 | ||
48 | static void cgit_print_repo_page(struct cacheitem *item) | 48 | static void cgit_print_repo_page(struct cacheitem *item) |
49 | { | 49 | { |
50 | char *title; | 50 | char *title; |
51 | int show_search; | 51 | int show_search; |
52 | 52 | ||
53 | if (!cgit_query_head) | 53 | if (!cgit_query_head) |
54 | cgit_query_head = cgit_repo->defbranch; | 54 | cgit_query_head = cgit_repo->defbranch; |
55 | 55 | ||
56 | if (chdir(cgit_repo->path)) { | 56 | if (chdir(cgit_repo->path)) { |
57 | title = fmt("%s - %s", cgit_root_title, "Bad request"); | 57 | title = fmt("%s - %s", cgit_root_title, "Bad request"); |
58 | cgit_print_docstart(title, item); | 58 | cgit_print_docstart(title, item); |
59 | cgit_print_pageheader(title, 0); | 59 | cgit_print_pageheader(title, 0); |
60 | cgit_print_error(fmt("Unable to scan repository: %s", | 60 | cgit_print_error(fmt("Unable to scan repository: %s", |
61 | strerror(errno))); | 61 | strerror(errno))); |
62 | cgit_print_docend(); | 62 | cgit_print_docend(); |
63 | return; | 63 | return; |
64 | } | 64 | } |
65 | 65 | ||
66 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); | 66 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); |
67 | show_search = 0; | 67 | show_search = 0; |
68 | setenv("GIT_DIR", cgit_repo->path, 1); | 68 | setenv("GIT_DIR", cgit_repo->path, 1); |
69 | 69 | ||
70 | if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { | 70 | if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { |
71 | cgit_print_snapshot(item, cgit_query_head, cgit_query_sha1, | 71 | cgit_print_snapshot(item, cgit_query_head, cgit_query_sha1, |
72 | cgit_repobasename(cgit_repo->url), | 72 | cgit_repobasename(cgit_repo->url), |
73 | cgit_query_path, | 73 | cgit_query_path, |
74 | cgit_repo->snapshots ); | 74 | cgit_repo->snapshots ); |
75 | return; | 75 | return; |
76 | } | 76 | } |
77 | 77 | ||
78 | if (cgit_cmd == CMD_BLOB) { | 78 | if (cgit_cmd == CMD_BLOB) { |
79 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); | 79 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); |
80 | return; | 80 | return; |
81 | } | 81 | } |
82 | 82 | ||
83 | show_search = (cgit_cmd == CMD_LOG); | 83 | show_search = (cgit_cmd == CMD_LOG); |
84 | cgit_print_docstart(title, item); | 84 | cgit_print_docstart(title, item); |
85 | if (!cgit_cmd) { | 85 | if (!cgit_cmd) { |
86 | cgit_print_pageheader("summary", show_search); | 86 | cgit_print_pageheader("summary", show_search); |
87 | cgit_print_summary(); | 87 | cgit_print_summary(); |
88 | cgit_print_docend(); | 88 | cgit_print_docend(); |
89 | return; | 89 | return; |
90 | } | 90 | } |
91 | 91 | ||
92 | cgit_print_pageheader(cgit_query_page, show_search); | 92 | cgit_print_pageheader(cgit_query_page, show_search); |
93 | 93 | ||
94 | switch(cgit_cmd) { | 94 | switch(cgit_cmd) { |
95 | case CMD_LOG: | 95 | case CMD_LOG: |
96 | cgit_print_log(cgit_query_sha1, cgit_query_ofs, | 96 | cgit_print_log(cgit_query_sha1, cgit_query_ofs, |
97 | cgit_max_commit_count, cgit_query_search, | 97 | cgit_max_commit_count, cgit_query_search, |
98 | cgit_query_path, 1); | 98 | cgit_query_path, 1); |
99 | break; | 99 | break; |
100 | case CMD_TREE: | 100 | case CMD_TREE: |
101 | cgit_print_tree(cgit_query_sha1, cgit_query_path); | 101 | cgit_print_tree(cgit_query_sha1, cgit_query_path); |
102 | break; | 102 | break; |
103 | case CMD_COMMIT: | 103 | case CMD_COMMIT: |
104 | cgit_print_commit(cgit_query_sha1); | 104 | cgit_print_commit(cgit_query_sha1); |
105 | break; | 105 | break; |
106 | case CMD_TAG: | 106 | case CMD_TAG: |
107 | cgit_print_tag(cgit_query_sha1); | 107 | cgit_print_tag(cgit_query_sha1); |
108 | break; | 108 | break; |
109 | case CMD_DIFF: | 109 | case CMD_DIFF: |
110 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2); | 110 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2, cgit_query_path); |
111 | break; | 111 | break; |
112 | default: | 112 | default: |
113 | cgit_print_error("Invalid request"); | 113 | cgit_print_error("Invalid request"); |
114 | } | 114 | } |
115 | cgit_print_docend(); | 115 | cgit_print_docend(); |
116 | } | 116 | } |
117 | 117 | ||
118 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) | 118 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
119 | { | 119 | { |
120 | static char buf[PATH_MAX]; | 120 | static char buf[PATH_MAX]; |
121 | int stdout2; | 121 | int stdout2; |
122 | 122 | ||
123 | getcwd(buf, sizeof(buf)); | 123 | getcwd(buf, sizeof(buf)); |
124 | item->st.st_mtime = time(NULL); | 124 | item->st.st_mtime = time(NULL); |
125 | 125 | ||
126 | if (use_cache) { | 126 | if (use_cache) { |
127 | stdout2 = chk_positive(dup(STDOUT_FILENO), | 127 | stdout2 = chk_positive(dup(STDOUT_FILENO), |
128 | "Preserving STDOUT"); | 128 | "Preserving STDOUT"); |
129 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); | 129 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); |
130 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); | 130 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); |
131 | } | 131 | } |
132 | 132 | ||
133 | if (cgit_repo) | 133 | if (cgit_repo) |
134 | cgit_print_repo_page(item); | 134 | cgit_print_repo_page(item); |
135 | else | 135 | else |
136 | cgit_print_repolist(item); | 136 | cgit_print_repolist(item); |
137 | 137 | ||
138 | if (use_cache) { | 138 | if (use_cache) { |
139 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); | 139 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); |
140 | chk_positive(dup2(stdout2, STDOUT_FILENO), | 140 | chk_positive(dup2(stdout2, STDOUT_FILENO), |
141 | "Restoring original STDOUT"); | 141 | "Restoring original STDOUT"); |
142 | chk_zero(close(stdout2), "Closing temporary STDOUT"); | 142 | chk_zero(close(stdout2), "Closing temporary STDOUT"); |
143 | } | 143 | } |
144 | 144 | ||
145 | chdir(buf); | 145 | chdir(buf); |
146 | } | 146 | } |
147 | 147 | ||
148 | static void cgit_check_cache(struct cacheitem *item) | 148 | static void cgit_check_cache(struct cacheitem *item) |
149 | { | 149 | { |
150 | int i = 0; | 150 | int i = 0; |
151 | 151 | ||
152 | top: | 152 | top: |
153 | if (++i > cgit_max_lock_attempts) { | 153 | if (++i > cgit_max_lock_attempts) { |
154 | die("cgit_refresh_cache: unable to lock %s: %s", | 154 | die("cgit_refresh_cache: unable to lock %s: %s", |
155 | item->name, strerror(errno)); | 155 | item->name, strerror(errno)); |
156 | } | 156 | } |
157 | if (!cache_exist(item)) { | 157 | if (!cache_exist(item)) { |
158 | if (!cache_lock(item)) { | 158 | if (!cache_lock(item)) { |
159 | sleep(1); | 159 | sleep(1); |
160 | goto top; | 160 | goto top; |
161 | } | 161 | } |
162 | if (!cache_exist(item)) { | 162 | if (!cache_exist(item)) { |
163 | cgit_fill_cache(item, 1); | 163 | cgit_fill_cache(item, 1); |
164 | cache_unlock(item); | 164 | cache_unlock(item); |
165 | } else { | 165 | } else { |
166 | cache_cancel_lock(item); | 166 | cache_cancel_lock(item); |
167 | } | 167 | } |
168 | } else if (cache_expired(item) && cache_lock(item)) { | 168 | } else if (cache_expired(item) && cache_lock(item)) { |
169 | if (cache_expired(item)) { | 169 | if (cache_expired(item)) { |
170 | cgit_fill_cache(item, 1); | 170 | cgit_fill_cache(item, 1); |
171 | cache_unlock(item); | 171 | cache_unlock(item); |
172 | } else { | 172 | } else { |
173 | cache_cancel_lock(item); | 173 | cache_cancel_lock(item); |
174 | } | 174 | } |