|
diff --git a/cgit.c b/cgit.c index 9b4815d..3e7e595 100644 --- a/ cgit.c+++ b/ cgit.c |
|
@@ -91,65 +91,66 @@ static void cgit_print_repo_page(struct cacheitem *item) |
91 | if (!strcmp(cgit_query_page, "blob")) { |
91 | if (!strcmp(cgit_query_page, "blob")) { |
92 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); |
92 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); |
93 | return; |
93 | return; |
94 | } |
94 | } |
95 | } |
95 | } |
96 | |
96 | |
97 | if (cgit_query_page && !strcmp(cgit_query_page, "log")) |
97 | if (cgit_query_page && !strcmp(cgit_query_page, "log")) |
98 | show_search = 1; |
98 | show_search = 1; |
99 | |
99 | |
100 | cgit_print_docstart(title, item); |
100 | cgit_print_docstart(title, item); |
101 | |
101 | |
102 | |
102 | |
103 | if (!cgit_query_page) { |
103 | if (!cgit_query_page) { |
104 | cgit_print_pageheader("summary", show_search); |
104 | cgit_print_pageheader("summary", show_search); |
105 | cgit_print_summary(); |
105 | cgit_print_summary(); |
106 | cgit_print_docend(); |
106 | cgit_print_docend(); |
107 | return; |
107 | return; |
108 | } |
108 | } |
109 | |
109 | |
110 | cgit_print_pageheader(cgit_query_page, show_search); |
110 | cgit_print_pageheader(cgit_query_page, show_search); |
111 | |
111 | |
112 | if (!strcmp(cgit_query_page, "log")) { |
112 | if (!strcmp(cgit_query_page, "log")) { |
113 | cgit_print_log(cgit_query_head, cgit_query_ofs, |
113 | cgit_print_log(cgit_query_head, cgit_query_ofs, |
114 | cgit_max_commit_count, cgit_query_search, |
114 | cgit_max_commit_count, cgit_query_search, |
115 | cgit_query_path); |
115 | cgit_query_path); |
116 | } else if (!strcmp(cgit_query_page, "tree")) { |
116 | } else if (!strcmp(cgit_query_page, "tree")) { |
117 | cgit_print_tree(cgit_query_head, cgit_query_sha1, cgit_query_path); |
117 | cgit_print_tree(cgit_query_head, cgit_query_sha1, cgit_query_path); |
118 | } else if (!strcmp(cgit_query_page, "commit")) { |
118 | } else if (!strcmp(cgit_query_page, "commit")) { |
119 | cgit_print_commit(cgit_query_head); |
119 | cgit_print_commit(cgit_query_head); |
120 | } else if (!strcmp(cgit_query_page, "view")) { |
120 | } else if (!strcmp(cgit_query_page, "view")) { |
121 | cgit_print_view(cgit_query_sha1, cgit_query_path); |
121 | cgit_print_view(cgit_query_sha1, cgit_query_path); |
122 | } else if (!strcmp(cgit_query_page, "diff")) { |
122 | } else if (!strcmp(cgit_query_page, "diff")) { |
123 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2, cgit_query_path); |
123 | cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2, |
| |
124 | cgit_query_path); |
124 | } else { |
125 | } else { |
125 | cgit_print_error("Invalid request"); |
126 | cgit_print_error("Invalid request"); |
126 | } |
127 | } |
127 | cgit_print_docend(); |
128 | cgit_print_docend(); |
128 | } |
129 | } |
129 | |
130 | |
130 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
131 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
131 | { |
132 | { |
132 | static char buf[PATH_MAX]; |
133 | static char buf[PATH_MAX]; |
133 | int stdout2; |
134 | int stdout2; |
134 | |
135 | |
135 | getcwd(buf, sizeof(buf)); |
136 | getcwd(buf, sizeof(buf)); |
136 | item->st.st_mtime = time(NULL); |
137 | item->st.st_mtime = time(NULL); |
137 | |
138 | |
138 | if (use_cache) { |
139 | if (use_cache) { |
139 | stdout2 = chk_positive(dup(STDOUT_FILENO), |
140 | stdout2 = chk_positive(dup(STDOUT_FILENO), |
140 | "Preserving STDOUT"); |
141 | "Preserving STDOUT"); |
141 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); |
142 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); |
142 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); |
143 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); |
143 | } |
144 | } |
144 | |
145 | |
145 | if (cgit_query_repo) |
146 | if (cgit_query_repo) |
146 | cgit_print_repo_page(item); |
147 | cgit_print_repo_page(item); |
147 | else |
148 | else |
148 | cgit_print_repolist(item); |
149 | cgit_print_repolist(item); |
149 | |
150 | |
150 | if (use_cache) { |
151 | if (use_cache) { |
151 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); |
152 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); |
152 | chk_positive(dup2(stdout2, STDOUT_FILENO), |
153 | chk_positive(dup2(stdout2, STDOUT_FILENO), |
153 | "Restoring original STDOUT"); |
154 | "Restoring original STDOUT"); |
154 | chk_zero(close(stdout2), "Closing temporary STDOUT"); |
155 | chk_zero(close(stdout2), "Closing temporary STDOUT"); |
155 | } |
156 | } |
|
|
diff --git a/cgit.h b/cgit.h index ac710a6..764225d 100644 --- a/ cgit.h+++ b/ cgit.h |
|
@@ -128,57 +128,58 @@ extern int cgit_diff_files(const unsigned char *old_sha1, |
128 | |
128 | |
129 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
129 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
130 | const unsigned char *new_sha1, |
130 | const unsigned char *new_sha1, |
131 | filepair_fn fn); |
131 | filepair_fn fn); |
132 | |
132 | |
133 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); |
133 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); |
134 | |
134 | |
135 | extern char *fmt(const char *format,...); |
135 | extern char *fmt(const char *format,...); |
136 | |
136 | |
137 | extern void html(const char *txt); |
137 | extern void html(const char *txt); |
138 | extern void htmlf(const char *format,...); |
138 | extern void htmlf(const char *format,...); |
139 | extern void html_txt(char *txt); |
139 | extern void html_txt(char *txt); |
140 | extern void html_ntxt(int len, char *txt); |
140 | extern void html_ntxt(int len, char *txt); |
141 | extern void html_attr(char *txt); |
141 | extern void html_attr(char *txt); |
142 | extern void html_hidden(char *name, char *value); |
142 | extern void html_hidden(char *name, char *value); |
143 | extern void html_link_open(char *url, char *title, char *class); |
143 | extern void html_link_open(char *url, char *title, char *class); |
144 | extern void html_link_close(void); |
144 | extern void html_link_close(void); |
145 | extern void html_filemode(unsigned short mode); |
145 | extern void html_filemode(unsigned short mode); |
146 | |
146 | |
147 | extern int cgit_read_config(const char *filename, configfn fn); |
147 | extern int cgit_read_config(const char *filename, configfn fn); |
148 | extern int cgit_parse_query(char *txt, configfn fn); |
148 | extern int cgit_parse_query(char *txt, configfn fn); |
149 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
149 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
150 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
150 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
151 | |
151 | |
152 | extern char *cache_safe_filename(const char *unsafe); |
152 | extern char *cache_safe_filename(const char *unsafe); |
153 | extern int cache_lock(struct cacheitem *item); |
153 | extern int cache_lock(struct cacheitem *item); |
154 | extern int cache_unlock(struct cacheitem *item); |
154 | extern int cache_unlock(struct cacheitem *item); |
155 | extern int cache_cancel_lock(struct cacheitem *item); |
155 | extern int cache_cancel_lock(struct cacheitem *item); |
156 | extern int cache_exist(struct cacheitem *item); |
156 | extern int cache_exist(struct cacheitem *item); |
157 | extern int cache_expired(struct cacheitem *item); |
157 | extern int cache_expired(struct cacheitem *item); |
158 | |
158 | |
159 | extern char *cgit_repourl(const char *reponame); |
159 | extern char *cgit_repourl(const char *reponame); |
160 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
160 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
161 | const char *query); |
161 | const char *query); |
162 | |
162 | |
163 | extern void cgit_print_error(char *msg); |
163 | extern void cgit_print_error(char *msg); |
164 | extern void cgit_print_date(unsigned long secs); |
164 | extern void cgit_print_date(unsigned long secs); |
165 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
165 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
166 | extern void cgit_print_docend(); |
166 | extern void cgit_print_docend(); |
167 | extern void cgit_print_pageheader(char *title, int show_search); |
167 | extern void cgit_print_pageheader(char *title, int show_search); |
168 | extern void cgit_print_snapshot_start(const char *mimetype, |
168 | extern void cgit_print_snapshot_start(const char *mimetype, |
169 | const char *filename, |
169 | const char *filename, |
170 | struct cacheitem *item); |
170 | struct cacheitem *item); |
171 | |
171 | |
172 | extern void cgit_print_repolist(struct cacheitem *item); |
172 | extern void cgit_print_repolist(struct cacheitem *item); |
173 | extern void cgit_print_summary(); |
173 | extern void cgit_print_summary(); |
174 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path); |
174 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path); |
175 | extern void cgit_print_view(const char *hex, char *path); |
175 | extern void cgit_print_view(const char *hex, char *path); |
176 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
176 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
177 | extern void cgit_print_tree(const char *rev, const char *hex, char *path); |
177 | extern void cgit_print_tree(const char *rev, const char *hex, char *path); |
178 | extern void cgit_print_commit(const char *hex); |
178 | extern void cgit_print_commit(const char *hex); |
179 | extern void cgit_print_diff(const char *old_hex, const char *new_hex, char *path); |
179 | extern void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex, |
180 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, |
180 | char *path); |
| |
181 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, |
181 | const char *format, const char *prefix, |
182 | const char *format, const char *prefix, |
182 | const char *filename); |
183 | const char *filename); |
183 | |
184 | |
184 | #endif /* CGIT_H */ |
185 | #endif /* CGIT_H */ |
|
|
diff --git a/ui-diff.c b/ui-diff.c index 999b6f3..afe1c90 100644 --- a/ ui-diff.c+++ b/ ui-diff.c |
|
@@ -37,69 +37,81 @@ static void header(unsigned char *sha1, char *path1, |
37 | char *abbrev1, *abbrev2; |
37 | char *abbrev1, *abbrev2; |
38 | if (is_null_sha1(sha1)) |
38 | if (is_null_sha1(sha1)) |
39 | path1 = "dev/null"; |
39 | path1 = "dev/null"; |
40 | if (is_null_sha1(sha2)) |
40 | if (is_null_sha1(sha2)) |
41 | path2 = "dev/null"; |
41 | path2 = "dev/null"; |
42 | html("<tr><td>"); |
42 | html("<tr><td>"); |
43 | html("<div class='head'>"); |
43 | html("<div class='head'>"); |
44 | html("diff --git a/"); |
44 | html("diff --git a/"); |
45 | html_txt(path1); |
45 | html_txt(path1); |
46 | html(" b/"); |
46 | html(" b/"); |
47 | html_txt(path2); |
47 | html_txt(path2); |
48 | abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); |
48 | abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); |
49 | abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); |
49 | abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); |
50 | htmlf("\nindex %s..%s", abbrev1, abbrev2); |
50 | htmlf("\nindex %s..%s", abbrev1, abbrev2); |
51 | free(abbrev1); |
51 | free(abbrev1); |
52 | free(abbrev2); |
52 | free(abbrev2); |
53 | html("\n--- a/"); |
53 | html("\n--- a/"); |
54 | html_txt(path1); |
54 | html_txt(path1); |
55 | html("\n+++ b/"); |
55 | html("\n+++ b/"); |
56 | html_txt(path2); |
56 | html_txt(path2); |
57 | html("</div>"); |
57 | html("</div>"); |
58 | } |
58 | } |
59 | |
59 | |
60 | static void filepair_cb(struct diff_filepair *pair) |
60 | static void filepair_cb(struct diff_filepair *pair) |
61 | { |
61 | { |
62 | header(pair->one->sha1, pair->one->path, |
62 | header(pair->one->sha1, pair->one->path, |
63 | pair->two->sha1, pair->two->path); |
63 | pair->two->sha1, pair->two->path); |
64 | if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line)) |
64 | if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line)) |
65 | cgit_print_error("Error running diff"); |
65 | cgit_print_error("Error running diff"); |
66 | html("</tr></td>"); |
66 | html("</tr></td>"); |
67 | } |
67 | } |
68 | |
68 | |
69 | void cgit_print_diff(const char *old_hex, const char *new_hex, char *path) |
69 | void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex, char *path) |
70 | { |
70 | { |
71 | unsigned char sha1[20], sha2[20]; |
71 | unsigned char sha1[20], sha2[20]; |
72 | enum object_type type; |
72 | enum object_type type; |
73 | unsigned long size; |
73 | unsigned long size; |
| |
74 | struct commit *commit; |
| |
75 | |
| |
76 | if (head && !old_hex && !new_hex) { |
| |
77 | get_sha1(head, sha1); |
| |
78 | commit = lookup_commit_reference(sha1); |
| |
79 | if (commit && !parse_commit(commit)) { |
| |
80 | html("<table class='diff'>"); |
| |
81 | cgit_diff_commit(commit, filepair_cb); |
| |
82 | html("</td></tr></table>"); |
| |
83 | } |
| |
84 | return; |
| |
85 | } |
74 | |
86 | |
75 | get_sha1(old_hex, sha1); |
87 | get_sha1(old_hex, sha1); |
76 | get_sha1(new_hex, sha2); |
88 | get_sha1(new_hex, sha2); |
77 | |
89 | |
78 | type = sha1_object_info(sha1, &size); |
90 | type = sha1_object_info(sha1, &size); |
79 | if (type == OBJ_BAD) { |
91 | if (type == OBJ_BAD) { |
80 | type = sha1_object_info(sha2, &size); |
92 | type = sha1_object_info(sha2, &size); |
81 | if (type == OBJ_BAD) { |
93 | if (type == OBJ_BAD) { |
82 | cgit_print_error(fmt("Bad object names: %s, %s", old_hex, new_hex)); |
94 | cgit_print_error(fmt("Bad object names: %s, %s", old_hex, new_hex)); |
83 | return; |
95 | return; |
84 | } |
96 | } |
85 | } |
97 | } |
86 | |
98 | |
87 | html("<table class='diff'>"); |
99 | html("<table class='diff'>"); |
88 | switch(type) { |
100 | switch(type) { |
89 | case OBJ_BLOB: |
101 | case OBJ_BLOB: |
90 | html("<tr><td>"); |
102 | html("<tr><td>"); |
91 | header(sha1, path, sha2, path); |
103 | header(sha1, path, sha2, path); |
92 | if (cgit_diff_files(sha1, sha2, print_line)) |
104 | if (cgit_diff_files(sha1, sha2, print_line)) |
93 | cgit_print_error("Error running diff"); |
105 | cgit_print_error("Error running diff"); |
94 | html("</tr></td>"); |
106 | html("</tr></td>"); |
95 | break; |
107 | break; |
96 | case OBJ_TREE: |
108 | case OBJ_TREE: |
97 | cgit_diff_tree(sha1, sha2, filepair_cb); |
109 | cgit_diff_tree(sha1, sha2, filepair_cb); |
98 | break; |
110 | break; |
99 | default: |
111 | default: |
100 | cgit_print_error(fmt("Unhandled object type: %s", |
112 | cgit_print_error(fmt("Unhandled object type: %s", |
101 | typename(type))); |
113 | typename(type))); |
102 | break; |
114 | break; |
103 | } |
115 | } |
104 | html("</td></tr></table>"); |
116 | html("</td></tr></table>"); |
105 | } |
117 | } |
|