dolt 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dolt (0.8.0)
4
+ dolt (0.9.0)
5
5
  async_sinatra (~> 1.0)
6
6
  json (~> 1.5)
7
- libdolt (~> 0.11)
7
+ libdolt (~> 0.12)
8
8
  sinatra (~> 1.0)
9
9
  thin (~> 1.4)
10
10
  tiltout (~> 1.4)
@@ -27,7 +27,7 @@ GEM
27
27
  github-markup (0.7.4)
28
28
  htmlentities (4.3.1)
29
29
  json (1.7.5)
30
- libdolt (0.11)
30
+ libdolt (0.12.0)
31
31
  em_pessimistic (~> 0.1)
32
32
  em_rugged (~> 0.3)
33
33
  eventmachine (~> 1.0)
data/dolt.gemspec CHANGED
@@ -11,7 +11,7 @@ end
11
11
 
12
12
  Gem::Specification.new do |s|
13
13
  s.name = "dolt"
14
- s.version = "0.9.0"
14
+ s.version = "0.10.0"
15
15
  s.authors = ["Christian Johansen"]
16
16
  s.email = ["christian@gitorious.org"]
17
17
  s.homepage = "http://gitorious.org/gitorious/dolt"
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.rubyforge_project = "dolt"
22
22
 
23
- s.add_dependency "libdolt", "~>0.12"
23
+ s.add_dependency "libdolt", "~>0.14"
24
24
  s.add_dependency "thin", "~>1.4"
25
25
  s.add_dependency "sinatra", "~>1.0"
26
26
  s.add_dependency "async_sinatra", "~>1.0"
@@ -30,7 +30,6 @@ Gem::Specification.new do |s|
30
30
  s.add_development_dependency "minitest", "~> 2.0"
31
31
  s.add_development_dependency "em-minitest-spec", "~> 1.1"
32
32
  s.add_development_dependency "rake", "~> 0.9"
33
- s.add_development_dependency "mocha"
34
33
 
35
34
  s.files = GemSpecHelper.files(".") + GemSpecHelper.files("vendor/ui")
36
35
  s.test_files = `git ls-files -- {test}/*`.split("\n")
@@ -16,6 +16,7 @@
16
16
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  #++
18
18
  require "json"
19
+ require "time"
19
20
 
20
21
  module Dolt
21
22
  module Sinatra
@@ -29,7 +30,7 @@ module Dolt
29
30
  end
30
31
 
31
32
  def error(error, repo, ref)
