8
8
# sudo gem install camping-omnibus --source http://code.whytheluckystiff.net
9
9
#
10
10
# author : scott chacon
11
+ # thanks to dr. nic for his syntax code highlighting deal
12
+ #
11
13
# /usr/local/lib/ruby/gems/1.8/gems/camping-1.5.180/examples/
12
14
13
15
Camping . goes :GitWeb
@@ -72,17 +74,80 @@ def get repo_id, sha
72
74
render :commit
73
75
end
74
76
end
75
- class Diff < R '/diff/(\d+)/(\w+)'
76
- end
77
+
77
78
class Tree < R '/tree/(\d+)/(\w+)'
79
+ def get repo_id , sha
80
+ @repo = Repository . find repo_id
81
+ @git = Git . bare ( @repo . path )
82
+ @tree = @git . gtree ( sha )
83
+ render :tree
84
+ end
85
+ end
86
+
87
+ class Blob < R '/blob/(\d+)/(.*?)/(\w+)'
88
+ def get repo_id , file , sha
89
+ @repo = Repository . find repo_id
90
+ @git = Git . bare ( @repo . path )
91
+ @blob = @git . gblob ( sha )
92
+ @file = file
93
+ render :blob
94
+ end
95
+ end
96
+
97
+ class BlobRaw < R '/blob/(\d+)/(\w+)'
98
+ def get repo_id , sha
99
+ @repo = Repository . find repo_id
100
+ @git = Git . bare ( @repo . path )
101
+ @blob = @git . gblob ( sha )
102
+ @blob . contents
103
+ end
104
+ end
105
+
106
+ class Archive < R '/archive/(\d+)/(\w+)'
107
+ def get repo_id , sha
108
+ @repo = Repository . find repo_id
109
+ @git = Git . bare ( @repo . path )
110
+
111
+ file = @git . gtree ( sha ) . archive
112
+ @headers [ 'Content-Type' ] = 'application/zip'
113
+ @headers [ "Content-Disposition" ] = "attachment; filename=archive.zip"
114
+ File . new ( file ) . read
115
+ end
116
+ end
117
+
118
+ class Diff < R '/diff/(\d+)/(\w+)/(\w+)'
119
+ def get repo_id , tree1 , tree2
120
+ @repo = Repository . find repo_id
121
+ @git = Git . bare ( @repo . path )
122
+ @tree1 = tree1
123
+ @tree2 = tree2
124
+ @diff = @git . diff ( tree1 , tree2 )
125
+ render :diff
126
+ end
78
127
end
79
- class Archive < R '/archive/(\d+)/(\W+)'
128
+
129
+ class Patch < R '/patch/(\d+)/(\w+)/(\w+)'
130
+ def get repo_id , tree1 , tree2
131
+ @repo = Repository . find repo_id
132
+ @git = Git . bare ( @repo . path )
133
+ @diff = @git . diff ( tree1 , tree2 ) . patch
134
+ end
80
135
end
136
+
81
137
end
82
138
83
139
module GitWeb ::Views
84
140
def layout
85
141
html do
142
+ style <<-END , :type => 'text/css'
143
+ body { color: #333; }
144
+ h1 { background: #cce; padding: 10px; margin: 3px; }
145
+ h3 { background: #aea; padding: 5px; margin: 3px; }
146
+ .options { float: right; margin: 10px; }
147
+ p { padding: 5px; }
148
+ .odd { background: #eee; }
149
+ .tag { margin: 5px; padding: 1px 3px; border: 1px solid #8a8; background: #afa;}
150
+ END
86
151
body do
87
152
self << yield
88
153
end
@@ -93,6 +158,9 @@ def view
93
158
h1 @repo . name
94
159
h2 @repo . path
95
160
161
+ @tags = { }
162
+ @git . tags . each { |tag | @tags [ tag . sha ] ||= [ ] ; @tags [ tag . sha ] << tag . name }
163
+
96
164
url = 'http:' + URL ( Fetch , @repo . id ) . to_s
97
165
98
166
h3 'info'
@@ -109,31 +177,123 @@ def view
109
177
td log . date . strftime ( "%Y-%m-%d" )
110
178
td log . sha [ 0 , 8 ]
111
179
td { em log . author . name }
112
- td log . message [ 0 , 60 ]
180
+ td do
181
+ span . message log . message [ 0 , 60 ]
182
+ @tags [ log . sha ] . each do |t |
183
+ span . space ' '
184
+ span . tag { code t }
185
+ end if @tags [ log . sha ]
186
+ end
113
187
td { a 'commit' , :href => R ( Commit , @repo , log . sha ) }
114
- td { a 'diff' , :href => R ( Diff , @repo , log . sha ) }
115
- td { a 'tree' , :href => R ( Tree , @repo , log . sha ) }
116
- td { a 'archive' , :href => R ( Archive , @repo , log . sha ) }
188
+ td { a 'commit- diff' , :href => R ( Diff , @repo , log . sha , log . parent . sha ) }
189
+ td { a 'tree' , :href => R ( Tree , @repo , log . gtree . sha ) }
190
+ td { a 'archive' , :href => R ( Archive , @repo , log . gtree . sha ) }
117
191
end
118
192
end
119
193
end
120
194
121
- h3 'heads '
195
+ h3 'branches '
122
196
@git . branches . each do |branch |
123
- li branch . full
197
+ li { a branch . full , :href => R ( Commit , @repo , branch . gcommit . sha ) }
198
+ end
199
+
200
+ h3 'tags'
201
+ @git . tags . each do |tag |
202
+ li { a tag . name , :href => R ( Commit , @repo , tag . sha ) }
124
203
end
204
+
125
205
end
126
206
127
207
def commit
208
+ a . options 'repo' , :href => R ( View , @repo )
128
209
h1 @commit . name
129
- h2 @commit . sha
210
+ h3 'info'
211
+ table . info do
212
+ tr { td 'author: ' ; td @commit . author . name + ' <' + @commit . author . email + '>' }
213
+ tr { td '' ; td { code @commit . author . date } }
214
+ tr { td 'committer: ' ; td @commit . committer . name + ' <' + @commit . committer . email + '>' }
215
+ tr { td '' ; td { code @commit . committer . date } }
216
+ tr { td 'commit sha: ' ; td { code @commit . sha } }
217
+ tr do
218
+ td 'tree sha: '
219
+ td do
220
+ code { a @commit . gtree . sha , :href => R ( Tree , @repo , @commit . gtree . sha ) }
221
+ span . space ' '
222
+ a 'archive' , :href => R ( Archive , @repo , @commit . gtree . sha )
223
+ end
224
+ end
225
+ tr do
226
+ td 'parents: '
227
+ td do
228
+ @commit . parents . each do |p |
229
+ code { a p . sha , :href => R ( Commit , @repo , p . sha ) }
230
+ span . space ' '
231
+ a 'diff' , :href => R ( DiffTwo , @repo , p . sha , @commit . sha )
232
+ span . space ' '
233
+ a 'archive' , :href => R ( Archive , @repo , p . gtree . sha )
234
+ br
235
+ end
236
+ end
237
+ end
238
+ end
239
+ h3 'commit message'
130
240
p @commit . message
131
- p @commit . parent
132
- p @commit . author . name
133
- p @commit . author . email
134
- p @commit . committer . name
135
- p @commit . committer . email
136
- p @commit . gtree . sha
241
+ end
242
+
243
+ def tree
244
+ a . options 'repo' , :href => R ( View , @repo )
245
+ h3 'tree : ' + @tree . sha
246
+ p { a 'archive tree' , :href => R ( Archive , @repo , @tree . sha ) } ;
247
+ table do
248
+ @tree . children . each do |file , node |
249
+ tr :class => cycle ( 'odd' , 'even' ) do
250
+ td { code node . sha [ 0 , 8 ] }
251
+ td node . mode
252
+ td file
253
+ if node . type == 'tree'
254
+ td { a node . type , :href => R ( Tree , @repo , node . sha ) }
255
+ td { a 'archive' , :href => R ( Archive , @repo , node . sha ) }
256
+ else
257
+ td { a node . type , :href => R ( Blob , @repo , file , node . sha ) }
258
+ td { a 'raw' , :href => R ( BlobRaw , @repo , node . sha ) }
259
+ end
260
+ end
261
+ end
262
+ end
263
+ end
264
+
265
+ def blob
266
+ link :rel => "stylesheet" , :type => "text/css" ,
267
+ :href => "http://drnicwilliams.com/external/CodeHighlighter/styles.css"
268
+ script :src => "http://drnicwilliams.com/external/CodeHighlighter/clean_tumblr_pre.js"
269
+
270
+ ext = File . extname ( @file ) . gsub ( '.' , '' )
271
+ ext = 'ruby' if ext == 'rb'
272
+
273
+ a . options 'repo' , :href => R ( View , @repo )
274
+ h3 'blob : ' + @blob . sha
275
+ h4 @file
276
+ pre { code @blob . contents , :class => ext }
277
+ end
278
+
279
+ def diff
280
+ a . options 'repo' , :href => R ( View , @repo )
281
+
282
+ p { a 'patch' , :href => R ( Patch , @repo , @tree1 , @tree2 ) }
283
+
284
+ h1 "diff"
285
+ p { strong @tree1 + ' : ' + @tree2 }
286
+
287
+ @diff . each do |file |
288
+ h3 file . path
289
+ pre file . patch
290
+ end
291
+ end
292
+
293
+
294
+ def cycle ( v1 , v2 )
295
+ ( @value == v1 ) ? @value = v2 : @value = v1
296
+ @value
137
297
end
138
298
139
299
def add
0 commit comments