diff options
author | Lars Hjemli | 2006-12-17 23:07:28 +0100 |
---|---|---|
committer | Lars Hjemli | 2006-12-17 23:07:28 +0100 |
commit | 6cb326c83b3c0b35d472305294afee3105b3088d (patch) | |
tree | fcceeec36ae6f1b3b8e9f861064e2d6ba962a6e0 | |
parent | Reformat code to avoid excessive line lengths (diff) | |
download | cgit-6cb326c83b3c0b35d472305294afee3105b3088d.tar.gz cgit-6cb326c83b3c0b35d472305294afee3105b3088d.zip |
Show list of modified files in ui-commit.c
Compare current commit with 1.parent, and for each affected file display current filemode, old filemode if changed, current filename and source filename if it was a copy/rename. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.css | 51 | ||||
-rw-r--r-- | cgit.h | 1 | ||||
-rw-r--r-- | git.h | 106 | ||||
-rw-r--r-- | html.c | 20 | ||||
-rw-r--r-- | ui-commit.c | 111 |
5 files changed, 281 insertions, 8 deletions
diff --git a/cgit.css b/cgit.css index 94372d6..ae304fa 100644 --- a/cgit.css +++ b/cgit.css | |||
@@ -3,7 +3,7 @@ body { | |||
3 | font-size: normal; | 3 | font-size: normal; |
4 | background: white; | 4 | background: white; |
5 | padding: 0em; | 5 | padding: 0em; |
6 | margin: 0.5em; | 6 | margin: 0.5em 1em; |
7 | } | 7 | } |
8 | 8 | ||
9 | 9 | ||
@@ -50,16 +50,19 @@ img { | |||
50 | 50 | ||
51 | 51 | ||
52 | div#header { | 52 | div#header { |
53 | background-color: #ddd; | 53 | background-color: #eee; |
54 | padding: 0.25em 0.25em 0.25em 0.5em; | 54 | padding: 0.25em 0.25em 0.25em 0.5em; |
55 | font-size: 150%; | 55 | font-size: 150%; |
56 | font-weight: bold; | 56 | font-weight: bold; |
57 | border: solid 1px #aaa; | 57 | border: solid 1px #ccc; |
58 | vertical-align: middle; | 58 | vertical-align: middle; |
59 | } | 59 | } |
60 | div#header img#logo { | 60 | div#header img#logo { |
61 | float: right; | 61 | float: right; |
62 | } | 62 | } |
63 | div#header a { | ||
64 | color: black; | ||
65 | } | ||
63 | 66 | ||
64 | div#content { | 67 | div#content { |
65 | margin: 0.5em 0.5em; | 68 | margin: 0.5em 0.5em; |
@@ -97,8 +100,7 @@ table.log td { | |||
97 | 100 | ||
98 | table.commit-info { | 101 | table.commit-info { |
99 | border-collapse: collapse; | 102 | border-collapse: collapse; |
100 | margin-top: 1em; | 103 | margin-top: 1.5em; |
101 | |||
102 | } | 104 | } |
103 | table.commit-info th { | 105 | table.commit-info th { |
104 | text-align: left; | 106 | text-align: left; |
@@ -111,14 +113,47 @@ table.commit-info td { | |||
111 | } | 113 | } |
112 | div.commit-subject { | 114 | div.commit-subject { |
113 | font-weight: bold; | 115 | font-weight: bold; |
114 | font-size: 110%; | 116 | font-size: 125%; |
115 | margin: 1em 0em 1em; | 117 | margin: 1.5em 0em 0.5em 0em; |
118 | padding: 0em; | ||
116 | } | 119 | } |
117 | div.commit-msg { | 120 | div.commit-msg { |
118 | white-space: pre; | 121 | white-space: pre; |
119 | font-family: courier; | 122 | font-family: monospace; |
123 | } | ||
124 | table.diffstat { | ||
125 | border-collapse: collapse; | ||
126 | margin-top: 1.5em; | ||
127 | } | ||
128 | table.diffstat th { | ||
129 | font-weight: normal; | ||
130 | text-align: left; | ||
131 | text-decoration: underline; | ||
132 | padding: 0.1em 1em 0.1em 0.1em; | ||
120 | font-size: 100%; | 133 | font-size: 100%; |
121 | } | 134 | } |
135 | table.diffstat td { | ||
136 | padding: 0.1em 1em 0.1em 0.1em; | ||
137 | font-size: 100%; | ||
138 | } | ||
139 | table.diffstat td span.modechange { | ||
140 | padding-left: 1em; | ||
141 | color: red; | ||
142 | } | ||
143 | table.diffstat td.add a { | ||
144 | color: green; | ||
145 | } | ||
146 | table.diffstat td.del a { | ||
147 | color: red; | ||
148 | } | ||
149 | table.diffstat td.upd a { | ||
150 | color: blue; | ||
151 | } | ||
152 | table.diffstat td.summary { | ||
153 | /* border-top: solid 1px black; */ | ||
154 | color: #888; | ||
155 | padding-top: 0.5em; | ||
156 | } | ||
122 | .sha1 { | 157 | .sha1 { |
123 | font-family: courier; | 158 | font-family: courier; |
124 | font-size: 90%; | 159 | font-size: 90%; |
diff --git a/cgit.h b/cgit.h index 02cc26a..37584d6 100644 --- a/cgit.h +++ b/cgit.h | |||
@@ -75,6 +75,7 @@ extern void html_txt(char *txt); | |||
75 | extern void html_attr(char *txt); | 75 | extern void html_attr(char *txt); |
76 | extern void html_link_open(char *url, char *title, char *class); | 76 | extern void html_link_open(char *url, char *title, char *class); |
77 | extern void html_link_close(void); | 77 | extern void html_link_close(void); |
78 | extern void html_filemode(unsigned short mode); | ||
78 | 79 | ||
79 | extern int cgit_read_config(const char *filename, configfn fn); | 80 | extern int cgit_read_config(const char *filename, configfn fn); |
80 | extern int cgit_parse_query(char *txt, configfn fn); | 81 | extern int cgit_parse_query(char *txt, configfn fn); |
diff --git a/git.h b/git.h index a3f977c..922a167 100644 --- a/git.h +++ b/git.h | |||
@@ -128,6 +128,8 @@ static inline ssize_t xwrite(int fd, const void *buf, size_t len) | |||
128 | #define MINIMUM_ABBREV 4 | 128 | #define MINIMUM_ABBREV 4 |
129 | #define DEFAULT_ABBREV 7 | 129 | #define DEFAULT_ABBREV 7 |
130 | 130 | ||
131 | extern const unsigned char null_sha1[20]; | ||
132 | |||
131 | extern int sha1_object_info(const unsigned char *, char *, unsigned long *); | 133 | extern int sha1_object_info(const unsigned char *, char *, unsigned long *); |
132 | 134 | ||
133 | extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size); | 135 | extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size); |
@@ -136,6 +138,24 @@ extern int get_sha1(const char *str, unsigned char *sha1); | |||
136 | extern int get_sha1_hex(const char *hex, unsigned char *sha1); | 138 | extern int get_sha1_hex(const char *hex, unsigned char *sha1); |
137 | extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */ | 139 | extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */ |
138 | 140 | ||
141 | static inline int is_null_sha1(const unsigned char *sha1) | ||
142 | { | ||
143 | return !memcmp(sha1, null_sha1, 20); | ||
144 | } | ||
145 | static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2) | ||
146 | { | ||
147 | return memcmp(sha1, sha2, 20); | ||
148 | } | ||
149 | static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src) | ||
150 | { | ||
151 | memcpy(sha_dst, sha_src, 20); | ||
152 | } | ||
153 | static inline void hashclr(unsigned char *hash) | ||
154 | { | ||
155 | memset(hash, 0, 20); | ||
156 | } | ||
157 | |||
158 | |||
139 | 159 | ||
140 | 160 | ||
141 | /* | 161 | /* |
@@ -257,6 +277,61 @@ typedef void* (*topo_sort_get_fn_t)(struct commit*); | |||
257 | 277 | ||
258 | 278 | ||
259 | 279 | ||
280 | /* | ||
281 | * from git:diffcore.h | ||
282 | */ | ||
283 | |||
284 | struct diff_filespec { | ||
285 | unsigned char sha1[20]; | ||
286 | char *path; | ||
287 | void *data; | ||
288 | void *cnt_data; | ||
289 | unsigned long size; | ||
290 | int xfrm_flags; /* for use by the xfrm */ | ||
291 | unsigned short mode; /* file mode */ | ||
292 | unsigned sha1_valid : 1; /* if true, use sha1 and trust mode; | ||
293 | * if false, use the name and read from | ||
294 | * the filesystem. | ||
295 | */ | ||
296 | #define DIFF_FILE_VALID(spec) (((spec)->mode) != 0) | ||
297 | unsigned should_free : 1; /* data should be free()'ed */ | ||
298 | unsigned should_munmap : 1; /* data should be munmap()'ed */ | ||
299 | }; | ||
300 | |||
301 | struct diff_filepair { | ||
302 | struct diff_filespec *one; | ||
303 | struct diff_filespec *two; | ||
304 | unsigned short int score; | ||
305 | char status; /* M C R N D U (see Documentation/diff-format.txt) */ | ||
306 | unsigned source_stays : 1; /* all of R/C are copies */ | ||
307 | unsigned broken_pair : 1; | ||
308 | unsigned renamed_pair : 1; | ||
309 | }; | ||
310 | |||
311 | #define DIFF_PAIR_UNMERGED(p) \ | ||
312 | (!DIFF_FILE_VALID((p)->one) && !DIFF_FILE_VALID((p)->two)) | ||
313 | |||
314 | #define DIFF_PAIR_RENAME(p) ((p)->renamed_pair) | ||
315 | |||
316 | #define DIFF_PAIR_BROKEN(p) \ | ||
317 | ( (!DIFF_FILE_VALID((p)->one) != !DIFF_FILE_VALID((p)->two)) && \ | ||
318 | ((p)->broken_pair != 0) ) | ||
319 | |||
320 | #define DIFF_PAIR_TYPE_CHANGED(p) \ | ||
321 | ((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode)) | ||
322 | |||
323 | #define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode) | ||
324 | |||
325 | extern void diff_free_filepair(struct diff_filepair *); | ||
326 | |||
327 | extern int diff_unmodified_pair(struct diff_filepair *); | ||
328 | |||
329 | struct diff_queue_struct { | ||
330 | struct diff_filepair **queue; | ||
331 | int alloc; | ||
332 | int nr; | ||
333 | }; | ||
334 | |||
260 | 335 | ||
261 | /* | 336 | /* |
262 | * from git:diff.h | 337 | * from git:diff.h |
@@ -352,6 +427,32 @@ enum color_diff { | |||
352 | }; | 427 | }; |
353 | 428 | ||
354 | 429 | ||
430 | extern int diff_tree_sha1(const unsigned char *old, const unsigned char *new, | ||
431 | const char *base, struct diff_options *opt); | ||
432 | |||
433 | extern int diff_root_tree_sha1(const unsigned char *new, const char *base, | ||
434 | struct diff_options *opt); | ||
435 | |||
436 | extern int git_diff_ui_config(const char *var, const char *value); | ||
437 | extern void diff_setup(struct diff_options *); | ||
438 | extern int diff_opt_parse(struct diff_options *, const char **, int); | ||
439 | extern int diff_setup_done(struct diff_options *); | ||
440 | |||
441 | |||
442 | extern void diffcore_std(struct diff_options *); | ||
443 | extern void diff_flush(struct diff_options*); | ||
444 | |||
445 | |||
446 | /* diff-raw status letters */ | ||
447 | #define DIFF_STATUS_ADDED 'A' | ||
448 | #define DIFF_STATUS_COPIED 'C' | ||
449 | #define DIFF_STATUS_DELETED 'D' | ||
450 | #define DIFF_STATUS_MODIFIED 'M' | ||
451 | #define DIFF_STATUS_RENAMED 'R' | ||
452 | #define DIFF_STATUS_TYPE_CHANGED 'T' | ||
453 | #define DIFF_STATUS_UNKNOWN 'X' | ||
454 | #define DIFF_STATUS_UNMERGED 'U' | ||
455 | |||
355 | 456 | ||
356 | 457 | ||
357 | /* | 458 | /* |
@@ -458,5 +559,10 @@ extern struct commit *get_revision(struct rev_info *revs); | |||
458 | 559 | ||
459 | 560 | ||
460 | 561 | ||
562 | /* from git:log-tree.h */ | ||
563 | |||
564 | int log_tree_commit(struct rev_info *, struct commit *); | ||
565 | |||
566 | |||
461 | 567 | ||
462 | #endif /* GIT_H */ | 568 | #endif /* GIT_H */ |
diff --git a/html.c b/html.c index fab67bd..8a69659 100644 --- a/html.c +++ b/html.c | |||
@@ -108,3 +108,23 @@ void html_link_close(void) | |||
108 | { | 108 | { |
109 | html("</a>"); | 109 | html("</a>"); |
110 | } | 110 | } |
111 | |||
112 | void html_fileperm(unsigned short mode) | ||
113 | { | ||
114 | htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), | ||
115 | (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); | ||
116 | } | ||
117 | |||
118 | void html_filemode(unsigned short mode) | ||
119 | { | ||
120 | if (S_ISDIR(mode)) | ||
121 | html("d"); | ||
122 | else if (S_ISLNK(mode)) | ||
123 | html("l"); | ||
124 | else | ||
125 | html("-"); | ||
126 | html_fileperm(mode >> 6); | ||
127 | html_fileperm(mode >> 3); | ||
128 | html_fileperm(mode); | ||
129 | } | ||
130 | |||
diff --git a/ui-commit.c b/ui-commit.c index 8916212..c5ee8e7 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -8,6 +8,111 @@ | |||
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | int files = 0; | ||
12 | |||
13 | void print_filepair(struct diff_filepair *pair) | ||
14 | { | ||
15 | char *query; | ||
16 | char *class; | ||
17 | |||
18 | switch (pair->status) { | ||
19 | case DIFF_STATUS_ADDED: | ||
20 | class = "add"; | ||
21 | break; | ||
22 | case DIFF_STATUS_COPIED: | ||
23 | class = "cpy"; | ||
24 | break; | ||
25 | case DIFF_STATUS_DELETED: | ||
26 | class = "del"; | ||
27 | break; | ||
28 | case DIFF_STATUS_MODIFIED: | ||
29 | class = "upd"; | ||
30 | break; | ||
31 | case DIFF_STATUS_RENAMED: | ||
32 | class = "mov"; | ||
33 | break; | ||
34 | case DIFF_STATUS_TYPE_CHANGED: | ||
35 | class = "typ"; | ||
36 | break; | ||
37 | case DIFF_STATUS_UNKNOWN: | ||
38 | class = "unk"; | ||
39 | break; | ||
40 | case DIFF_STATUS_UNMERGED: | ||
41 | class = "stg"; | ||
42 | break; | ||
43 | default: | ||
44 | die("bug: unhandled diff status %c", pair->status); | ||
45 | } | ||
46 | |||
47 | html("<tr>"); | ||
48 | htmlf("<td class='mode'>"); | ||
49 | html_filemode(pair->two->mode); | ||
50 | if (pair->one->mode != pair->two->mode) { | ||
51 | html("<span class='modechange'>["); | ||
52 | html_filemode(pair->one->mode); | ||
53 | html("]</span>"); | ||
54 | } | ||
55 | htmlf("</td><td class='%s'>", class); | ||
56 | query = fmt("id=%s", sha1_to_hex(pair->two->sha1)); | ||
57 | html_link_open(cgit_pageurl(cgit_query_repo, "view", query), | ||
58 | NULL, NULL); | ||
59 | if (pair->status == DIFF_STATUS_COPIED || | ||
60 | pair->status == DIFF_STATUS_RENAMED) { | ||
61 | html_txt(pair->two->path); | ||
62 | htmlf("</a> (%s from ", pair->status == DIFF_STATUS_COPIED ? | ||
63 | "copied" : "renamed"); | ||
64 | query = fmt("id=%s", sha1_to_hex(pair->one->sha1)); | ||
65 | html_link_open(cgit_pageurl(cgit_query_repo, "view", query), | ||
66 | NULL, NULL); | ||
67 | html_txt(pair->one->path); | ||
68 | html("</a>)"); | ||
69 | } else { | ||
70 | html_txt(pair->two->path); | ||
71 | html("</a>"); | ||
72 | } | ||
73 | html("<td>"); | ||
74 | |||
75 | //TODO: diffstat graph | ||
76 | |||
77 | html("</td></tr>\n"); | ||
78 | files++; | ||
79 | } | ||
80 | |||
81 | void diff_format_cb(struct diff_queue_struct *q, | ||
82 | struct diff_options *options, void *data) | ||
83 | { | ||
84 | int i; | ||
85 | |||
86 | for (i = 0; i < q->nr; i++) { | ||
87 | if (q->queue[i]->status == 'U') | ||
88 | continue; | ||
89 | print_filepair(q->queue[i]); | ||
90 | } | ||
91 | } | ||
92 | |||
93 | void cgit_diffstat(struct commit *commit) | ||
94 | { | ||
95 | struct diff_options opt; | ||
96 | int ret; | ||
97 | |||
98 | diff_setup(&opt); | ||
99 | opt.output_format = DIFF_FORMAT_CALLBACK; | ||
100 | opt.detect_rename = 1; | ||
101 | opt.recursive = 1; | ||
102 | opt.format_callback = diff_format_cb; | ||
103 | diff_setup_done(&opt); | ||
104 | |||
105 | if (commit->parents) | ||
106 | ret = diff_tree_sha1(commit->parents->item->object.sha1, | ||
107 | commit->object.sha1, | ||
108 | "", &opt); | ||
109 | else | ||
110 | ret = diff_root_tree_sha1(commit->object.sha1, "", &opt); | ||
111 | |||
112 | diffcore_std(&opt); | ||
113 | diff_flush(&opt); | ||
114 | } | ||
115 | |||
11 | void cgit_print_commit(const char *hex) | 116 | void cgit_print_commit(const char *hex) |
12 | { | 117 | { |
13 | struct commit *commit; | 118 | struct commit *commit; |
@@ -62,5 +167,11 @@ void cgit_print_commit(const char *hex) | |||
62 | html("<div class='commit-msg'>"); | 167 | html("<div class='commit-msg'>"); |
63 | html_txt(info->msg); | 168 | html_txt(info->msg); |
64 | html("</div>"); | 169 | html("</div>"); |
170 | html("<table class='diffstat'>"); | ||
171 | html("<tr><th colspan='3'>Affected files</tr>\n"); | ||
172 | cgit_diffstat(commit); | ||
173 | htmlf("<tr><td colspan='3' class='summary'>" | ||
174 | "%d file%s changed</td></tr>\n", files, files > 1 ? "s" : ""); | ||
175 | html("</table>"); | ||
65 | cgit_free_commitinfo(info); | 176 | cgit_free_commitinfo(info); |
66 | } | 177 | } |