author | Lars Hjemli <hjemli@gmail.com> | 2006-12-17 22:07:28 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2006-12-17 22:07:28 (UTC) |
commit | 6cb326c83b3c0b35d472305294afee3105b3088d (patch) (unidiff) | |
tree | fcceeec36ae6f1b3b8e9f861064e2d6ba962a6e0 | |
parent | 9c5229ea394808f90433ee84439503bee124e1de (diff) | |
download | cgit-6cb326c83b3c0b35d472305294afee3105b3088d.zip cgit-6cb326c83b3c0b35d472305294afee3105b3088d.tar.gz cgit-6cb326c83b3c0b35d472305294afee3105b3088d.tar.bz2 |
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
@@ -1,131 +1,166 @@ | |||
1 | body { | 1 | body { |
2 | font-family: arial; | 2 | font-family: arial; |
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 | ||
10 | h2 { | 10 | h2 { |
11 | font-size: normal; | 11 | font-size: normal; |
12 | font-weight: bold; | 12 | font-weight: bold; |
13 | margin-bottom: 0.1em; | 13 | margin-bottom: 0.1em; |
14 | } | 14 | } |
15 | 15 | ||
16 | a { | 16 | a { |
17 | color: blue; | 17 | color: blue; |
18 | text-decoration: none; | 18 | text-decoration: none; |
19 | } | 19 | } |
20 | 20 | ||
21 | a:hover { | 21 | a:hover { |
22 | text-decoration: underline; | 22 | text-decoration: underline; |
23 | } | 23 | } |
24 | 24 | ||
25 | table.list { | 25 | table.list { |
26 | border: solid 1px black; | 26 | border: solid 1px black; |
27 | border-collapse: collapse; | 27 | border-collapse: collapse; |
28 | border: solid 1px #aaa; | 28 | border: solid 1px #aaa; |
29 | } | 29 | } |
30 | table.list tr { | 30 | table.list tr { |
31 | background: white; | 31 | background: white; |
32 | } | 32 | } |
33 | table.list tr:hover { | 33 | table.list tr:hover { |
34 | background: #eee; | 34 | background: #eee; |
35 | } | 35 | } |
36 | table.list th { | 36 | table.list th { |
37 | font-weight: bold; | 37 | font-weight: bold; |
38 | background: #ddd; | 38 | background: #ddd; |
39 | border-bottom: solid 1px #aaa; | 39 | border-bottom: solid 1px #aaa; |
40 | padding: 0.1em 0.5em 0.1em 0.5em; | 40 | padding: 0.1em 0.5em 0.1em 0.5em; |
41 | vertical-align: baseline; | 41 | vertical-align: baseline; |
42 | } | 42 | } |
43 | table.list td { | 43 | table.list td { |
44 | border: none; | 44 | border: none; |
45 | padding: 0.1em 0.5em 0.1em 0.5em; | 45 | padding: 0.1em 0.5em 0.1em 0.5em; |
46 | } | 46 | } |
47 | img { | 47 | img { |
48 | border: none; | 48 | border: none; |
49 | } | 49 | } |
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; |
66 | } | 69 | } |
67 | 70 | ||
68 | div#blob { | 71 | div#blob { |
69 | border: solid 1px black; | 72 | border: solid 1px black; |
70 | } | 73 | } |
71 | 74 | ||
72 | div.error { | 75 | div.error { |
73 | color: red; | 76 | color: red; |
74 | font-weight: bold; | 77 | font-weight: bold; |
75 | margin: 1em 2em; | 78 | margin: 1em 2em; |
76 | } | 79 | } |
77 | div.ls-dir a { | 80 | div.ls-dir a { |
78 | font-weight: bold; | 81 | font-weight: bold; |
79 | } | 82 | } |
80 | th.filesize, td.filesize { | 83 | th.filesize, td.filesize { |
81 | text-align: right; | 84 | text-align: right; |
82 | } | 85 | } |
83 | th.filemode, td.filemode { | 86 | th.filemode, td.filemode { |
84 | text-align: center; | 87 | text-align: center; |
85 | } | 88 | } |
86 | 89 | ||
87 | td.blob { | 90 | td.blob { |
88 | white-space: pre; | 91 | white-space: pre; |
89 | font-family: courier; | 92 | font-family: courier; |
90 | font-size: 100%; | 93 | font-size: 100%; |
91 | background-color: white; | 94 | background-color: white; |
92 | } | 95 | } |
93 | 96 | ||
94 | table.log td { | 97 | table.log td { |
95 | white-space: nowrap; | 98 | white-space: nowrap; |
96 | } | 99 | } |
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; |
105 | font-weight: normal; | 107 | font-weight: normal; |
106 | padding: 0.1em 1em 0.1em 0.1em; | 108 | padding: 0.1em 1em 0.1em 0.1em; |
107 | } | 109 | } |
108 | table.commit-info td { | 110 | table.commit-info td { |
109 | font-weight: normal; | 111 | font-weight: normal; |
110 | padding: 0.1em 1em 0.1em 0.1em; | 112 | padding: 0.1em 1em 0.1em 0.1em; |
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%; |
125 | } | 160 | } |
126 | .left { | 161 | .left { |
127 | text-align: left; | 162 | text-align: left; |
128 | } | 163 | } |
129 | .right { | 164 | .right { |
130 | text-align: right; | 165 | text-align: right; |
131 | } | 166 | } |
@@ -1,107 +1,108 @@ | |||
1 | #ifndef CGIT_H | 1 | #ifndef CGIT_H |
2 | #define CGIT_H | 2 | #define CGIT_H |
3 | 3 | ||
4 | #include "git.h" | 4 | #include "git.h" |
5 | #include <openssl/sha.h> | 5 | #include <openssl/sha.h> |
6 | #include <ctype.h> | 6 | #include <ctype.h> |
7 | #include <sched.h> | 7 | #include <sched.h> |
8 | 8 | ||
9 | typedef void (*configfn)(const char *name, const char *value); | 9 | typedef void (*configfn)(const char *name, const char *value); |
10 | 10 | ||
11 | struct cacheitem { | 11 | struct cacheitem { |
12 | char *name; | 12 | char *name; |
13 | struct stat st; | 13 | struct stat st; |
14 | int ttl; | 14 | int ttl; |
15 | int fd; | 15 | int fd; |
16 | }; | 16 | }; |
17 | 17 | ||
18 | struct commitinfo { | 18 | struct commitinfo { |
19 | struct commit *commit; | 19 | struct commit *commit; |
20 | char *author; | 20 | char *author; |
21 | char *author_email; | 21 | char *author_email; |
22 | unsigned long author_date; | 22 | unsigned long author_date; |
23 | char *committer; | 23 | char *committer; |
24 | char *committer_email; | 24 | char *committer_email; |
25 | unsigned long committer_date; | 25 | unsigned long committer_date; |
26 | char *subject; | 26 | char *subject; |
27 | char *msg; | 27 | char *msg; |
28 | }; | 28 | }; |
29 | 29 | ||
30 | extern const char cgit_version[]; | 30 | extern const char cgit_version[]; |
31 | 31 | ||
32 | extern char *cgit_root; | 32 | extern char *cgit_root; |
33 | extern char *cgit_root_title; | 33 | extern char *cgit_root_title; |
34 | extern char *cgit_css; | 34 | extern char *cgit_css; |
35 | extern char *cgit_logo; | 35 | extern char *cgit_logo; |
36 | extern char *cgit_logo_link; | 36 | extern char *cgit_logo_link; |
37 | extern char *cgit_virtual_root; | 37 | extern char *cgit_virtual_root; |
38 | extern char *cgit_cache_root; | 38 | extern char *cgit_cache_root; |
39 | 39 | ||
40 | extern int cgit_nocache; | 40 | extern int cgit_nocache; |
41 | extern int cgit_max_lock_attempts; | 41 | extern int cgit_max_lock_attempts; |
42 | extern int cgit_cache_root_ttl; | 42 | extern int cgit_cache_root_ttl; |
43 | extern int cgit_cache_repo_ttl; | 43 | extern int cgit_cache_repo_ttl; |
44 | extern int cgit_cache_dynamic_ttl; | 44 | extern int cgit_cache_dynamic_ttl; |
45 | extern int cgit_cache_static_ttl; | 45 | extern int cgit_cache_static_ttl; |
46 | extern int cgit_cache_max_create_time; | 46 | extern int cgit_cache_max_create_time; |
47 | 47 | ||
48 | extern char *cgit_repo_name; | 48 | extern char *cgit_repo_name; |
49 | extern char *cgit_repo_desc; | 49 | extern char *cgit_repo_desc; |
50 | extern char *cgit_repo_owner; | 50 | extern char *cgit_repo_owner; |
51 | 51 | ||
52 | extern int cgit_query_has_symref; | 52 | extern int cgit_query_has_symref; |
53 | extern int cgit_query_has_sha1; | 53 | extern int cgit_query_has_sha1; |
54 | 54 | ||
55 | extern char *cgit_querystring; | 55 | extern char *cgit_querystring; |
56 | extern char *cgit_query_repo; | 56 | extern char *cgit_query_repo; |
57 | extern char *cgit_query_page; | 57 | extern char *cgit_query_page; |
58 | extern char *cgit_query_head; | 58 | extern char *cgit_query_head; |
59 | extern char *cgit_query_sha1; | 59 | extern char *cgit_query_sha1; |
60 | extern int cgit_query_ofs; | 60 | extern int cgit_query_ofs; |
61 | 61 | ||
62 | extern int htmlfd; | 62 | extern int htmlfd; |
63 | 63 | ||
64 | extern void cgit_global_config_cb(const char *name, const char *value); | 64 | extern void cgit_global_config_cb(const char *name, const char *value); |
65 | extern void cgit_repo_config_cb(const char *name, const char *value); | 65 | extern void cgit_repo_config_cb(const char *name, const char *value); |
66 | extern void cgit_querystring_cb(const char *name, const char *value); | 66 | extern void cgit_querystring_cb(const char *name, const char *value); |
67 | 67 | ||
68 | extern void *cgit_free_commitinfo(struct commitinfo *info); | 68 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
69 | 69 | ||
70 | extern char *fmt(const char *format,...); | 70 | extern char *fmt(const char *format,...); |
71 | 71 | ||
72 | extern void html(const char *txt); | 72 | extern void html(const char *txt); |
73 | extern void htmlf(const char *format,...); | 73 | extern void htmlf(const char *format,...); |
74 | extern void html_txt(char *txt); | 74 | 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); |
81 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 82 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
82 | 83 | ||
83 | extern void cache_prepare(struct cacheitem *item); | 84 | extern void cache_prepare(struct cacheitem *item); |
84 | extern int cache_lock(struct cacheitem *item); | 85 | extern int cache_lock(struct cacheitem *item); |
85 | extern int cache_unlock(struct cacheitem *item); | 86 | extern int cache_unlock(struct cacheitem *item); |
86 | extern int cache_cancel_lock(struct cacheitem *item); | 87 | extern int cache_cancel_lock(struct cacheitem *item); |
87 | extern int cache_exist(struct cacheitem *item); | 88 | extern int cache_exist(struct cacheitem *item); |
88 | extern int cache_expired(struct cacheitem *item); | 89 | extern int cache_expired(struct cacheitem *item); |
89 | 90 | ||
90 | extern char *cgit_repourl(const char *reponame); | 91 | extern char *cgit_repourl(const char *reponame); |
91 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 92 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
92 | const char *query); | 93 | const char *query); |
93 | 94 | ||
94 | extern void cgit_print_error(char *msg); | 95 | extern void cgit_print_error(char *msg); |
95 | extern void cgit_print_date(unsigned long secs); | 96 | extern void cgit_print_date(unsigned long secs); |
96 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 97 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
97 | extern void cgit_print_docend(); | 98 | extern void cgit_print_docend(); |
98 | extern void cgit_print_pageheader(char *title); | 99 | extern void cgit_print_pageheader(char *title); |
99 | 100 | ||
100 | extern void cgit_print_repolist(struct cacheitem *item); | 101 | extern void cgit_print_repolist(struct cacheitem *item); |
101 | extern void cgit_print_summary(); | 102 | extern void cgit_print_summary(); |
102 | extern void cgit_print_log(const char *tip, int ofs, int cnt); | 103 | extern void cgit_print_log(const char *tip, int ofs, int cnt); |
103 | extern void cgit_print_view(const char *hex); | 104 | extern void cgit_print_view(const char *hex); |
104 | extern void cgit_print_tree(const char *hex); | 105 | extern void cgit_print_tree(const char *hex); |
105 | extern void cgit_print_commit(const char *hex); | 106 | extern void cgit_print_commit(const char *hex); |
106 | 107 | ||
107 | #endif /* CGIT_H */ | 108 | #endif /* CGIT_H */ |
@@ -1,462 +1,568 @@ | |||
1 | #ifndef GIT_H | 1 | #ifndef GIT_H |
2 | #define GIT_H | 2 | #define GIT_H |
3 | 3 | ||
4 | 4 | ||
5 | /* | 5 | /* |
6 | * from git:git-compat-util.h | 6 | * from git:git-compat-util.h |
7 | */ | 7 | */ |
8 | 8 | ||
9 | 9 | ||
10 | #ifndef FLEX_ARRAY | 10 | #ifndef FLEX_ARRAY |
11 | #if defined(__GNUC__) && (__GNUC__ < 3) | 11 | #if defined(__GNUC__) && (__GNUC__ < 3) |
12 | #define FLEX_ARRAY 0 | 12 | #define FLEX_ARRAY 0 |
13 | #else | 13 | #else |
14 | #define FLEX_ARRAY /* empty */ | 14 | #define FLEX_ARRAY /* empty */ |
15 | #endif | 15 | #endif |
16 | #endif | 16 | #endif |
17 | 17 | ||
18 | 18 | ||
19 | #include <unistd.h> | 19 | #include <unistd.h> |
20 | #include <stdio.h> | 20 | #include <stdio.h> |
21 | #include <sys/stat.h> | 21 | #include <sys/stat.h> |
22 | #include <fcntl.h> | 22 | #include <fcntl.h> |
23 | #include <stddef.h> | 23 | #include <stddef.h> |
24 | #include <stdlib.h> | 24 | #include <stdlib.h> |
25 | #include <stdarg.h> | 25 | #include <stdarg.h> |
26 | #include <string.h> | 26 | #include <string.h> |
27 | #include <errno.h> | 27 | #include <errno.h> |
28 | #include <limits.h> | 28 | #include <limits.h> |
29 | #include <sys/param.h> | 29 | #include <sys/param.h> |
30 | #include <netinet/in.h> | 30 | #include <netinet/in.h> |
31 | #include <sys/types.h> | 31 | #include <sys/types.h> |
32 | #include <dirent.h> | 32 | #include <dirent.h> |
33 | #include <time.h> | 33 | #include <time.h> |
34 | 34 | ||
35 | 35 | ||
36 | /* On most systems <limits.h> would have given us this, but | 36 | /* On most systems <limits.h> would have given us this, but |
37 | * not on some systems (e.g. GNU/Hurd). | 37 | * not on some systems (e.g. GNU/Hurd). |
38 | */ | 38 | */ |
39 | #ifndef PATH_MAX | 39 | #ifndef PATH_MAX |
40 | #define PATH_MAX 4096 | 40 | #define PATH_MAX 4096 |
41 | #endif | 41 | #endif |
42 | 42 | ||
43 | #ifdef __GNUC__ | 43 | #ifdef __GNUC__ |
44 | #define NORETURN __attribute__((__noreturn__)) | 44 | #define NORETURN __attribute__((__noreturn__)) |
45 | #else | 45 | #else |
46 | #define NORETURN | 46 | #define NORETURN |
47 | #ifndef __attribute__ | 47 | #ifndef __attribute__ |
48 | #define __attribute__(x) | 48 | #define __attribute__(x) |
49 | #endif | 49 | #endif |
50 | #endif | 50 | #endif |
51 | 51 | ||
52 | 52 | ||
53 | extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); | 53 | extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); |
54 | 54 | ||
55 | 55 | ||
56 | static inline char* xstrdup(const char *str) | 56 | static inline char* xstrdup(const char *str) |
57 | { | 57 | { |
58 | char *ret = strdup(str); | 58 | char *ret = strdup(str); |
59 | if (!ret) | 59 | if (!ret) |
60 | die("Out of memory, strdup failed"); | 60 | die("Out of memory, strdup failed"); |
61 | return ret; | 61 | return ret; |
62 | } | 62 | } |
63 | 63 | ||
64 | static inline void *xmalloc(size_t size) | 64 | static inline void *xmalloc(size_t size) |
65 | { | 65 | { |
66 | void *ret = malloc(size); | 66 | void *ret = malloc(size); |
67 | if (!ret && !size) | 67 | if (!ret && !size) |
68 | ret = malloc(1); | 68 | ret = malloc(1); |
69 | if (!ret) | 69 | if (!ret) |
70 | die("Out of memory, malloc failed"); | 70 | die("Out of memory, malloc failed"); |
71 | #ifdef XMALLOC_POISON | 71 | #ifdef XMALLOC_POISON |
72 | memset(ret, 0xA5, size); | 72 | memset(ret, 0xA5, size); |
73 | #endif | 73 | #endif |
74 | return ret; | 74 | return ret; |
75 | } | 75 | } |
76 | 76 | ||
77 | static inline void *xrealloc(void *ptr, size_t size) | 77 | static inline void *xrealloc(void *ptr, size_t size) |
78 | { | 78 | { |
79 | void *ret = realloc(ptr, size); | 79 | void *ret = realloc(ptr, size); |
80 | if (!ret && !size) | 80 | if (!ret && !size) |
81 | ret = realloc(ptr, 1); | 81 | ret = realloc(ptr, 1); |
82 | if (!ret) | 82 | if (!ret) |
83 | die("Out of memory, realloc failed"); | 83 | die("Out of memory, realloc failed"); |
84 | return ret; | 84 | return ret; |
85 | } | 85 | } |
86 | 86 | ||
87 | static inline void *xcalloc(size_t nmemb, size_t size) | 87 | static inline void *xcalloc(size_t nmemb, size_t size) |
88 | { | 88 | { |
89 | void *ret = calloc(nmemb, size); | 89 | void *ret = calloc(nmemb, size); |
90 | if (!ret && (!nmemb || !size)) | 90 | if (!ret && (!nmemb || !size)) |
91 | ret = calloc(1, 1); | 91 | ret = calloc(1, 1); |
92 | if (!ret) | 92 | if (!ret) |
93 | die("Out of memory, calloc failed"); | 93 | die("Out of memory, calloc failed"); |
94 | return ret; | 94 | return ret; |
95 | } | 95 | } |
96 | 96 | ||
97 | static inline ssize_t xread(int fd, void *buf, size_t len) | 97 | static inline ssize_t xread(int fd, void *buf, size_t len) |
98 | { | 98 | { |
99 | ssize_t nr; | 99 | ssize_t nr; |
100 | while (1) { | 100 | while (1) { |
101 | nr = read(fd, buf, len); | 101 | nr = read(fd, buf, len); |
102 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) | 102 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) |
103 | continue; | 103 | continue; |
104 | return nr; | 104 | return nr; |
105 | } | 105 | } |
106 | } | 106 | } |
107 | 107 | ||
108 | static inline ssize_t xwrite(int fd, const void *buf, size_t len) | 108 | static inline ssize_t xwrite(int fd, const void *buf, size_t len) |
109 | { | 109 | { |
110 | ssize_t nr; | 110 | ssize_t nr; |
111 | while (1) { | 111 | while (1) { |
112 | nr = write(fd, buf, len); | 112 | nr = write(fd, buf, len); |
113 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) | 113 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) |
114 | continue; | 114 | continue; |
115 | return nr; | 115 | return nr; |
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | 119 | ||
120 | 120 | ||
121 | 121 | ||
122 | /* | 122 | /* |
123 | * from git:cache.h | 123 | * from git:cache.h |
124 | */ | 124 | */ |
125 | 125 | ||
126 | 126 | ||
127 | /* Convert to/from hex/sha1 representation */ | 127 | /* Convert to/from hex/sha1 representation */ |
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); |
134 | 136 | ||
135 | extern int get_sha1(const char *str, unsigned char *sha1); | 137 | 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 | /* |
142 | * from git:object.h | 162 | * from git:object.h |
143 | */ | 163 | */ |
144 | 164 | ||
145 | struct object_list { | 165 | struct object_list { |
146 | struct object *item; | 166 | struct object *item; |
147 | struct object_list *next; | 167 | struct object_list *next; |
148 | }; | 168 | }; |
149 | 169 | ||
150 | struct object_refs { | 170 | struct object_refs { |
151 | unsigned count; | 171 | unsigned count; |
152 | struct object *base; | 172 | struct object *base; |
153 | struct object *ref[FLEX_ARRAY]; /* more */ | 173 | struct object *ref[FLEX_ARRAY]; /* more */ |
154 | }; | 174 | }; |
155 | 175 | ||
156 | struct object_array { | 176 | struct object_array { |
157 | unsigned int nr; | 177 | unsigned int nr; |
158 | unsigned int alloc; | 178 | unsigned int alloc; |
159 | struct object_array_entry { | 179 | struct object_array_entry { |
160 | struct object *item; | 180 | struct object *item; |
161 | const char *name; | 181 | const char *name; |
162 | } *objects; | 182 | } *objects; |
163 | }; | 183 | }; |
164 | 184 | ||
165 | #define TYPE_BITS 3 | 185 | #define TYPE_BITS 3 |
166 | #define FLAG_BITS 27 | 186 | #define FLAG_BITS 27 |
167 | 187 | ||
168 | /* | 188 | /* |
169 | * The object type is stored in 3 bits. | 189 | * The object type is stored in 3 bits. |
170 | */ | 190 | */ |
171 | struct object { | 191 | struct object { |
172 | unsigned parsed : 1; | 192 | unsigned parsed : 1; |
173 | unsigned used : 1; | 193 | unsigned used : 1; |
174 | unsigned type : TYPE_BITS; | 194 | unsigned type : TYPE_BITS; |
175 | unsigned flags : FLAG_BITS; | 195 | unsigned flags : FLAG_BITS; |
176 | unsigned char sha1[20]; | 196 | unsigned char sha1[20]; |
177 | }; | 197 | }; |
178 | 198 | ||
179 | 199 | ||
180 | /* | 200 | /* |
181 | * from git:tree.h | 201 | * from git:tree.h |
182 | */ | 202 | */ |
183 | 203 | ||
184 | struct tree { | 204 | struct tree { |
185 | struct object object; | 205 | struct object object; |
186 | void *buffer; | 206 | void *buffer; |
187 | unsigned long size; | 207 | unsigned long size; |
188 | }; | 208 | }; |
189 | 209 | ||
190 | 210 | ||
191 | struct tree *lookup_tree(const unsigned char *sha1); | 211 | struct tree *lookup_tree(const unsigned char *sha1); |
192 | int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size); | 212 | int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size); |
193 | int parse_tree(struct tree *tree); | 213 | int parse_tree(struct tree *tree); |
194 | struct tree *parse_tree_indirect(const unsigned char *sha1); | 214 | struct tree *parse_tree_indirect(const unsigned char *sha1); |
195 | 215 | ||
196 | typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const char *, unsigned int, int); | 216 | typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const char *, unsigned int, int); |
197 | 217 | ||
198 | extern int read_tree_recursive(struct tree *tree, | 218 | extern int read_tree_recursive(struct tree *tree, |
199 | const char *base, int baselen, | 219 | const char *base, int baselen, |
200 | int stage, const char **match, | 220 | int stage, const char **match, |
201 | read_tree_fn_t fn); | 221 | read_tree_fn_t fn); |
202 | 222 | ||
203 | extern int read_tree(struct tree *tree, int stage, const char **paths); | 223 | extern int read_tree(struct tree *tree, int stage, const char **paths); |
204 | 224 | ||
205 | 225 | ||
206 | /* from git:commit.h */ | 226 | /* from git:commit.h */ |
207 | 227 | ||
208 | struct commit_list { | 228 | struct commit_list { |
209 | struct commit *item; | 229 | struct commit *item; |
210 | struct commit_list *next; | 230 | struct commit_list *next; |
211 | }; | 231 | }; |
212 | 232 | ||
213 | struct commit { | 233 | struct commit { |
214 | struct object object; | 234 | struct object object; |
215 | void *util; | 235 | void *util; |
216 | unsigned long date; | 236 | unsigned long date; |
217 | struct commit_list *parents; | 237 | struct commit_list *parents; |
218 | struct tree *tree; | 238 | struct tree *tree; |
219 | char *buffer; | 239 | char *buffer; |
220 | }; | 240 | }; |
221 | 241 | ||
222 | 242 | ||
223 | struct commit *lookup_commit(const unsigned char *sha1); | 243 | struct commit *lookup_commit(const unsigned char *sha1); |
224 | struct commit *lookup_commit_reference(const unsigned char *sha1); | 244 | struct commit *lookup_commit_reference(const unsigned char *sha1); |
225 | struct commit *lookup_commit_reference_gently(const unsigned char *sha1, | 245 | struct commit *lookup_commit_reference_gently(const unsigned char *sha1, |
226 | int quiet); | 246 | int quiet); |
227 | 247 | ||
228 | int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size); | 248 | int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size); |
229 | int parse_commit(struct commit *item); | 249 | int parse_commit(struct commit *item); |
230 | 250 | ||
231 | struct commit_list * commit_list_insert(struct commit *item, struct commit_list **list_p); | 251 | struct commit_list * commit_list_insert(struct commit *item, struct commit_list **list_p); |
232 | struct commit_list * insert_by_date(struct commit *item, struct commit_list **list); | 252 | struct commit_list * insert_by_date(struct commit *item, struct commit_list **list); |
233 | 253 | ||
234 | void free_commit_list(struct commit_list *list); | 254 | void free_commit_list(struct commit_list *list); |
235 | 255 | ||
236 | void sort_by_date(struct commit_list **list); | 256 | void sort_by_date(struct commit_list **list); |
237 | 257 | ||
238 | /* Commit formats */ | 258 | /* Commit formats */ |
239 | enum cmit_fmt { | 259 | enum cmit_fmt { |
240 | CMIT_FMT_RAW, | 260 | CMIT_FMT_RAW, |
241 | CMIT_FMT_MEDIUM, | 261 | CMIT_FMT_MEDIUM, |
242 | CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM, | 262 | CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM, |
243 | CMIT_FMT_SHORT, | 263 | CMIT_FMT_SHORT, |
244 | CMIT_FMT_FULL, | 264 | CMIT_FMT_FULL, |
245 | CMIT_FMT_FULLER, | 265 | CMIT_FMT_FULLER, |
246 | CMIT_FMT_ONELINE, | 266 | CMIT_FMT_ONELINE, |
247 | CMIT_FMT_EMAIL, | 267 | CMIT_FMT_EMAIL, |
248 | 268 | ||
249 | CMIT_FMT_UNSPECIFIED, | 269 | CMIT_FMT_UNSPECIFIED, |
250 | }; | 270 | }; |
251 | 271 | ||
252 | extern unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *, unsigned long len, char *buf, unsigned long space, int abbrev, const char *subject, const char *after_subject, int relative_date); | 272 | extern unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *, unsigned long len, char *buf, unsigned long space, int abbrev, const char *subject, const char *after_subject, int relative_date); |
253 | 273 | ||
254 | 274 | ||
255 | typedef void (*topo_sort_set_fn_t)(struct commit*, void *data); | 275 | typedef void (*topo_sort_set_fn_t)(struct commit*, void *data); |
256 | typedef void* (*topo_sort_get_fn_t)(struct commit*); | 276 | 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 |
263 | */ | 338 | */ |
264 | 339 | ||
265 | 340 | ||
266 | struct rev_info; | 341 | struct rev_info; |
267 | struct diff_options; | 342 | struct diff_options; |
268 | struct diff_queue_struct; | 343 | struct diff_queue_struct; |
269 | 344 | ||
270 | typedef void (*change_fn_t)(struct diff_options *options, | 345 | typedef void (*change_fn_t)(struct diff_options *options, |
271 | unsigned old_mode, unsigned new_mode, | 346 | unsigned old_mode, unsigned new_mode, |
272 | const unsigned char *old_sha1, | 347 | const unsigned char *old_sha1, |
273 | const unsigned char *new_sha1, | 348 | const unsigned char *new_sha1, |
274 | const char *base, const char *path); | 349 | const char *base, const char *path); |
275 | 350 | ||
276 | typedef void (*add_remove_fn_t)(struct diff_options *options, | 351 | typedef void (*add_remove_fn_t)(struct diff_options *options, |
277 | int addremove, unsigned mode, | 352 | int addremove, unsigned mode, |
278 | const unsigned char *sha1, | 353 | const unsigned char *sha1, |
279 | const char *base, const char *path); | 354 | const char *base, const char *path); |
280 | 355 | ||
281 | typedef void (*diff_format_fn_t)(struct diff_queue_struct *q, | 356 | typedef void (*diff_format_fn_t)(struct diff_queue_struct *q, |
282 | struct diff_options *options, void *data); | 357 | struct diff_options *options, void *data); |
283 | 358 | ||
284 | #define DIFF_FORMAT_RAW 0x0001 | 359 | #define DIFF_FORMAT_RAW 0x0001 |
285 | #define DIFF_FORMAT_DIFFSTAT0x0002 | 360 | #define DIFF_FORMAT_DIFFSTAT0x0002 |
286 | #define DIFF_FORMAT_NUMSTAT0x0004 | 361 | #define DIFF_FORMAT_NUMSTAT0x0004 |
287 | #define DIFF_FORMAT_SUMMARY0x0008 | 362 | #define DIFF_FORMAT_SUMMARY0x0008 |
288 | #define DIFF_FORMAT_PATCH0x0010 | 363 | #define DIFF_FORMAT_PATCH0x0010 |
289 | 364 | ||
290 | /* These override all above */ | 365 | /* These override all above */ |
291 | #define DIFF_FORMAT_NAME0x0100 | 366 | #define DIFF_FORMAT_NAME0x0100 |
292 | #define DIFF_FORMAT_NAME_STATUS0x0200 | 367 | #define DIFF_FORMAT_NAME_STATUS0x0200 |
293 | #define DIFF_FORMAT_CHECKDIFF0x0400 | 368 | #define DIFF_FORMAT_CHECKDIFF0x0400 |
294 | 369 | ||
295 | /* Same as output_format = 0 but we know that -s flag was given | 370 | /* Same as output_format = 0 but we know that -s flag was given |
296 | * and we should not give default value to output_format. | 371 | * and we should not give default value to output_format. |
297 | */ | 372 | */ |
298 | #define DIFF_FORMAT_NO_OUTPUT0x0800 | 373 | #define DIFF_FORMAT_NO_OUTPUT0x0800 |
299 | 374 | ||
300 | #define DIFF_FORMAT_CALLBACK0x1000 | 375 | #define DIFF_FORMAT_CALLBACK0x1000 |
301 | 376 | ||
302 | struct diff_options { | 377 | struct diff_options { |
303 | const char *filter; | 378 | const char *filter; |
304 | const char *orderfile; | 379 | const char *orderfile; |
305 | const char *pickaxe; | 380 | const char *pickaxe; |
306 | const char *single_follow; | 381 | const char *single_follow; |
307 | unsigned recursive:1, | 382 | unsigned recursive:1, |
308 | tree_in_recursive:1, | 383 | tree_in_recursive:1, |
309 | binary:1, | 384 | binary:1, |
310 | text:1, | 385 | text:1, |
311 | full_index:1, | 386 | full_index:1, |
312 | silent_on_remove:1, | 387 | silent_on_remove:1, |
313 | find_copies_harder:1, | 388 | find_copies_harder:1, |
314 | color_diff:1, | 389 | color_diff:1, |
315 | color_diff_words:1; | 390 | color_diff_words:1; |
316 | int context; | 391 | int context; |
317 | int break_opt; | 392 | int break_opt; |
318 | int detect_rename; | 393 | int detect_rename; |
319 | int line_termination; | 394 | int line_termination; |
320 | int output_format; | 395 | int output_format; |
321 | int pickaxe_opts; | 396 | int pickaxe_opts; |
322 | int rename_score; | 397 | int rename_score; |
323 | int reverse_diff; | 398 | int reverse_diff; |
324 | int rename_limit; | 399 | int rename_limit; |
325 | int setup; | 400 | int setup; |
326 | int abbrev; | 401 | int abbrev; |
327 | const char *msg_sep; | 402 | const char *msg_sep; |
328 | const char *stat_sep; | 403 | const char *stat_sep; |
329 | long xdl_opts; | 404 | long xdl_opts; |
330 | 405 | ||
331 | int stat_width; | 406 | int stat_width; |
332 | int stat_name_width; | 407 | int stat_name_width; |
333 | 408 | ||
334 | int nr_paths; | 409 | int nr_paths; |
335 | const char **paths; | 410 | const char **paths; |
336 | int *pathlens; | 411 | int *pathlens; |
337 | change_fn_t change; | 412 | change_fn_t change; |
338 | add_remove_fn_t add_remove; | 413 | add_remove_fn_t add_remove; |
339 | diff_format_fn_t format_callback; | 414 | diff_format_fn_t format_callback; |
340 | void *format_callback_data; | 415 | void *format_callback_data; |
341 | }; | 416 | }; |
342 | 417 | ||
343 | enum color_diff { | 418 | enum color_diff { |
344 | DIFF_RESET = 0, | 419 | DIFF_RESET = 0, |
345 | DIFF_PLAIN = 1, | 420 | DIFF_PLAIN = 1, |
346 | DIFF_METAINFO = 2, | 421 | DIFF_METAINFO = 2, |
347 | DIFF_FRAGINFO = 3, | 422 | DIFF_FRAGINFO = 3, |
348 | DIFF_FILE_OLD = 4, | 423 | DIFF_FILE_OLD = 4, |
349 | DIFF_FILE_NEW = 5, | 424 | DIFF_FILE_NEW = 5, |
350 | DIFF_COMMIT = 6, | 425 | DIFF_COMMIT = 6, |
351 | DIFF_WHITESPACE = 7, | 426 | DIFF_WHITESPACE = 7, |
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 | /* |
358 | * from git:refs.g | 459 | * from git:refs.g |
359 | */ | 460 | */ |
360 | 461 | ||
361 | typedef int each_ref_fn(const char *refname, const unsigned char *sha1, int flags, void *cb_data); | 462 | typedef int each_ref_fn(const char *refname, const unsigned char *sha1, int flags, void *cb_data); |
362 | extern int head_ref(each_ref_fn, void *); | 463 | extern int head_ref(each_ref_fn, void *); |
363 | extern int for_each_ref(each_ref_fn, void *); | 464 | extern int for_each_ref(each_ref_fn, void *); |
364 | extern int for_each_tag_ref(each_ref_fn, void *); | 465 | extern int for_each_tag_ref(each_ref_fn, void *); |
365 | extern int for_each_branch_ref(each_ref_fn, void *); | 466 | extern int for_each_branch_ref(each_ref_fn, void *); |
366 | extern int for_each_remote_ref(each_ref_fn, void *); | 467 | extern int for_each_remote_ref(each_ref_fn, void *); |
367 | 468 | ||
368 | 469 | ||
369 | 470 | ||
370 | /* | 471 | /* |
371 | * from git:revision.h | 472 | * from git:revision.h |
372 | */ | 473 | */ |
373 | 474 | ||
374 | struct rev_info; | 475 | struct rev_info; |
375 | struct log_info; | 476 | struct log_info; |
376 | 477 | ||
377 | typedef void (prune_fn_t)(struct rev_info *revs, struct commit *commit); | 478 | typedef void (prune_fn_t)(struct rev_info *revs, struct commit *commit); |
378 | 479 | ||
379 | struct rev_info { | 480 | struct rev_info { |
380 | /* Starting list */ | 481 | /* Starting list */ |
381 | struct commit_list *commits; | 482 | struct commit_list *commits; |
382 | struct object_array pending; | 483 | struct object_array pending; |
383 | 484 | ||
384 | /* Basic information */ | 485 | /* Basic information */ |
385 | const char *prefix; | 486 | const char *prefix; |
386 | void *prune_data; | 487 | void *prune_data; |
387 | prune_fn_t *prune_fn; | 488 | prune_fn_t *prune_fn; |
388 | 489 | ||
389 | /* Traversal flags */ | 490 | /* Traversal flags */ |
390 | unsigned intdense:1, | 491 | unsigned intdense:1, |
391 | no_merges:1, | 492 | no_merges:1, |
392 | no_walk:1, | 493 | no_walk:1, |
393 | remove_empty_trees:1, | 494 | remove_empty_trees:1, |
394 | simplify_history:1, | 495 | simplify_history:1, |
395 | lifo:1, | 496 | lifo:1, |
396 | topo_order:1, | 497 | topo_order:1, |
397 | tag_objects:1, | 498 | tag_objects:1, |
398 | tree_objects:1, | 499 | tree_objects:1, |
399 | blob_objects:1, | 500 | blob_objects:1, |
400 | edge_hint:1, | 501 | edge_hint:1, |
401 | limited:1, | 502 | limited:1, |
402 | unpacked:1, /* see also ignore_packed below */ | 503 | unpacked:1, /* see also ignore_packed below */ |
403 | boundary:1, | 504 | boundary:1, |
404 | parents:1; | 505 | parents:1; |
405 | 506 | ||
406 | /* Diff flags */ | 507 | /* Diff flags */ |
407 | unsigned intdiff:1, | 508 | unsigned intdiff:1, |
408 | full_diff:1, | 509 | full_diff:1, |
409 | show_root_diff:1, | 510 | show_root_diff:1, |
410 | no_commit_id:1, | 511 | no_commit_id:1, |
411 | verbose_header:1, | 512 | verbose_header:1, |
412 | ignore_merges:1, | 513 | ignore_merges:1, |
413 | combine_merges:1, | 514 | combine_merges:1, |
414 | dense_combined_merges:1, | 515 | dense_combined_merges:1, |
415 | always_show_header:1; | 516 | always_show_header:1; |
416 | 517 | ||
417 | /* Format info */ | 518 | /* Format info */ |
418 | unsigned intshown_one:1, | 519 | unsigned intshown_one:1, |
419 | abbrev_commit:1, | 520 | abbrev_commit:1, |
420 | relative_date:1; | 521 | relative_date:1; |
421 | 522 | ||
422 | const char **ignore_packed; /* pretend objects in these are unpacked */ | 523 | const char **ignore_packed; /* pretend objects in these are unpacked */ |
423 | int num_ignore_packed; | 524 | int num_ignore_packed; |
424 | 525 | ||
425 | unsigned intabbrev; | 526 | unsigned intabbrev; |
426 | enum cmit_fmtcommit_format; | 527 | enum cmit_fmtcommit_format; |
427 | struct log_info *loginfo; | 528 | struct log_info *loginfo; |
428 | int nr, total; | 529 | int nr, total; |
429 | const char*mime_boundary; | 530 | const char*mime_boundary; |
430 | const char*message_id; | 531 | const char*message_id; |
431 | const char*ref_message_id; | 532 | const char*ref_message_id; |
432 | const char*add_signoff; | 533 | const char*add_signoff; |
433 | const char*extra_headers; | 534 | const char*extra_headers; |
434 | 535 | ||
435 | /* Filter by commit log message */ | 536 | /* Filter by commit log message */ |
436 | struct grep_opt*grep_filter; | 537 | struct grep_opt*grep_filter; |
437 | 538 | ||
438 | /* special limits */ | 539 | /* special limits */ |
439 | int max_count; | 540 | int max_count; |
440 | unsigned long max_age; | 541 | unsigned long max_age; |
441 | unsigned long min_age; | 542 | unsigned long min_age; |
442 | 543 | ||
443 | /* diff info for patches and for paths limiting */ | 544 | /* diff info for patches and for paths limiting */ |
444 | struct diff_options diffopt; | 545 | struct diff_options diffopt; |
445 | struct diff_options pruning; | 546 | struct diff_options pruning; |
446 | 547 | ||
447 | topo_sort_set_fn_t topo_setter; | 548 | topo_sort_set_fn_t topo_setter; |
448 | topo_sort_get_fn_t topo_getter; | 549 | topo_sort_get_fn_t topo_getter; |
449 | }; | 550 | }; |
450 | 551 | ||
451 | 552 | ||
452 | extern void init_revisions(struct rev_info *revs, const char *prefix); | 553 | extern void init_revisions(struct rev_info *revs, const char *prefix); |
453 | extern int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def); | 554 | extern int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def); |
454 | extern int handle_revision_arg(const char *arg, struct rev_info *revs,int flags,int cant_be_filename); | 555 | extern int handle_revision_arg(const char *arg, struct rev_info *revs,int flags,int cant_be_filename); |
455 | 556 | ||
456 | extern void prepare_revision_walk(struct rev_info *revs); | 557 | extern void prepare_revision_walk(struct rev_info *revs); |
457 | extern struct commit *get_revision(struct rev_info *revs); | 558 | 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 */ |
@@ -1,110 +1,130 @@ | |||
1 | /* html.c: helper functions for html output | 1 | /* html.c: helper functions for html output |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | char *fmt(const char *format, ...) | 11 | char *fmt(const char *format, ...) |
12 | { | 12 | { |
13 | static char buf[8][1024]; | 13 | static char buf[8][1024]; |
14 | static int bufidx; | 14 | static int bufidx; |
15 | int len; | 15 | int len; |
16 | va_list args; | 16 | va_list args; |
17 | 17 | ||
18 | bufidx++; | 18 | bufidx++; |
19 | bufidx &= 7; | 19 | bufidx &= 7; |
20 | 20 | ||
21 | va_start(args, format); | 21 | va_start(args, format); |
22 | len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); | 22 | len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); |
23 | va_end(args); | 23 | va_end(args); |
24 | if (len>sizeof(buf[bufidx])) | 24 | if (len>sizeof(buf[bufidx])) |
25 | die("[html.c] string truncated: %s", format); | 25 | die("[html.c] string truncated: %s", format); |
26 | return buf[bufidx]; | 26 | return buf[bufidx]; |
27 | } | 27 | } |
28 | 28 | ||
29 | void html(const char *txt) | 29 | void html(const char *txt) |
30 | { | 30 | { |
31 | write(htmlfd, txt, strlen(txt)); | 31 | write(htmlfd, txt, strlen(txt)); |
32 | } | 32 | } |
33 | 33 | ||
34 | void htmlf(const char *format, ...) | 34 | void htmlf(const char *format, ...) |
35 | { | 35 | { |
36 | static char buf[65536]; | 36 | static char buf[65536]; |
37 | va_list args; | 37 | va_list args; |
38 | 38 | ||
39 | va_start(args, format); | 39 | va_start(args, format); |
40 | vsnprintf(buf, sizeof(buf), format, args); | 40 | vsnprintf(buf, sizeof(buf), format, args); |
41 | va_end(args); | 41 | va_end(args); |
42 | html(buf); | 42 | html(buf); |
43 | } | 43 | } |
44 | 44 | ||
45 | void html_txt(char *txt) | 45 | void html_txt(char *txt) |
46 | { | 46 | { |
47 | char *t = txt; | 47 | char *t = txt; |
48 | while(*t){ | 48 | while(*t){ |
49 | int c = *t; | 49 | int c = *t; |
50 | if (c=='<' || c=='>' || c=='&') { | 50 | if (c=='<' || c=='>' || c=='&') { |
51 | *t = '\0'; | 51 | *t = '\0'; |
52 | html(txt); | 52 | html(txt); |
53 | *t = c; | 53 | *t = c; |
54 | if (c=='>') | 54 | if (c=='>') |
55 | html(">"); | 55 | html(">"); |
56 | else if (c=='<') | 56 | else if (c=='<') |
57 | html("<"); | 57 | html("<"); |
58 | else if (c=='&') | 58 | else if (c=='&') |
59 | html("&"); | 59 | html("&"); |
60 | txt = t+1; | 60 | txt = t+1; |
61 | } | 61 | } |
62 | t++; | 62 | t++; |
63 | } | 63 | } |
64 | if (t!=txt) | 64 | if (t!=txt) |
65 | html(txt); | 65 | html(txt); |
66 | } | 66 | } |
67 | 67 | ||
68 | 68 | ||
69 | void html_attr(char *txt) | 69 | void html_attr(char *txt) |
70 | { | 70 | { |
71 | char *t = txt; | 71 | char *t = txt; |
72 | while(*t){ | 72 | while(*t){ |
73 | int c = *t; | 73 | int c = *t; |
74 | if (c=='<' || c=='>' || c=='\'') { | 74 | if (c=='<' || c=='>' || c=='\'') { |
75 | *t = '\0'; | 75 | *t = '\0'; |
76 | html(txt); | 76 | html(txt); |
77 | *t = c; | 77 | *t = c; |
78 | if (c=='>') | 78 | if (c=='>') |
79 | html(">"); | 79 | html(">"); |
80 | else if (c=='<') | 80 | else if (c=='<') |
81 | html("<"); | 81 | html("<"); |
82 | else if (c=='\'') | 82 | else if (c=='\'') |
83 | html(""e;"); | 83 | html(""e;"); |
84 | txt = t+1; | 84 | txt = t+1; |
85 | } | 85 | } |
86 | t++; | 86 | t++; |
87 | } | 87 | } |
88 | if (t!=txt) | 88 | if (t!=txt) |
89 | html(txt); | 89 | html(txt); |
90 | } | 90 | } |
91 | 91 | ||
92 | void html_link_open(char *url, char *title, char *class) | 92 | void html_link_open(char *url, char *title, char *class) |
93 | { | 93 | { |
94 | html("<a href='"); | 94 | html("<a href='"); |
95 | html_attr(url); | 95 | html_attr(url); |
96 | if (title) { | 96 | if (title) { |
97 | html("' title='"); | 97 | html("' title='"); |
98 | html_attr(title); | 98 | html_attr(title); |
99 | } | 99 | } |
100 | if (class) { | 100 | if (class) { |
101 | html("' class='"); | 101 | html("' class='"); |
102 | html_attr(class); | 102 | html_attr(class); |
103 | } | 103 | } |
104 | html("'>"); | 104 | html("'>"); |
105 | } | 105 | } |
106 | 106 | ||
107 | void html_link_close(void) | 107 | 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 | |||
@@ -1,66 +1,177 @@ | |||
1 | /* ui-commit.c: generate commit view | 1 | /* ui-commit.c: generate commit view |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
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; |
14 | struct commitinfo *info; | 119 | struct commitinfo *info; |
15 | struct commit_list *p; | 120 | struct commit_list *p; |
16 | unsigned char sha1[20]; | 121 | unsigned char sha1[20]; |
17 | char *query; | 122 | char *query; |
18 | 123 | ||
19 | if (get_sha1(hex, sha1)) { | 124 | if (get_sha1(hex, sha1)) { |
20 | cgit_print_error(fmt("Bad object id: %s", hex)); | 125 | cgit_print_error(fmt("Bad object id: %s", hex)); |
21 | return; | 126 | return; |
22 | } | 127 | } |
23 | commit = lookup_commit_reference(sha1); | 128 | commit = lookup_commit_reference(sha1); |
24 | if (!commit) { | 129 | if (!commit) { |
25 | cgit_print_error(fmt("Bad commit reference: %s", hex)); | 130 | cgit_print_error(fmt("Bad commit reference: %s", hex)); |
26 | return; | 131 | return; |
27 | } | 132 | } |
28 | info = cgit_parse_commit(commit); | 133 | info = cgit_parse_commit(commit); |
29 | 134 | ||
30 | html("<table class='commit-info'>\n"); | 135 | html("<table class='commit-info'>\n"); |
31 | html("<tr><th>author</th><td>"); | 136 | html("<tr><th>author</th><td>"); |
32 | html_txt(info->author); | 137 | html_txt(info->author); |
33 | html(" "); | 138 | html(" "); |
34 | html_txt(info->author_email); | 139 | html_txt(info->author_email); |
35 | html("</td><td class='right'>"); | 140 | html("</td><td class='right'>"); |
36 | cgit_print_date(info->author_date); | 141 | cgit_print_date(info->author_date); |
37 | html("</td></tr>\n"); | 142 | html("</td></tr>\n"); |
38 | html("<tr><th>committer</th><td>"); | 143 | html("<tr><th>committer</th><td>"); |
39 | html_txt(info->committer); | 144 | html_txt(info->committer); |
40 | html(" "); | 145 | html(" "); |
41 | html_txt(info->committer_email); | 146 | html_txt(info->committer_email); |
42 | html("</td><td class='right'>"); | 147 | html("</td><td class='right'>"); |
43 | cgit_print_date(info->committer_date); | 148 | cgit_print_date(info->committer_date); |
44 | html("</td></tr>\n"); | 149 | html("</td></tr>\n"); |
45 | html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='"); | 150 | html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='"); |
46 | query = fmt("id=%s", sha1_to_hex(commit->tree->object.sha1)); | 151 | query = fmt("id=%s", sha1_to_hex(commit->tree->object.sha1)); |
47 | html_attr(cgit_pageurl(cgit_query_repo, "tree", query)); | 152 | html_attr(cgit_pageurl(cgit_query_repo, "tree", query)); |
48 | htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1)); | 153 | htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1)); |
49 | for (p = commit->parents; p ; p = p->next) { | 154 | for (p = commit->parents; p ; p = p->next) { |
50 | html("<tr><th>parent</th>" | 155 | html("<tr><th>parent</th>" |
51 | "<td colspan='2' class='sha1'>" | 156 | "<td colspan='2' class='sha1'>" |
52 | "<a href='"); | 157 | "<a href='"); |
53 | query = fmt("id=%s", sha1_to_hex(p->item->object.sha1)); | 158 | query = fmt("id=%s", sha1_to_hex(p->item->object.sha1)); |
54 | html_attr(cgit_pageurl(cgit_query_repo, "commit", query)); | 159 | html_attr(cgit_pageurl(cgit_query_repo, "commit", query)); |
55 | htmlf("'>%s</a></td></tr>\n", | 160 | htmlf("'>%s</a></td></tr>\n", |
56 | sha1_to_hex(p->item->object.sha1)); | 161 | sha1_to_hex(p->item->object.sha1)); |
57 | } | 162 | } |
58 | html("</table>\n"); | 163 | html("</table>\n"); |
59 | html("<div class='commit-subject'>"); | 164 | html("<div class='commit-subject'>"); |
60 | html_txt(info->subject); | 165 | html_txt(info->subject); |
61 | html("</div>"); | 166 | html("</div>"); |
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 | } |