32
- response["Content-Type"] = "text/html"
33
+ add_headers(response)
33
34
  body(renderer.render(:"500", {
34
35
  :error => error,
35
36
  :repository_slug => repo,
@@ -60,12 +61,12 @@ module Dolt
60
61
  })
61
62
  end
62
63
 
63
- def blob(repo, ref, path, options = { :template => :blob, :content_type => "text/html" })
64
+ def blob(repo, ref, path, options = { :template => :blob })
64
65
  actions.blob(repo, ref, path) do |err, data|
65
66
  next error(err, repo, ref) if !err.nil?
66
67
  blob = data[:blob]
67
68
  next redirect(tree_url(repo, ref, path)) if blob.class.to_s !~ /\bBlob/
68
- response["Content-Type"] = options[:content_type]
69
+ add_headers(response, options.merge(:ref => ref))
69
70
  tpl_options = options[:template_options] || {}
70
71
  body(renderer.render(options[:template], data, tpl_options))
71
72
  end
@@ -77,7 +78,7 @@ module Dolt
77
78
  next error(err, repo, ref) if !err.nil?
78
79
  tree = data[:tree]
79
80
  next redirect(blob_url(repo, ref, path)) if tree.class.to_s !~ /\bTree/
80
- response["Content-Type"] = "text/html"
81
+ add_headers(response, :ref => ref)
81
82
  body(renderer.render(:tree, data))
82
83
  rescue Exception => err
83
84
  error(err, repo, ref)
@@ -89,7 +90,7 @@ module Dolt
89
90
  actions.tree_entry(repo, ref, path) do |err, data|
90
91
  begin
91
92
  next error(err, repo, ref) if !err.nil?
92
- response["Content-Type"] = "text/html"
93
+ add_headers(response, :ref => ref)
93
94
  body(renderer.render(data.key?(:tree) ? :tree : :blob, data))
94
95
  rescue Exception => err
95
96
  error(err, repo, ref)
@@ -100,7 +101,7 @@ module Dolt
100
101
  def blame(repo, ref, path)
101
102
  actions.blame(repo, ref, path) do |err, data|
102
103
  next error(err, repo, ref) if !err.nil?
103
- response["Content-Type"] = "text/html"
104
+ add_headers(response, :ref => ref)
104
105
  body(renderer.render(:blame, data))
105
106
  end
106
107
  end
@@ -108,7 +109,7 @@ module Dolt
108
109
  def history(repo, ref, path, count)
109
110
  actions.history(repo, ref, path, count) do |err, data|
110
111
  next error(err, repo, ref) if !err.nil?
111
- response["Content-Type"] = "text/html"
112
+ add_headers(response, :ref => ref)
112
113
  body(renderer.render(:commits, data))
113
114
  end
114
115
  end
@@ -116,21 +117,38 @@ module Dolt
116
117
  def refs(repo)
117
118
  actions.refs(repo) do |err, data|
118
119
  next error(err, repo, ref) if !err.nil?
119
- response["Content-Type"] = "application/json"
120
+ add_headers(response, :content_type => "application/json")
120
121
  body(renderer.render(:refs, data, :layout => nil))
121
122
  end
122
123
  end
123
124
 
124
125
  def tree_history(repo, ref, path, count = 1)
125
126
  actions.tree_history(repo, ref, path, count) do |err, data|
126
- if !err.nil?
127
+ begin
128
+ if !err.nil?
129
+ error(err, repo, ref)
130
+ else
131
+ add_headers(response, :content_type => "application/json", :ref => ref)
132
+ body(renderer.render(:tree_history, data, :layout => nil))
133
+ end
134
+ rescue Exception => err
127
135
  error(err, repo, ref)
128
- else
129
- response["Content-Type"] = "application/json"
130
- body(renderer.render(:tree_history, data, :layout => nil))
131
136
  end
132
137
  end
133
138
  end
139
+
140
+ private
141
+ def add_headers(response, headers = {})
142
+ default_ct = "text/html; charset=utf-8"
143
+ response["Content-Type"] = headers[:content_type] || default_ct
144
+ response["X-UA-Compatible"] = "IE=edge"
145
+
146
+ if headers[:ref] && headers[:ref].length == 40
147
+ response["Cache-Control"] = "max-age=315360000, public"
148
+ year = 60*60*24*365
149
+ response["Expires"] = (Time.now + year).httpdate
150
+ end
151
+ end
134
152
  end
135
153
  end
136
154
  end
@@ -137,18 +137,25 @@ describe Dolt::Sinatra::Actions do
137
137
  app = DummySinatraApp.new(Actions.new(BlobStub.new), Renderer.new("Blob"))
138
138
  app.blob("gitorious", "master", "app/models/repository.rb")
139
139
 
140
- assert_equal "text/html", app.response["Content-Type"]
140
+ assert_equal "text/html; charset=utf-8", app.response["Content-Type"]
141
141
  assert_equal "blob:Blob", app.body
142
142
  end
143
143
 
144
144
  it "redirects tree views to tree action" do
145
- app = DummySinatraApp.new(Actions.new(TreeStub.new), Renderer.new("Blob"))
145
+ app = DummySinatraApp.new(Actions.new(TreeStub.new), Renderer.new("Tree"))
146
146
  app.blob("gitorious", "master", "app/models")
147
147
 
148
148
  assert_equal 302, app.response.status
149
149
  assert_equal "/gitorious/tree/master:app/models", app.response["Location"]
150
150
  assert_equal "", app.body
151
151
  end
152
+
153
+ it "unescapes ref" do
154
+ app = DummySinatraApp.new(Actions.new(BlobStub.new), Renderer.new("Blob"))
155
+ app.blob("gitorious", "issue-%23221", "app/my documents")
156
+
157
+ assert_equal "issue-#221", actions.ref
158
+ end
152
159
  end
153
160
 
154
161
  describe "#tree" do
@@ -166,7 +173,7 @@ describe Dolt::Sinatra::Actions do
166
173
  app = DummySinatraApp.new(Actions.new(TreeStub.new), Renderer.new("Tree"))
167
174
  app.tree("gitorious", "master", "app/models")
168
175
 
169
- assert_equal "text/html", app.response["Content-Type"]
176
+ assert_equal "text/html; charset=utf-8", app.response["Content-Type"]
170
177
  assert_equal "tree:Tree", app.body
171
178
  end
172
179
 
@@ -179,6 +186,28 @@ describe Dolt::Sinatra::Actions do
179
186
  assert_equal "/gitorious/blob/master:app/models/repository.rb", location
180
187
  assert_equal "", app.body
181
188
  end
189
+
190
+ it "sets X-UA-Compatible header" do
191
+ app = DummySinatraApp.new(Actions.new(TreeStub.new), Renderer.new("Tree"))
192
+ app.tree("gitorious", "master", "app/models")
193
+
194
+ assert_equal "IE=edge", app.response["X-UA-Compatible"]
195
+ end
196
+
197
+ it "does not set cache-control header for head ref" do
198
+ app = DummySinatraApp.new(Actions.new(TreeStub.new), Renderer.new("Tree"))
199
+ app.tree("gitorious", "master", "app/models")
200
+
201
+ assert !app.response.key?("Cache-Control")
202
+ end
203
+
204
+ it "sets cache headers for full oid ref" do
205
+ app = DummySinatraApp.new(Actions.new(TreeStub.new), Renderer.new("Tree"))
206
+ app.tree("gitorious", "a" * 40, "app/models")
207
+
208
+ assert_equal "max-age=315360000, public", app.response["Cache-Control"]
209
+ refute_nil app.response["Expires"]
210
+ end
182
211
  end
183
212
 
184
213
  describe "#tree_entry" do
@@ -186,7 +215,7 @@ describe Dolt::Sinatra::Actions do
186
215
  app = DummySinatraApp.new(Actions.new(TreeStub.new), Renderer.new("Tree"))
187
216
  app.tree_entry("gitorious", "master", "app/models")
188
217
 
189
- assert_equal "text/html", app.response["Content-Type"]
218
+ assert_equal "text/html; charset=utf-8", app.response["Content-Type"]
190
219
  assert_equal "tree:Tree", app.body
191
220
  end
192
221
 
@@ -194,7 +223,7 @@ describe Dolt::Sinatra::Actions do
194
223
  app = DummySinatraApp.new(Actions.new(BlobStub.new), Renderer.new("Blob"))
195
224
  app.tree_entry("gitorious", "master", "app/models")
196
225
 
197
- assert_equal "text/html", app.response["Content-Type"]
226
+ assert_equal "text/html; charset=utf-8", app.response["Content-Type"]
198
227
  assert_equal "blob:Blob", app.body
199
228
  end
200
229
  end
@@ -244,7 +273,7 @@ describe Dolt::Sinatra::Actions do
244
273
  app = DummySinatraApp.new(Actions.new(BlobStub.new), Renderer.new("Text"))
245
274
  app.blame("gitorious", "master", "app/models/repository.rb")
246
275
 
247
- assert_equal "text/html", app.response["Content-Type"]
276
+ assert_equal "text/html; charset=utf-8", app.response["Content-Type"]
248
277
  assert_equal "blame:Text", app.body
249
278
  end
250
279
  end
@@ -264,7 +293,7 @@ describe Dolt::Sinatra::Actions do
264
293
  app = DummySinatraApp.new(Actions.new(BlobStub.new), Renderer.new("Text"))
265
294
  app.history("gitorious", "master", "app/models/repository.rb", 10)
266
295
 
267
- assert_equal "text/html", app.response["Content-Type"]
296
+ assert_equal "text/html; charset=utf-8", app.response["Content-Type"]
268
297
  assert_equal "commits:Text", app.body
269
298
  end
270
299
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dolt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-14 00:00:00.000000000 Z
12
+ date: 2013-01-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: libdolt
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '0.12'
21
+ version: '0.14'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: '0.12'
29
+ version: '0.14'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: thin
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -155,22 +155,6 @@ dependencies:
155
155
  - - ~>
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0.9'
158
- - !ruby/object:Gem::Dependency
159
- name: mocha
160
- requirement: !ruby/object:Gem::Requirement
161
- none: false
162
- requirements:
163
- - - ! '>='
164
- - !ruby/object:Gem::Version
165
- version: '0'
166
- type: :development
167
- prerelease: false
168
- version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
- requirements:
171
- - - ! '>='
172
- - !ruby/object:Gem::Version
173
- version: '0'
174
158
  description: Dolt serves git trees and syntax highlighted blobs
175
159
  email:
176
160
  - christian@gitorious.org