summaryrefslogtreecommitdiffabout
authorRagnar Ouchterlony <ragnar@lysator.liu.se>2009-09-13 17:36:35 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2009-09-16 18:17:56 (UTC)
commit40e174d5364910750413d94b5417e57d108190ef (patch) (unidiff)
tree21d71be66e1b058cecc45b861523c071fb4ee126
parent27479ac54c99584612f7246c9456119e88621eaa (diff)
downloadcgit-40e174d5364910750413d94b5417e57d108190ef.zip
cgit-40e174d5364910750413d94b5417e57d108190ef.tar.gz
cgit-40e174d5364910750413d94b5417e57d108190ef.tar.bz2
First version of side-by-side diff.
This constitutes the first prototype of a side-by-side diff. It is not possible to switch between unidiff and side-by-side diff at all at this stage. Signed-off-by: Ragnar Ouchterlony <ragnar@lysator.liu.se> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--Makefile1
-rw-r--r--cgit.css35
-rw-r--r--ui-diff.c15
-rw-r--r--ui-ssdiff.c264
-rw-r--r--ui-ssdiff.h12
5 files changed, 325 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 60d8c58..cb7875e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,171 +1,172 @@
1CGIT_VERSION = v0.8.3 1CGIT_VERSION = v0.8.3
2CGIT_SCRIPT_NAME = cgit.cgi 2CGIT_SCRIPT_NAME = cgit.cgi
3CGIT_SCRIPT_PATH = /var/www/htdocs/cgit 3CGIT_SCRIPT_PATH = /var/www/htdocs/cgit
4CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH) 4CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH)
5CGIT_CONFIG = /etc/cgitrc 5CGIT_CONFIG = /etc/cgitrc
6CACHE_ROOT = /var/cache/cgit 6CACHE_ROOT = /var/cache/cgit
7SHA1_HEADER = <openssl/sha.h> 7SHA1_HEADER = <openssl/sha.h>
8GIT_VER = 1.6.4.3 8GIT_VER = 1.6.4.3
9GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 9GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2
10INSTALL = install 10INSTALL = install
11 11
12# Define NO_STRCASESTR if you don't have strcasestr. 12# Define NO_STRCASESTR if you don't have strcasestr.
13# 13#
14# Define NEEDS_LIBICONV if linking with libc is not enough (eg. Darwin). 14# Define NEEDS_LIBICONV if linking with libc is not enough (eg. Darwin).
15# 15#
16 16
17#-include config.mak 17#-include config.mak
18 18
19# 19#
20# Platform specific tweaks 20# Platform specific tweaks
21# 21#
22 22
23uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') 23uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
24uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not') 24uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not')
25uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not') 25uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not')
26 26
27ifeq ($(uname_O),Cygwin) 27ifeq ($(uname_O),Cygwin)
28 NO_STRCASESTR = YesPlease 28 NO_STRCASESTR = YesPlease
29 NEEDS_LIBICONV = YesPlease 29 NEEDS_LIBICONV = YesPlease
30endif 30endif
31 31
32# 32#
33# Let the user override the above settings. 33# Let the user override the above settings.
34# 34#
35-include cgit.conf 35-include cgit.conf
36 36
37# 37#
38# Define a way to invoke make in subdirs quietly, shamelessly ripped 38# Define a way to invoke make in subdirs quietly, shamelessly ripped
39# from git.git 39# from git.git
40# 40#
41QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir 41QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir
42QUIET_SUBDIR1 = 42QUIET_SUBDIR1 =
43 43
44ifneq ($(findstring $(MAKEFLAGS),w),w) 44ifneq ($(findstring $(MAKEFLAGS),w),w)
45PRINT_DIR = --no-print-directory 45PRINT_DIR = --no-print-directory
46else # "make -w" 46else # "make -w"
47NO_SUBDIR = : 47NO_SUBDIR = :
48endif 48endif
49 49
50ifndef V 50ifndef V
51 QUIET_CC = @echo ' ' CC $@; 51 QUIET_CC = @echo ' ' CC $@;
52 QUIET_MM = @echo ' ' MM $@; 52 QUIET_MM = @echo ' ' MM $@;
53 QUIET_SUBDIR0 = +@subdir= 53 QUIET_SUBDIR0 = +@subdir=
54 QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ 54 QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \
55 $(MAKE) $(PRINT_DIR) -C $$subdir 55 $(MAKE) $(PRINT_DIR) -C $$subdir
56endif 56endif
57 57
58# 58#
59# Define a pattern rule for automatic dependency building 59# Define a pattern rule for automatic dependency building
60# 60#
61%.d: %.c 61%.d: %.c
62 $(QUIET_MM)$(CC) $(CFLAGS) -MM $< | sed -e 's/\($*\)\.o:/\1.o $@:/g' >$@ 62 $(QUIET_MM)$(CC) $(CFLAGS) -MM $< | sed -e 's/\($*\)\.o:/\1.o $@:/g' >$@
63 63
64# 64#
65# Define a pattern rule for silent object building 65# Define a pattern rule for silent object building
66# 66#
67%.o: %.c 67%.o: %.c
68 $(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $< 68 $(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $<
69 69
70 70
71EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto 71EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto
72OBJECTS = 72OBJECTS =
73OBJECTS += cache.o 73OBJECTS += cache.o
74OBJECTS += cgit.o 74OBJECTS += cgit.o
75OBJECTS += cmd.o 75OBJECTS += cmd.o
76OBJECTS += configfile.o 76OBJECTS += configfile.o
77OBJECTS += html.o 77OBJECTS += html.o
78OBJECTS += parsing.o 78OBJECTS += parsing.o
79OBJECTS += scan-tree.o 79OBJECTS += scan-tree.o
80OBJECTS += shared.o 80OBJECTS += shared.o
81OBJECTS += ui-atom.o 81OBJECTS += ui-atom.o
82OBJECTS += ui-blob.o 82OBJECTS += ui-blob.o
83OBJECTS += ui-clone.o 83OBJECTS += ui-clone.o
84OBJECTS += ui-commit.o 84OBJECTS += ui-commit.o
85OBJECTS += ui-diff.o 85OBJECTS += ui-diff.o
86OBJECTS += ui-log.o 86OBJECTS += ui-log.o
87OBJECTS += ui-patch.o 87OBJECTS += ui-patch.o
88OBJECTS += ui-plain.o 88OBJECTS += ui-plain.o
89OBJECTS += ui-refs.o 89OBJECTS += ui-refs.o
90OBJECTS += ui-repolist.o 90OBJECTS += ui-repolist.o
91OBJECTS += ui-shared.o 91OBJECTS += ui-shared.o
92OBJECTS += ui-snapshot.o 92OBJECTS += ui-snapshot.o
93OBJECTS += ui-ssdiff.o
93OBJECTS += ui-stats.o 94OBJECTS += ui-stats.o
94OBJECTS += ui-summary.o 95OBJECTS += ui-summary.o
95OBJECTS += ui-tag.o 96OBJECTS += ui-tag.o
96OBJECTS += ui-tree.o 97OBJECTS += ui-tree.o
97 98
98ifdef NEEDS_LIBICONV 99ifdef NEEDS_LIBICONV
99 EXTLIBS += -liconv 100 EXTLIBS += -liconv
100endif 101endif
101 102
102 103
103.PHONY: all libgit test install uninstall clean force-version get-git \ 104.PHONY: all libgit test install uninstall clean force-version get-git \
104 doc man-doc html-doc clean-doc 105 doc man-doc html-doc clean-doc
105 106
106all: cgit 107all: cgit
107 108
108VERSION: force-version 109VERSION: force-version
109 @./gen-version.sh "$(CGIT_VERSION)" 110 @./gen-version.sh "$(CGIT_VERSION)"
110-include VERSION 111-include VERSION
111 112
112 113
113CFLAGS += -g -Wall -Igit 114CFLAGS += -g -Wall -Igit
114CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' 115CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)'
115CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' 116CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"'
116CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' 117CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"'
117CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' 118CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"'
118CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' 119CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"'
119 120
120ifdef NO_ICONV 121ifdef NO_ICONV
121 CFLAGS += -DNO_ICONV 122 CFLAGS += -DNO_ICONV
122endif 123endif
123ifdef NO_STRCASESTR 124ifdef NO_STRCASESTR
124 CFLAGS += -DNO_STRCASESTR 125 CFLAGS += -DNO_STRCASESTR
125endif 126endif
126 127
127cgit: $(OBJECTS) libgit 128cgit: $(OBJECTS) libgit
128 $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o cgit $(OBJECTS) $(EXTLIBS) 129 $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o cgit $(OBJECTS) $(EXTLIBS)
129 130
130cgit.o: VERSION 131cgit.o: VERSION
131 132
132-include $(OBJECTS:.o=.d) 133-include $(OBJECTS:.o=.d)
133 134
134libgit: 135libgit:
135 $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 libgit.a 136 $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 libgit.a
136 $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 xdiff/lib.a 137 $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 xdiff/lib.a
137 138
138test: all 139test: all
139 $(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all 140 $(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all
140 141
141install: all 142install: all
142 $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_SCRIPT_PATH) 143 $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_SCRIPT_PATH)
143 $(INSTALL) -m 0755 cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) 144 $(INSTALL) -m 0755 cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME)
144 $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_DATA_PATH) 145 $(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_DATA_PATH)
145 $(INSTALL) -m 0644 cgit.css $(DESTDIR)$(CGIT_DATA_PATH)/cgit.css 146 $(INSTALL) -m 0644 cgit.css $(DESTDIR)$(CGIT_DATA_PATH)/cgit.css
146 $(INSTALL) -m 0644 cgit.png $(DESTDIR)$(CGIT_DATA_PATH)/cgit.png 147 $(INSTALL) -m 0644 cgit.png $(DESTDIR)$(CGIT_DATA_PATH)/cgit.png
147 148
148uninstall: 149uninstall:
149 rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) 150 rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME)
150 rm -f $(CGIT_DATA_PATH)/cgit.css 151 rm -f $(CGIT_DATA_PATH)/cgit.css
151 rm -f $(CGIT_DATA_PATH)/cgit.png 152 rm -f $(CGIT_DATA_PATH)/cgit.png
152 153
153doc: man-doc html-doc pdf-doc 154doc: man-doc html-doc pdf-doc
154 155
155man-doc: cgitrc.5.txt 156man-doc: cgitrc.5.txt
156 a2x -f manpage cgitrc.5.txt 157 a2x -f manpage cgitrc.5.txt
157 158
158html-doc: cgitrc.5.txt 159html-doc: cgitrc.5.txt
159 a2x -f xhtml --stylesheet=cgit-doc.css cgitrc.5.txt 160 a2x -f xhtml --stylesheet=cgit-doc.css cgitrc.5.txt
160 161
161pdf-doc: cgitrc.5.txt 162pdf-doc: cgitrc.5.txt
162 a2x -f pdf cgitrc.5.txt 163 a2x -f pdf cgitrc.5.txt
163 164
164clean: clean-doc 165clean: clean-doc
165 rm -f cgit VERSION *.o *.d 166 rm -f cgit VERSION *.o *.d
166 167
167clean-doc: 168clean-doc:
168 rm -f cgitrc.5 cgitrc.5.html cgitrc.5.pdf cgitrc.5.xml cgitrc.5.fo 169 rm -f cgitrc.5 cgitrc.5.html cgitrc.5.pdf cgitrc.5.xml cgitrc.5.fo
169 170
170get-git: 171get-git:
171 curl $(GIT_URL) | tar -xj && rm -rf git && mv git-$(GIT_VER) git 172 curl $(GIT_URL) | tar -xj && rm -rf git && mv git-$(GIT_VER) git
diff --git a/cgit.css b/cgit.css
index c47ebc9..bf58b8a 100644
--- a/cgit.css
+++ b/cgit.css
@@ -1,603 +1,638 @@
1body, table, form { 1body, table, form {
2 padding: 0em; 2 padding: 0em;
3 margin: 0em; 3 margin: 0em;
4} 4}
5 5
6body { 6body {
7 font-family: sans-serif; 7 font-family: sans-serif;
8 font-size: 10pt; 8 font-size: 10pt;
9 color: #333; 9 color: #333;
10 background: white; 10 background: white;
11 padding: 4px; 11 padding: 4px;
12} 12}
13 13
14a { 14a {
15 color: blue; 15 color: blue;
16 text-decoration: none; 16 text-decoration: none;
17} 17}
18 18
19a:hover { 19a:hover {
20 text-decoration: underline; 20 text-decoration: underline;
21} 21}
22 22
23table { 23table {
24 border-collapse: collapse; 24 border-collapse: collapse;
25} 25}
26 26
27table#header { 27table#header {
28 width: 100%; 28 width: 100%;
29 margin-bottom: 1em; 29 margin-bottom: 1em;
30} 30}
31 31
32table#header td.logo { 32table#header td.logo {
33 width: 96px; 33 width: 96px;
34} 34}
35 35
36table#header td.main { 36table#header td.main {
37 font-size: 250%; 37 font-size: 250%;
38 padding-left: 10px; 38 padding-left: 10px;
39 white-space: nowrap; 39 white-space: nowrap;
40} 40}
41 41
42table#header td.main a { 42table#header td.main a {
43 color: #000; 43 color: #000;
44} 44}
45 45
46table#header td.form { 46table#header td.form {
47 text-align: right; 47 text-align: right;
48 vertical-align: bottom; 48 vertical-align: bottom;
49 padding-right: 1em; 49 padding-right: 1em;
50 padding-bottom: 2px; 50 padding-bottom: 2px;
51 white-space: nowrap; 51 white-space: nowrap;
52} 52}
53 53
54table#header td.form form, 54table#header td.form form,
55table#header td.form input, 55table#header td.form input,
56table#header td.form select { 56table#header td.form select {
57 font-size: 90%; 57 font-size: 90%;
58} 58}
59 59
60table#header td.sub { 60table#header td.sub {
61 color: #777; 61 color: #777;
62 border-top: solid 1px #ccc; 62 border-top: solid 1px #ccc;
63 padding-left: 10px; 63 padding-left: 10px;
64} 64}
65 65
66table.tabs { 66table.tabs {
67 /* border-bottom: solid 2px #ccc; */ 67 /* border-bottom: solid 2px #ccc; */
68 border-collapse: collapse; 68 border-collapse: collapse;
69 margin-top: 2em; 69 margin-top: 2em;
70 margin-bottom: 0px; 70 margin-bottom: 0px;
71 width: 100%; 71 width: 100%;
72} 72}
73 73
74table.tabs td { 74table.tabs td {
75 padding: 0px 1em; 75 padding: 0px 1em;
76 vertical-align: bottom; 76 vertical-align: bottom;
77} 77}
78 78
79table.tabs td a { 79table.tabs td a {
80 padding: 2px 0.75em; 80 padding: 2px 0.75em;
81 color: #777; 81 color: #777;
82 font-size: 110%; 82 font-size: 110%;
83} 83}
84 84
85table.tabs td a.active { 85table.tabs td a.active {
86 color: #000; 86 color: #000;
87 background-color: #ccc; 87 background-color: #ccc;
88} 88}
89 89
90table.tabs td.form { 90table.tabs td.form {
91 text-align: right; 91 text-align: right;
92} 92}
93 93
94table.tabs td.form form { 94table.tabs td.form form {
95 padding-bottom: 2px; 95 padding-bottom: 2px;
96 font-size: 90%; 96 font-size: 90%;
97 white-space: nowrap; 97 white-space: nowrap;
98} 98}
99 99
100table.tabs td.form input, 100table.tabs td.form input,
101table.tabs td.form select { 101table.tabs td.form select {
102 font-size: 90%; 102 font-size: 90%;
103} 103}
104 104
105div.content { 105div.content {
106 margin: 0px; 106 margin: 0px;
107 padding: 2em; 107 padding: 2em;
108 border-top: solid 3px #ccc; 108 border-top: solid 3px #ccc;
109 border-bottom: solid 3px #ccc; 109 border-bottom: solid 3px #ccc;
110} 110}
111 111
112 112
113table.list { 113table.list {
114 width: 100%; 114 width: 100%;
115 border: none; 115 border: none;
116 border-collapse: collapse; 116 border-collapse: collapse;
117} 117}
118 118
119table.list tr { 119table.list tr {
120 background: white; 120 background: white;
121} 121}
122 122
123table.list tr.logheader { 123table.list tr.logheader {
124 background: #eee; 124 background: #eee;
125} 125}
126 126
127table.list tr:hover { 127table.list tr:hover {
128 background: #eee; 128 background: #eee;
129} 129}
130 130
131table.list tr.nohover:hover { 131table.list tr.nohover:hover {
132 background: white; 132 background: white;
133} 133}
134 134
135table.list th { 135table.list th {
136 font-weight: bold; 136 font-weight: bold;
137 /* color: #888; 137 /* color: #888;
138 border-top: dashed 1px #888; 138 border-top: dashed 1px #888;
139 border-bottom: dashed 1px #888; 139 border-bottom: dashed 1px #888;
140 */ 140 */
141 padding: 0.1em 0.5em 0.05em 0.5em; 141 padding: 0.1em 0.5em 0.05em 0.5em;
142 vertical-align: baseline; 142 vertical-align: baseline;
143} 143}
144 144
145table.list td { 145table.list td {
146 border: none; 146 border: none;
147 padding: 0.1em 0.5em 0.1em 0.5em; 147 padding: 0.1em 0.5em 0.1em 0.5em;
148} 148}
149 149
150table.list td.logsubject { 150table.list td.logsubject {
151 font-family: monospace; 151 font-family: monospace;
152 font-weight: bold; 152 font-weight: bold;
153} 153}
154 154
155table.list td.logmsg { 155table.list td.logmsg {
156 font-family: monospace; 156 font-family: monospace;
157 white-space: pre; 157 white-space: pre;
158 padding: 1em 0.5em 2em 0.5em; 158 padding: 1em 0.5em 2em 0.5em;
159} 159}
160 160
161table.list td a { 161table.list td a {
162 color: black; 162 color: black;
163} 163}
164 164
165table.list td a:hover { 165table.list td a:hover {
166 color: #00f; 166 color: #00f;
167} 167}
168 168
169img { 169img {
170 border: none; 170 border: none;
171} 171}
172 172
173input#switch-btn { 173input#switch-btn {
174 margin: 2px 0px 0px 0px; 174 margin: 2px 0px 0px 0px;
175} 175}
176 176
177td#sidebar input.txt { 177td#sidebar input.txt {
178 width: 100%; 178 width: 100%;
179 margin: 2px 0px 0px 0px; 179 margin: 2px 0px 0px 0px;
180} 180}
181 181
182table#grid { 182table#grid {
183 margin: 0px; 183 margin: 0px;
184} 184}
185 185
186td#content { 186td#content {
187 vertical-align: top; 187 vertical-align: top;
188 padding: 1em 2em 1em 1em; 188 padding: 1em 2em 1em 1em;
189 border: none; 189 border: none;
190} 190}
191 191
192div#summary { 192div#summary {
193 vertical-align: top; 193 vertical-align: top;
194 margin-bottom: 1em; 194 margin-bottom: 1em;
195} 195}
196 196
197table#downloads { 197table#downloads {
198 float: right; 198 float: right;
199 border-collapse: collapse; 199 border-collapse: collapse;
200 border: solid 1px #777; 200 border: solid 1px #777;
201 margin-left: 0.5em; 201 margin-left: 0.5em;
202 margin-bottom: 0.5em; 202 margin-bottom: 0.5em;
203} 203}
204 204
205table#downloads th { 205table#downloads th {
206 background-color: #ccc; 206 background-color: #ccc;
207} 207}
208 208
209div#blob { 209div#blob {
210 border: solid 1px black; 210 border: solid 1px black;
211} 211}
212 212
213div.error { 213div.error {
214 color: red; 214 color: red;
215 font-weight: bold; 215 font-weight: bold;
216 margin: 1em 2em; 216 margin: 1em 2em;
217} 217}
218 218
219a.ls-blob, a.ls-dir, a.ls-mod { 219a.ls-blob, a.ls-dir, a.ls-mod {
220 font-family: monospace; 220 font-family: monospace;
221} 221}
222 222
223td.ls-size { 223td.ls-size {
224 text-align: right; 224 text-align: right;
225 font-family: monospace; 225 font-family: monospace;
226 width: 10em; 226 width: 10em;
227} 227}
228 228
229td.ls-mode { 229td.ls-mode {
230 font-family: monospace; 230 font-family: monospace;
231 width: 10em; 231 width: 10em;
232} 232}
233 233
234table.blob { 234table.blob {
235 margin-top: 0.5em; 235 margin-top: 0.5em;
236 border-top: solid 1px black; 236 border-top: solid 1px black;
237} 237}
238 238
239table.blob td.lines { 239table.blob td.lines {
240 margin: 0; padding: 0 0 0 0.5em; 240 margin: 0; padding: 0 0 0 0.5em;
241 vertical-align: top; 241 vertical-align: top;
242 color: black; 242 color: black;
243} 243}
244 244
245table.blob td.linenumbers { 245table.blob td.linenumbers {
246 margin: 0; padding: 0 0.5em 0 0.5em; 246 margin: 0; padding: 0 0.5em 0 0.5em;
247 vertical-align: top; 247 vertical-align: top;
248 text-align: right; 248 text-align: right;
249 border-right: 1px solid gray; 249 border-right: 1px solid gray;
250} 250}
251 251
252table.blob pre { 252table.blob pre {
253 padding: 0; margin: 0; 253 padding: 0; margin: 0;
254} 254}
255 255
256table.blob a.no { 256table.blob a.no {
257 color: gray; 257 color: gray;
258 text-align: right; 258 text-align: right;
259 text-decoration: none; 259 text-decoration: none;
260} 260}
261 261
262table.blob a.no a:hover { 262table.blob a.no a:hover {
263 color: black; 263 color: black;
264} 264}
265 265
266table.bin-blob { 266table.bin-blob {
267 margin-top: 0.5em; 267 margin-top: 0.5em;
268 border: solid 1px black; 268 border: solid 1px black;
269} 269}
270 270
271table.bin-blob th { 271table.bin-blob th {
272 font-family: monospace; 272 font-family: monospace;
273 white-space: pre; 273 white-space: pre;
274 border: solid 1px #777; 274 border: solid 1px #777;
275 padding: 0.5em 1em; 275 padding: 0.5em 1em;
276} 276}
277 277
278table.bin-blob td { 278table.bin-blob td {
279 font-family: monospace; 279 font-family: monospace;
280 white-space: pre; 280 white-space: pre;
281 border-left: solid 1px #777; 281 border-left: solid 1px #777;
282 padding: 0em 1em; 282 padding: 0em 1em;
283} 283}
284 284
285table.nowrap td { 285table.nowrap td {
286 white-space: nowrap; 286 white-space: nowrap;
287} 287}
288 288
289table.commit-info { 289table.commit-info {
290 border-collapse: collapse; 290 border-collapse: collapse;
291 margin-top: 1.5em; 291 margin-top: 1.5em;
292} 292}
293 293
294table.commit-info th { 294table.commit-info th {
295 text-align: left; 295 text-align: left;
296 font-weight: normal; 296 font-weight: normal;
297 padding: 0.1em 1em 0.1em 0.1em; 297 padding: 0.1em 1em 0.1em 0.1em;
298 vertical-align: top; 298 vertical-align: top;
299} 299}
300 300
301table.commit-info td { 301table.commit-info td {
302 font-weight: normal; 302 font-weight: normal;
303 padding: 0.1em 1em 0.1em 0.1em; 303 padding: 0.1em 1em 0.1em 0.1em;
304} 304}
305 305
306div.commit-subject { 306div.commit-subject {
307 font-weight: bold; 307 font-weight: bold;
308 font-size: 125%; 308 font-size: 125%;
309 margin: 1.5em 0em 0.5em 0em; 309 margin: 1.5em 0em 0.5em 0em;
310 padding: 0em; 310 padding: 0em;
311} 311}
312 312
313div.commit-msg { 313div.commit-msg {
314 white-space: pre; 314 white-space: pre;
315 font-family: monospace; 315 font-family: monospace;
316} 316}
317 317
318div.diffstat-header { 318div.diffstat-header {
319 font-weight: bold; 319 font-weight: bold;
320 padding-top: 1.5em; 320 padding-top: 1.5em;
321} 321}
322 322
323table.diffstat { 323table.diffstat {
324 border-collapse: collapse; 324 border-collapse: collapse;
325 border: solid 1px #aaa; 325 border: solid 1px #aaa;
326 background-color: #eee; 326 background-color: #eee;
327} 327}
328 328
329table.diffstat th { 329table.diffstat th {
330 font-weight: normal; 330 font-weight: normal;
331 text-align: left; 331 text-align: left;
332 text-decoration: underline; 332 text-decoration: underline;
333 padding: 0.1em 1em 0.1em 0.1em; 333 padding: 0.1em 1em 0.1em 0.1em;
334 font-size: 100%; 334 font-size: 100%;
335} 335}
336 336
337table.diffstat td { 337table.diffstat td {
338 padding: 0.2em 0.2em 0.1em 0.1em; 338 padding: 0.2em 0.2em 0.1em 0.1em;
339 font-size: 100%; 339 font-size: 100%;
340 border: none; 340 border: none;
341} 341}
342 342
343table.diffstat td.mode { 343table.diffstat td.mode {
344 white-space: nowrap; 344 white-space: nowrap;
345} 345}
346 346
347table.diffstat td span.modechange { 347table.diffstat td span.modechange {
348 padding-left: 1em; 348 padding-left: 1em;
349 color: red; 349 color: red;
350} 350}
351 351
352table.diffstat td.add a { 352table.diffstat td.add a {
353 color: green; 353 color: green;
354} 354}
355 355
356table.diffstat td.del a { 356table.diffstat td.del a {
357 color: red; 357 color: red;
358} 358}
359 359
360table.diffstat td.upd a { 360table.diffstat td.upd a {
361 color: blue; 361 color: blue;
362} 362}
363 363
364table.diffstat td.graph { 364table.diffstat td.graph {
365 width: 500px; 365 width: 500px;
366 vertical-align: middle; 366 vertical-align: middle;
367} 367}
368 368
369table.diffstat td.graph table { 369table.diffstat td.graph table {
370 border: none; 370 border: none;
371} 371}
372 372
373table.diffstat td.graph td { 373table.diffstat td.graph td {
374 padding: 0px; 374 padding: 0px;
375 border: 0px; 375 border: 0px;
376 height: 7pt; 376 height: 7pt;
377} 377}
378 378
379table.diffstat td.graph td.add { 379table.diffstat td.graph td.add {
380 background-color: #5c5; 380 background-color: #5c5;
381} 381}
382 382
383table.diffstat td.graph td.rem { 383table.diffstat td.graph td.rem {
384 background-color: #c55; 384 background-color: #c55;
385} 385}
386 386
387div.diffstat-summary { 387div.diffstat-summary {
388 color: #888; 388 color: #888;
389 padding-top: 0.5em; 389 padding-top: 0.5em;
390} 390}
391 391
392table.diff { 392table.diff {
393 width: 100%; 393 width: 100%;
394} 394}
395 395
396table.diff td { 396table.diff td {
397 font-family: monospace; 397 font-family: monospace;
398 white-space: pre; 398 white-space: pre;
399} 399}
400 400
401table.diff td div.head { 401table.diff td div.head {
402 font-weight: bold; 402 font-weight: bold;
403 margin-top: 1em; 403 margin-top: 1em;
404 color: black; 404 color: black;
405} 405}
406 406
407table.diff td div.hunk { 407table.diff td div.hunk {
408 color: #009; 408 color: #009;
409} 409}
410 410
411table.diff td div.add { 411table.diff td div.add {
412 color: green; 412 color: green;
413} 413}
414 414
415table.diff td div.del { 415table.diff td div.del {
416 color: red; 416 color: red;
417} 417}
418 418
419.sha1 { 419.sha1 {
420 font-family: monospace; 420 font-family: monospace;
421 font-size: 90%; 421 font-size: 90%;
422} 422}
423 423
424.left { 424.left {
425 text-align: left; 425 text-align: left;
426} 426}
427 427
428.right { 428.right {
429 text-align: right; 429 text-align: right;
430} 430}
431 431
432table.list td.reposection { 432table.list td.reposection {
433 font-style: italic; 433 font-style: italic;
434 color: #888; 434 color: #888;
435} 435}
436 436
437a.button { 437a.button {
438 font-size: 80%; 438 font-size: 80%;
439 padding: 0em 0.5em; 439 padding: 0em 0.5em;
440} 440}
441 441
442a.primary { 442a.primary {
443 font-size: 100%; 443 font-size: 100%;
444} 444}
445 445
446a.secondary { 446a.secondary {
447 font-size: 90%; 447 font-size: 90%;
448} 448}
449 449
450td.toplevel-repo { 450td.toplevel-repo {
451 451
452} 452}
453 453
454table.list td.sublevel-repo { 454table.list td.sublevel-repo {
455 padding-left: 1.5em; 455 padding-left: 1.5em;
456} 456}
457 457
458div.pager { 458div.pager {
459 text-align: center; 459 text-align: center;
460 margin: 1em 0em 0em 0em; 460 margin: 1em 0em 0em 0em;
461} 461}
462 462
463div.pager a { 463div.pager a {
464 color: #777; 464 color: #777;
465 margin: 0em 0.5em; 465 margin: 0em 0.5em;
466} 466}
467 467
468span.age-mins { 468span.age-mins {
469 font-weight: bold; 469 font-weight: bold;
470 color: #080; 470 color: #080;
471} 471}
472 472
473span.age-hours { 473span.age-hours {
474 color: #080; 474 color: #080;
475} 475}
476 476
477span.age-days { 477span.age-days {
478 color: #040; 478 color: #040;
479} 479}
480 480
481span.age-weeks { 481span.age-weeks {
482 color: #444; 482 color: #444;
483} 483}
484 484
485span.age-months { 485span.age-months {
486 color: #888; 486 color: #888;
487} 487}
488 488
489span.age-years { 489span.age-years {
490 color: #bbb; 490 color: #bbb;
491} 491}
492div.footer { 492div.footer {
493 margin-top: 0.5em; 493 margin-top: 0.5em;
494 text-align: center; 494 text-align: center;
495 font-size: 80%; 495 font-size: 80%;
496 color: #ccc; 496 color: #ccc;
497} 497}
498a.branch-deco { 498a.branch-deco {
499 margin: 0px 0.5em; 499 margin: 0px 0.5em;
500 padding: 0px 0.25em; 500 padding: 0px 0.25em;
501 background-color: #88ff88; 501 background-color: #88ff88;
502 border: solid 1px #007700; 502 border: solid 1px #007700;
503} 503}
504a.tag-deco { 504a.tag-deco {
505 margin: 0px 0.5em; 505 margin: 0px 0.5em;
506 padding: 0px 0.25em; 506 padding: 0px 0.25em;
507 background-color: #ffff88; 507 background-color: #ffff88;
508 border: solid 1px #777700; 508 border: solid 1px #777700;
509} 509}
510a.remote-deco { 510a.remote-deco {
511 margin: 0px 0.5em; 511 margin: 0px 0.5em;
512 padding: 0px 0.25em; 512 padding: 0px 0.25em;
513 background-color: #ccccff; 513 background-color: #ccccff;
514 border: solid 1px #000077; 514 border: solid 1px #000077;
515} 515}
516a.deco { 516a.deco {
517 margin: 0px 0.5em; 517 margin: 0px 0.5em;
518 padding: 0px 0.25em; 518 padding: 0px 0.25em;
519 background-color: #ff8888; 519 background-color: #ff8888;
520 border: solid 1px #770000; 520 border: solid 1px #770000;
521} 521}
522 522
523div.commit-subject a { 523div.commit-subject a {
524 margin-left: 1em; 524 margin-left: 1em;
525 font-size: 75%; 525 font-size: 75%;
526} 526}
527 527
528table.stats { 528table.stats {
529 border: solid 1px black; 529 border: solid 1px black;
530 border-collapse: collapse; 530 border-collapse: collapse;
531} 531}
532 532
533table.stats th { 533table.stats th {
534 text-align: left; 534 text-align: left;
535 padding: 1px 0.5em; 535 padding: 1px 0.5em;
536 background-color: #eee; 536 background-color: #eee;
537 border: solid 1px black; 537 border: solid 1px black;
538} 538}
539 539
540table.stats td { 540table.stats td {
541 text-align: right; 541 text-align: right;
542 padding: 1px 0.5em; 542 padding: 1px 0.5em;
543 border: solid 1px black; 543 border: solid 1px black;
544} 544}
545 545
546table.stats td.total { 546table.stats td.total {
547 font-weight: bold; 547 font-weight: bold;
548 text-align: left; 548 text-align: left;
549} 549}
550 550
551table.stats td.sum { 551table.stats td.sum {
552 color: #c00; 552 color: #c00;
553 font-weight: bold; 553 font-weight: bold;
554 /*background-color: #eee; */ 554 /*background-color: #eee; */
555} 555}
556 556
557table.stats td.left { 557table.stats td.left {
558 text-align: left; 558 text-align: left;
559} 559}
560 560
561table.vgraph { 561table.vgraph {
562 border-collapse: separate; 562 border-collapse: separate;
563 border: solid 1px black; 563 border: solid 1px black;
564 height: 200px; 564 height: 200px;
565} 565}
566 566
567table.vgraph th { 567table.vgraph th {
568 background-color: #eee; 568 background-color: #eee;
569 font-weight: bold; 569 font-weight: bold;
570 border: solid 1px white; 570 border: solid 1px white;
571 padding: 1px 0.5em; 571 padding: 1px 0.5em;
572} 572}
573 573
574table.vgraph td { 574table.vgraph td {
575 vertical-align: bottom; 575 vertical-align: bottom;
576 padding: 0px 10px; 576 padding: 0px 10px;
577} 577}
578 578
579table.vgraph div.bar { 579table.vgraph div.bar {
580 background-color: #eee; 580 background-color: #eee;
581} 581}
582 582
583table.hgraph { 583table.hgraph {
584 border: solid 1px black; 584 border: solid 1px black;
585 width: 800px; 585 width: 800px;
586} 586}
587 587
588table.hgraph th { 588table.hgraph th {
589 background-color: #eee; 589 background-color: #eee;
590 font-weight: bold; 590 font-weight: bold;
591 border: solid 1px black; 591 border: solid 1px black;
592 padding: 1px 0.5em; 592 padding: 1px 0.5em;
593} 593}
594 594
595table.hgraph td { 595table.hgraph td {
596 vertical-align: center; 596 vertical-align: center;
597 padding: 2px 2px; 597 padding: 2px 2px;
598} 598}
599 599
600table.hgraph div.bar { 600table.hgraph div.bar {
601 background-color: #eee; 601 background-color: #eee;
602 height: 1em; 602 height: 1em;
603} 603}
604
605table.ssdiff td.add {
606 color: black;
607 background: #afa;
608}
609
610table.ssdiff td.add_dark {
611 color: black;
612 background: #9c9;
613}
614
615table.ssdiff td.del {
616 color: black;
617 background: #faa;
618}
619
620table.ssdiff td.del_dark {
621 color: black;
622 background: #c99;
623}
624
625table.ssdiff td.changed {
626 color: black;
627 background: #ffa;
628}
629
630table.ssdiff td.changed_dark {
631 color: black;
632 background: #cc9;
633}
634
635table.ssdiff td.hunk {
636 color: #black;
637 background: #ccf;
638}
diff --git a/ui-diff.c b/ui-diff.c
index 2196745..0c6f8d7 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -1,313 +1,324 @@
1/* ui-diff.c: show diff between two blobs 1/* ui-diff.c: show diff between two blobs
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#include "html.h" 10#include "html.h"
11#include "ui-shared.h" 11#include "ui-shared.h"
12#include "ui-ssdiff.h"
12 13
13unsigned char old_rev_sha1[20]; 14unsigned char old_rev_sha1[20];
14unsigned char new_rev_sha1[20]; 15unsigned char new_rev_sha1[20];
15 16
16static int files, slots; 17static int files, slots;
17static int total_adds, total_rems, max_changes; 18static int total_adds, total_rems, max_changes;
18static int lines_added, lines_removed; 19static int lines_added, lines_removed;
19 20
20static struct fileinfo { 21static struct fileinfo {
21 char status; 22 char status;
22 unsigned char old_sha1[20]; 23 unsigned char old_sha1[20];
23 unsigned char new_sha1[20]; 24 unsigned char new_sha1[20];
24 unsigned short old_mode; 25 unsigned short old_mode;
25 unsigned short new_mode; 26 unsigned short new_mode;
26 char *old_path; 27 char *old_path;
27 char *new_path; 28 char *new_path;
28 unsigned int added; 29 unsigned int added;
29 unsigned int removed; 30 unsigned int removed;
30 unsigned long old_size; 31 unsigned long old_size;
31 unsigned long new_size; 32 unsigned long new_size;
32 int binary:1; 33 int binary:1;
33} *items; 34} *items;
34 35
36static int use_ssdiff = 0;
35 37
36static void print_fileinfo(struct fileinfo *info) 38static void print_fileinfo(struct fileinfo *info)
37{ 39{
38 char *class; 40 char *class;
39 41
40 switch (info->status) { 42 switch (info->status) {
41 case DIFF_STATUS_ADDED: 43 case DIFF_STATUS_ADDED:
42 class = "add"; 44 class = "add";
43 break; 45 break;
44 case DIFF_STATUS_COPIED: 46 case DIFF_STATUS_COPIED:
45 class = "cpy"; 47 class = "cpy";
46 break; 48 break;
47 case DIFF_STATUS_DELETED: 49 case DIFF_STATUS_DELETED:
48 class = "del"; 50 class = "del";
49 break; 51 break;
50 case DIFF_STATUS_MODIFIED: 52 case DIFF_STATUS_MODIFIED:
51 class = "upd"; 53 class = "upd";
52 break; 54 break;
53 case DIFF_STATUS_RENAMED: 55 case DIFF_STATUS_RENAMED:
54 class = "mov"; 56 class = "mov";
55 break; 57 break;
56 case DIFF_STATUS_TYPE_CHANGED: 58 case DIFF_STATUS_TYPE_CHANGED:
57 class = "typ"; 59 class = "typ";
58 break; 60 break;
59 case DIFF_STATUS_UNKNOWN: 61 case DIFF_STATUS_UNKNOWN:
60 class = "unk"; 62 class = "unk";
61 break; 63 break;
62 case DIFF_STATUS_UNMERGED: 64 case DIFF_STATUS_UNMERGED:
63 class = "stg"; 65 class = "stg";
64 break; 66 break;
65 default: 67 default:
66 die("bug: unhandled diff status %c", info->status); 68 die("bug: unhandled diff status %c", info->status);
67 } 69 }
68 70
69 html("<tr>"); 71 html("<tr>");
70 htmlf("<td class='mode'>"); 72 htmlf("<td class='mode'>");
71 if (is_null_sha1(info->new_sha1)) { 73 if (is_null_sha1(info->new_sha1)) {
72 cgit_print_filemode(info->old_mode); 74 cgit_print_filemode(info->old_mode);
73 } else { 75 } else {
74 cgit_print_filemode(info->new_mode); 76 cgit_print_filemode(info->new_mode);
75 } 77 }
76 78
77 if (info->old_mode != info->new_mode && 79 if (info->old_mode != info->new_mode &&
78 !is_null_sha1(info->old_sha1) && 80 !is_null_sha1(info->old_sha1) &&
79 !is_null_sha1(info->new_sha1)) { 81 !is_null_sha1(info->new_sha1)) {
80 html("<span class='modechange'>["); 82 html("<span class='modechange'>[");
81 cgit_print_filemode(info->old_mode); 83 cgit_print_filemode(info->old_mode);
82 html("]</span>"); 84 html("]</span>");
83 } 85 }
84 htmlf("</td><td class='%s'>", class); 86 htmlf("</td><td class='%s'>", class);
85 cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.sha1, 87 cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.sha1,
86 ctx.qry.sha2, info->new_path); 88 ctx.qry.sha2, info->new_path);
87 if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) 89 if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED)
88 htmlf(" (%s from %s)", 90 htmlf(" (%s from %s)",
89 info->status == DIFF_STATUS_COPIED ? "copied" : "renamed", 91 info->status == DIFF_STATUS_COPIED ? "copied" : "renamed",
90 info->old_path); 92 info->old_path);
91 html("</td><td class='right'>"); 93 html("</td><td class='right'>");
92 if (info->binary) { 94 if (info->binary) {
93 htmlf("bin</td><td class='graph'>%d -> %d bytes", 95 htmlf("bin</td><td class='graph'>%d -> %d bytes",
94 info->old_size, info->new_size); 96 info->old_size, info->new_size);
95 return; 97 return;
96 } 98 }
97 htmlf("%d", info->added + info->removed); 99 htmlf("%d", info->added + info->removed);
98 html("</td><td class='graph'>"); 100 html("</td><td class='graph'>");
99 htmlf("<table summary='file diffstat' width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes)); 101 htmlf("<table summary='file diffstat' width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes));
100 htmlf("<td class='add' style='width: %.1f%%;'/>", 102 htmlf("<td class='add' style='width: %.1f%%;'/>",
101 info->added * 100.0 / max_changes); 103 info->added * 100.0 / max_changes);
102 htmlf("<td class='rem' style='width: %.1f%%;'/>", 104 htmlf("<td class='rem' style='width: %.1f%%;'/>",
103 info->removed * 100.0 / max_changes); 105 info->removed * 100.0 / max_changes);
104 htmlf("<td class='none' style='width: %.1f%%;'/>", 106 htmlf("<td class='none' style='width: %.1f%%;'/>",
105 (max_changes - info->removed - info->added) * 100.0 / max_changes); 107 (max_changes - info->removed - info->added) * 100.0 / max_changes);
106 html("</tr></table></td></tr>\n"); 108 html("</tr></table></td></tr>\n");
107} 109}
108 110
109static void count_diff_lines(char *line, int len) 111static void count_diff_lines(char *line, int len)
110{ 112{
111 if (line && (len > 0)) { 113 if (line && (len > 0)) {
112 if (line[0] == '+') 114 if (line[0] == '+')
113 lines_added++; 115 lines_added++;
114 else if (line[0] == '-') 116 else if (line[0] == '-')
115 lines_removed++; 117 lines_removed++;
116 } 118 }
117} 119}
118 120
119static void inspect_filepair(struct diff_filepair *pair) 121static void inspect_filepair(struct diff_filepair *pair)
120{ 122{
121 int binary = 0; 123 int binary = 0;
122 unsigned long old_size = 0; 124 unsigned long old_size = 0;
123 unsigned long new_size = 0; 125 unsigned long new_size = 0;
124 files++; 126 files++;
125 lines_added = 0; 127 lines_added = 0;
126 lines_removed = 0; 128 lines_removed = 0;
127 cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, &new_size, 129 cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, &new_size,
128 &binary, count_diff_lines); 130 &binary, count_diff_lines);
129 if (files >= slots) { 131 if (files >= slots) {
130 if (slots == 0) 132 if (slots == 0)
131 slots = 4; 133 slots = 4;
132 else 134 else
133 slots = slots * 2; 135 slots = slots * 2;
134 items = xrealloc(items, slots * sizeof(struct fileinfo)); 136 items = xrealloc(items, slots * sizeof(struct fileinfo));
135 } 137 }
136 items[files-1].status = pair->status; 138 items[files-1].status = pair->status;
137 hashcpy(items[files-1].old_sha1, pair->one->sha1); 139 hashcpy(items[files-1].old_sha1, pair->one->sha1);
138 hashcpy(items[files-1].new_sha1, pair->two->sha1); 140 hashcpy(items[files-1].new_sha1, pair->two->sha1);
139 items[files-1].old_mode = pair->one->mode; 141 items[files-1].old_mode = pair->one->mode;
140 items[files-1].new_mode = pair->two->mode; 142 items[files-1].new_mode = pair->two->mode;
141 items[files-1].old_path = xstrdup(pair->one->path); 143 items[files-1].old_path = xstrdup(pair->one->path);
142 items[files-1].new_path = xstrdup(pair->two->path); 144 items[files-1].new_path = xstrdup(pair->two->path);
143 items[files-1].added = lines_added; 145 items[files-1].added = lines_added;
144 items[files-1].removed = lines_removed; 146 items[files-1].removed = lines_removed;
145 items[files-1].old_size = old_size; 147 items[files-1].old_size = old_size;
146 items[files-1].new_size = new_size; 148 items[files-1].new_size = new_size;
147 items[files-1].binary = binary; 149 items[files-1].binary = binary;
148 if (lines_added + lines_removed > max_changes) 150 if (lines_added + lines_removed > max_changes)
149 max_changes = lines_added + lines_removed; 151 max_changes = lines_added + lines_removed;
150 total_adds += lines_added; 152 total_adds += lines_added;
151 total_rems += lines_removed; 153 total_rems += lines_removed;
152} 154}
153 155
154void cgit_print_diffstat(const unsigned char *old_sha1, 156void cgit_print_diffstat(const unsigned char *old_sha1,
155 const unsigned char *new_sha1) 157 const unsigned char *new_sha1)
156{ 158{
157 int i; 159 int i;
158 160
159 html("<div class='diffstat-header'>"); 161 html("<div class='diffstat-header'>");
160 cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1, 162 cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1,
161 ctx.qry.sha2, NULL); 163 ctx.qry.sha2, NULL);
162 html("</div>"); 164 html("</div>");
163 html("<table summary='diffstat' class='diffstat'>"); 165 html("<table summary='diffstat' class='diffstat'>");
164 max_changes = 0; 166 max_changes = 0;
165 cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, NULL); 167 cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, NULL);
166 for(i = 0; i<files; i++) 168 for(i = 0; i<files; i++)
167 print_fileinfo(&items[i]); 169 print_fileinfo(&items[i]);
168 html("</table>"); 170 html("</table>");
169 html("<div class='diffstat-summary'>"); 171 html("<div class='diffstat-summary'>");
170 htmlf("%d files changed, %d insertions, %d deletions", 172 htmlf("%d files changed, %d insertions, %d deletions",
171 files, total_adds, total_rems); 173 files, total_adds, total_rems);
172 html("</div>"); 174 html("</div>");
173} 175}
174 176
175 177
176/* 178/*
177 * print a single line returned from xdiff 179 * print a single line returned from xdiff
178 */ 180 */
179static void print_line(char *line, int len) 181static void print_line(char *line, int len)
180{ 182{
181 char *class = "ctx"; 183 char *class = "ctx";
182 char c = line[len-1]; 184 char c = line[len-1];
183 185
184 if (line[0] == '+') 186 if (line[0] == '+')
185 class = "add"; 187 class = "add";
186 else if (line[0] == '-') 188 else if (line[0] == '-')
187 class = "del"; 189 class = "del";
188 else if (line[0] == '@') 190 else if (line[0] == '@')
189 class = "hunk"; 191 class = "hunk";
190 192
191 htmlf("<div class='%s'>", class); 193 htmlf("<div class='%s'>", class);
192 line[len-1] = '\0'; 194 line[len-1] = '\0';
193 html_txt(line); 195 html_txt(line);
194 html("</div>"); 196 html("</div>");
195 line[len-1] = c; 197 line[len-1] = c;
196} 198}
197 199
198static void header(unsigned char *sha1, char *path1, int mode1, 200static void header(unsigned char *sha1, char *path1, int mode1,
199 unsigned char *sha2, char *path2, int mode2) 201 unsigned char *sha2, char *path2, int mode2)
200{ 202{
201 char *abbrev1, *abbrev2; 203 char *abbrev1, *abbrev2;
202 int subproject; 204 int subproject;
203 205
204 subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2)); 206 subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2));
205 html("<div class='head'>"); 207 html("<div class='head'>");
206 html("diff --git a/"); 208 html("diff --git a/");
207 html_txt(path1); 209 html_txt(path1);
208 html(" b/"); 210 html(" b/");
209 html_txt(path2); 211 html_txt(path2);
210 212
211 if (is_null_sha1(sha1)) 213 if (is_null_sha1(sha1))
212 path1 = "dev/null"; 214 path1 = "dev/null";
213 if (is_null_sha1(sha2)) 215 if (is_null_sha1(sha2))
214 path2 = "dev/null"; 216 path2 = "dev/null";
215 217
216 if (mode1 == 0) 218 if (mode1 == 0)
217 htmlf("<br/>new file mode %.6o", mode2); 219 htmlf("<br/>new file mode %.6o", mode2);
218 220
219 if (mode2 == 0) 221 if (mode2 == 0)
220 htmlf("<br/>deleted file mode %.6o", mode1); 222 htmlf("<br/>deleted file mode %.6o", mode1);
221 223
222 if (!subproject) { 224 if (!subproject) {
223 abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); 225 abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV));
224 abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); 226 abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV));
225 htmlf("<br/>index %s..%s", abbrev1, abbrev2); 227 htmlf("<br/>index %s..%s", abbrev1, abbrev2);
226 free(abbrev1); 228 free(abbrev1);
227 free(abbrev2); 229 free(abbrev2);
228 if (mode1 != 0 && mode2 != 0) { 230 if (mode1 != 0 && mode2 != 0) {
229 htmlf(" %.6o", mode1); 231 htmlf(" %.6o", mode1);
230 if (mode2 != mode1) 232 if (mode2 != mode1)
231 htmlf("..%.6o", mode2); 233 htmlf("..%.6o", mode2);
232 } 234 }
233 html("<br/>--- a/"); 235 html("<br/>--- a/");
234 if (mode1 != 0) 236 if (mode1 != 0)
235 cgit_tree_link(path1, NULL, NULL, ctx.qry.head, 237 cgit_tree_link(path1, NULL, NULL, ctx.qry.head,
236 sha1_to_hex(old_rev_sha1), path1); 238 sha1_to_hex(old_rev_sha1), path1);
237 else 239 else
238 html_txt(path1); 240 html_txt(path1);
239 html("<br/>+++ b/"); 241 html("<br/>+++ b/");
240 if (mode2 != 0) 242 if (mode2 != 0)
241 cgit_tree_link(path2, NULL, NULL, ctx.qry.head, 243 cgit_tree_link(path2, NULL, NULL, ctx.qry.head,
242 sha1_to_hex(new_rev_sha1), path2); 244 sha1_to_hex(new_rev_sha1), path2);
243 else 245 else
244 html_txt(path2); 246 html_txt(path2);
245 } 247 }
246 html("</div>"); 248 html("</div>");
249 if (use_ssdiff)
250 cgit_ssdiff_header();
247} 251}
248 252
249static void filepair_cb(struct diff_filepair *pair) 253static void filepair_cb(struct diff_filepair *pair)
250{ 254{
251 unsigned long old_size = 0; 255 unsigned long old_size = 0;
252 unsigned long new_size = 0; 256 unsigned long new_size = 0;
253 int binary = 0; 257 int binary = 0;
258 linediff_fn print_line_fn = print_line;
254 259
255 header(pair->one->sha1, pair->one->path, pair->one->mode, 260 header(pair->one->sha1, pair->one->path, pair->one->mode,
256 pair->two->sha1, pair->two->path, pair->two->mode); 261 pair->two->sha1, pair->two->path, pair->two->mode);
262 if (use_ssdiff) {
263 cgit_ssdiff_header();
264 print_line_fn = cgit_ssdiff_line_cb;
265 }
257 if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { 266 if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) {
258 if (S_ISGITLINK(pair->one->mode)) 267 if (S_ISGITLINK(pair->one->mode))
259 print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); 268 print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52);
260 if (S_ISGITLINK(pair->two->mode)) 269 if (S_ISGITLINK(pair->two->mode))
261 print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); 270 print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52);
262 return; 271 return;
263 } 272 }
264 if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, 273 if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size,
265 &new_size, &binary, print_line)) 274 &new_size, &binary, print_line_fn))
266 cgit_print_error("Error running diff"); 275 cgit_print_error("Error running diff");
267 if (binary) 276 if (binary)
268 html("Binary files differ"); 277 html("Binary files differ");
278 if (use_ssdiff)
279 cgit_ssdiff_footer();
269} 280}
270 281
271void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix) 282void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix)
272{ 283{
273 enum object_type type; 284 enum object_type type;
274 unsigned long size; 285 unsigned long size;
275 struct commit *commit, *commit2; 286 struct commit *commit, *commit2;
276 287
277 if (!new_rev) 288 if (!new_rev)
278 new_rev = ctx.qry.head; 289 new_rev = ctx.qry.head;
279 get_sha1(new_rev, new_rev_sha1); 290 get_sha1(new_rev, new_rev_sha1);
280 type = sha1_object_info(new_rev_sha1, &size); 291 type = sha1_object_info(new_rev_sha1, &size);
281 if (type == OBJ_BAD) { 292 if (type == OBJ_BAD) {
282 cgit_print_error(fmt("Bad object name: %s", new_rev)); 293 cgit_print_error(fmt("Bad object name: %s", new_rev));
283 return; 294 return;
284 } 295 }
285 commit = lookup_commit_reference(new_rev_sha1); 296 commit = lookup_commit_reference(new_rev_sha1);
286 if (!commit || parse_commit(commit)) 297 if (!commit || parse_commit(commit))
287 cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(new_rev_sha1))); 298 cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(new_rev_sha1)));
288 299
289 if (old_rev) 300 if (old_rev)
290 get_sha1(old_rev, old_rev_sha1); 301 get_sha1(old_rev, old_rev_sha1);
291 else if (commit->parents && commit->parents->item) 302 else if (commit->parents && commit->parents->item)
292 hashcpy(old_rev_sha1, commit->parents->item->object.sha1); 303 hashcpy(old_rev_sha1, commit->parents->item->object.sha1);
293 else 304 else
294 hashclr(old_rev_sha1); 305 hashclr(old_rev_sha1);
295 306
296 if (!is_null_sha1(old_rev_sha1)) { 307 if (!is_null_sha1(old_rev_sha1)) {
297 type = sha1_object_info(old_rev_sha1, &size); 308 type = sha1_object_info(old_rev_sha1, &size);
298 if (type == OBJ_BAD) { 309 if (type == OBJ_BAD) {
299 cgit_print_error(fmt("Bad object name: %s", sha1_to_hex(old_rev_sha1))); 310 cgit_print_error(fmt("Bad object name: %s", sha1_to_hex(old_rev_sha1)));
300 return; 311 return;
301 } 312 }
302 commit2 = lookup_commit_reference(old_rev_sha1); 313 commit2 = lookup_commit_reference(old_rev_sha1);
303 if (!commit2 || parse_commit(commit2)) 314 if (!commit2 || parse_commit(commit2))
304 cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1))); 315 cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1)));
305 } 316 }
306 cgit_print_diffstat(old_rev_sha1, new_rev_sha1); 317 cgit_print_diffstat(old_rev_sha1, new_rev_sha1);
307 318
308 html("<table summary='diff' class='diff'>"); 319 html("<table summary='diff' class='diff'>");
309 html("<tr><td>"); 320 html("<tr><td>");
310 cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix); 321 cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix);
311 html("</td></tr>"); 322 html("</td></tr>");
312 html("</table>"); 323 html("</table>");
313} 324}
diff --git a/ui-ssdiff.c b/ui-ssdiff.c
new file mode 100644
index 0000000..3591ab4
--- a/dev/null
+++ b/ui-ssdiff.c
@@ -0,0 +1,264 @@
1#include "cgit.h"
2#include "html.h"
3#include "ui-shared.h"
4
5extern int use_ssdiff;
6
7static int current_old_line, current_new_line;
8
9struct deferred_lines {
10 int line_no;
11 char *line;
12 struct deferred_lines *next;
13};
14
15static struct deferred_lines *deferred_old, *deferred_old_last;
16static struct deferred_lines *deferred_new, *deferred_new_last;
17
18static int line_from_hunk(char *line, char type)
19{
20 char *buf1, *buf2;
21 int len;
22
23 buf1 = strchr(line, type);
24 if (buf1 == NULL)
25 return 0;
26 buf1 += 1;
27 buf2 = strchr(buf1, ',');
28 if (buf2 == NULL)
29 return 0;
30 len = buf2 - buf1;
31 buf2 = xmalloc(len + 1);
32 strncpy(buf2, buf1, len);
33 buf2[len] = '\0';
34 int res = atoi(buf2);
35 free(buf2);
36 return res;
37}
38
39static char *replace_tabs(char *line)
40{
41 char *prev_buf = line;
42 char *cur_buf;
43 int linelen = strlen(line);
44 int n_tabs = 0;
45 int i;
46 char *result;
47 char *spaces = " ";
48
49 if (linelen == 0) {
50 result = xmalloc(1);
51 result[0] = '\0';
52 return result;
53 }
54
55 for (i = 0; i < linelen; i++)
56 if (line[i] == '\t')
57 n_tabs += 1;
58 result = xmalloc(linelen + n_tabs * 8 + 1);
59 result[0] = '\0';
60
61 while (1) {
62 cur_buf = strchr(prev_buf, '\t');
63 if (!cur_buf) {
64 strcat(result, prev_buf);
65 break;
66 } else {
67 strcat(result, " ");
68 strncat(result, spaces, 8 - (strlen(result) % 8));
69 strncat(result, prev_buf, cur_buf - prev_buf);
70 }
71 prev_buf = cur_buf + 1;
72 }
73 return result;
74}
75
76static void deferred_old_add(char *line, int line_no)
77{
78 struct deferred_lines *item = xmalloc(sizeof(struct deferred_lines));
79 item->line = xstrdup(line);
80 item->line_no = line_no;
81 item->next = NULL;
82 if (deferred_old) {
83 deferred_old_last->next = item;
84 deferred_old_last = item;
85 } else {
86 deferred_old = deferred_old_last = item;
87 }
88}
89
90static void deferred_new_add(char *line, int line_no)
91{
92 struct deferred_lines *item = xmalloc(sizeof(struct deferred_lines));
93 item->line = xstrdup(line);
94 item->line_no = line_no;
95 item->next = NULL;
96 if (deferred_new) {
97 deferred_new_last->next = item;
98 deferred_new_last = item;
99 } else {
100 deferred_new = deferred_new_last = item;
101 }
102}
103
104static void print_ssdiff_line(char *class, int old_line_no, char *old_line,
105 int new_line_no, char *new_line)
106{
107 html("<tr>");
108 if (old_line_no > 0)
109 htmlf("<td class='%s'>%d </td><td class='%s'>", class,
110 old_line_no, class);
111 else
112 htmlf("<td class='%s_dark'> </td><td class='%s_dark'>", class, class);
113
114 if (old_line) {
115 old_line = replace_tabs(old_line + 1);
116 html_txt(old_line);
117 free(old_line);
118 }
119
120 html(" </td>");
121
122 if (new_line_no > 0)
123 htmlf("<td class='%s'> %d </td><td class='%s'>", class,
124 new_line_no, class);
125 else
126 htmlf("<td class='%s_dark'> </td><td class='%s_dark'>", class, class);
127
128 if (new_line) {
129 new_line = replace_tabs(new_line + 1);
130 html_txt(new_line);
131 free(new_line);
132 }
133
134 html("</td></tr>");
135}
136
137static void print_deferred_old_lines()
138{
139 struct deferred_lines *iter_old, *tmp;
140
141 iter_old = deferred_old;
142 while (iter_old) {
143 print_ssdiff_line("del", iter_old->line_no,
144 iter_old->line, -1, NULL);
145 tmp = iter_old->next;
146 free(iter_old);
147 iter_old = tmp;
148 }
149}
150
151static void print_deferred_new_lines()
152{
153 struct deferred_lines *iter_new, *tmp;
154
155 iter_new = deferred_new;
156 while (iter_new) {
157 print_ssdiff_line("add", -1, NULL, iter_new->line_no,
158 iter_new->line);
159 tmp = iter_new->next;
160 free(iter_new);
161 iter_new = tmp;
162 }
163}
164
165static void print_deferred_changed_lines()
166{
167 struct deferred_lines *iter_old, *iter_new, *tmp;
168
169 iter_old = deferred_old;
170 iter_new = deferred_new;
171 while (iter_old || iter_new) {
172 if (iter_old && iter_new)
173 print_ssdiff_line("changed", iter_old->line_no,
174 iter_old->line,
175 iter_new->line_no, iter_new->line);
176 else if (iter_old)
177 print_ssdiff_line("changed", iter_old->line_no,
178 iter_old->line, -1, NULL);
179 else if (iter_new)
180 print_ssdiff_line("changed", -1, NULL,
181 iter_new->line_no, iter_new->line);
182
183 if (iter_old) {
184 tmp = iter_old->next;
185 free(iter_old);
186 iter_old = tmp;
187 }
188
189 if (iter_new) {
190 tmp = iter_new->next;
191 free(iter_new);
192 iter_new = tmp;
193 }
194 }
195}
196
197void cgit_ssdiff_print_deferred_lines()
198{
199 if (!deferred_old && !deferred_new)
200 return;
201
202 if (deferred_old && !deferred_new)
203 print_deferred_old_lines();
204 else if (!deferred_old && deferred_new)
205 print_deferred_new_lines();
206 else
207 print_deferred_changed_lines();
208
209 deferred_old = deferred_old_last = NULL;
210 deferred_new = deferred_new_last = NULL;
211}
212
213/*
214 * print a single line returned from xdiff
215 */
216void cgit_ssdiff_line_cb(char *line, int len)
217{
218 char c = line[len - 1];
219
220 line[len - 1] = '\0';
221
222 if (line[0] == '@') {
223 current_old_line = line_from_hunk(line, '-');
224 current_new_line = line_from_hunk(line, '+');
225 }
226
227 if (line[0] == ' ') {
228 if (deferred_old || deferred_new)
229 cgit_ssdiff_print_deferred_lines();
230 print_ssdiff_line("ctx", current_old_line, line,
231 current_new_line, line);
232 current_old_line += 1;
233 current_new_line += 1;
234 } else if (line[0] == '+') {
235 deferred_new_add(line, current_new_line);
236 current_new_line += 1;
237 } else if (line[0] == '-') {
238 deferred_old_add(line, current_old_line);
239 current_old_line += 1;
240 } else if (line[0] == '@') {
241 html("<tr><td colspan='4' class='hunk'>");
242 html_txt(line);
243 html("</td></tr>");
244 } else {
245 html("<tr><td colspan='4' class='ctx'>");
246 html_txt(line);
247 html("</td></tr>");
248 }
249 line[len - 1] = c;
250}
251
252void cgit_ssdiff_header()
253{
254 current_old_line = 0;
255 current_new_line = 0;
256 html("<table class='ssdiff'>");
257}
258
259void cgit_ssdiff_footer()
260{
261 if (deferred_old || deferred_new)
262 cgit_ssdiff_print_deferred_lines();
263 html("</table>");
264}
diff --git a/ui-ssdiff.h b/ui-ssdiff.h
new file mode 100644
index 0000000..a0b1efe
--- a/dev/null
+++ b/ui-ssdiff.h
@@ -0,0 +1,12 @@
1#ifndef UI_SSDIFF_H
2#define UI_SSDIFF_H
3
4extern void cgit_ssdiff_print_deferred_lines();
5
6extern void cgit_ssdiff_line_cb(char *line, int len);
7
8extern void cgit_ssdiff_header();
9
10extern void cgit_ssdiff_footer();
11
12#endif /* UI_SSDIFF_H */