dolt 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dolt (0.9.0)
4
+ dolt (0.11.0)
5
5
  async_sinatra (~> 1.0)
6
6
  json (~> 1.5)
7
- libdolt (~> 0.12)
7
+ libdolt (~> 0.15)
8
8
  sinatra (~> 1.0)
9
9
  thin (~> 1.4)
10
10
  tiltout (~> 1.4)
@@ -24,10 +24,10 @@ GEM
24
24
  eventmachine (~> 1.0)
25
25
  rugged (= 0.17.0.b6)
26
26
  eventmachine (1.0.0)
27
- github-markup (0.7.4)
27
+ github-markup (0.7.5)
28
28
  htmlentities (4.3.1)
29
- json (1.7.5)
30
- libdolt (0.12.0)
29
+ json (1.7.6)
30
+ libdolt (0.15.0)
31
31
  em_pessimistic (~> 0.1)
32
32
  em_rugged (~> 0.3)
33
33
  eventmachine (~> 1.0)
@@ -41,17 +41,14 @@ GEM
41
41
  github-markup (~> 0.7)
42
42
  htmlentities (~> 4.3)
43
43
  pygments.rb (~> 0.2)
44
- metaclass (0.0.1)
45
44
  mime-types (1.19)
46
45
  minitest (2.12.1)
47
- mocha (0.12.7)
48
- metaclass (~> 0.0.1)
49
46
  posix-spawn (0.3.6)
50
- pygments.rb (0.3.2)
47
+ pygments.rb (0.3.7)
51
48
  posix-spawn (~> 0.3.6)
52
49
  yajl-ruby (~> 1.1.0)
53
- rack (1.4.1)
54
- rack-protection (1.2.0)
50
+ rack (1.4.3)
51
+ rack-protection (1.3.2)
55
52
  rack
56
53
  rake (0.9.2.2)
57
54
  rugged (0.17.0.b6)
@@ -77,5 +74,4 @@ DEPENDENCIES
77
74
  dolt!
78
75
  em-minitest-spec (~> 1.1)
79
76
  minitest (~> 2.0)
80
- mocha
81
77
  rake (~> 0.9)
@@ -11,7 +11,7 @@ end
11
11
 
12
12
  Gem::Specification.new do |s|
13
13
  s.name = "dolt"
14
- s.version = "0.10.0"
14
+ s.version = "0.11.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.14"
23
+ s.add_dependency "libdolt", "~>0.15"
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"
@@ -54,6 +54,10 @@ module Dolt
54
54
  end
55
55
 
56
56
  def raw(repo, ref, path)
57
+ if oid = lookup_ref_oid(repo, ref)
58
+ redirect(raw_url(repo, oid, path)) and return
59
+ end
60
+
57
61
  blob(repo, ref, path, {
58
62
  :template => :raw,
59
63
  :content_type => "text/plain",
@@ -62,7 +66,11 @@ module Dolt
62
66
  end
63
67
 
64
68
  def blob(repo, ref, path, options = { :template => :blob })
65
- actions.blob(repo, ref, path) do |err, data|
69
+ if oid = lookup_ref_oid(repo, ref)
70
+ redirect(blob_url(repo, oid, path)) and return
71
+ end
72
+
73
+ actions.blob(repo, u(ref), path) do |err, data|
66
74
  next error(err, repo, ref) if !err.nil?
67
75
  blob = data[:blob]
68
76
  next redirect(tree_url(repo, ref, path)) if blob.class.to_s !~ /\bBlob/
@@ -73,7 +81,11 @@ module Dolt
73
81
  end
74
82
 
75
83
  def tree(repo, ref, path)
76
- actions.tree(repo, ref, path) do |err, data|
84
+ if oid = lookup_ref_oid(repo, ref)
85
+ redirect(tree_url(repo, oid, path)) and return
86
+ end
87
+
88
+ actions.tree(repo, u(ref), path) do |err, data|
77
89
  begin
78
90
  next error(err, repo, ref) if !err.nil?
79
91
  tree = data[:tree]
@@ -87,7 +99,11 @@ module Dolt
87
99
  end
88
100
 
89
101
  def tree_entry(repo, ref, path)
90
- actions.tree_entry(repo, ref, path) do |err, data|
102
+ if oid = lookup_ref_oid(repo, ref)
103
+ redirect(tree_entry_url(repo, oid, path)) and return
104
+ end
105
+
106
+ actions.tree_entry(repo, u(ref), path) do |err, data|
91
107
  begin
92
108
  next error(err, repo, ref) if !err.nil?
93
109
  add_headers(response, :ref => ref)
@@ -99,7 +115,11 @@ module Dolt
99
115
  end
100
116
 
101
117
  def blame(repo, ref, path)
102
- actions.blame(repo, ref, path) do |err, data|
118
+ if oid = lookup_ref_oid(repo, ref)
119
+ redirect(blame_url(repo, oid, path)) and return
120
+ end
121
+
122
+ actions.blame(repo, u(ref), path) do |err, data|
103
123
  next error(err, repo, ref) if !err.nil?
104
124
  add_headers(response, :ref => ref)
105
125
  body(renderer.render(:blame, data))
@@ -107,7 +127,11 @@ module Dolt
107
127
  end
108
128
 
109
129
  def history(repo, ref, path, count)
110
- actions.history(repo, ref, path, count) do |err, data|
130
+ if oid = lookup_ref_oid(repo, ref)
131
+ redirect(history_url(repo, oid, path)) and return
132
+ end
133
+
134
+ actions.history(repo, u(ref), path, count) do |err, data|
111
135
  next error(err, repo, ref) if !err.nil?
112
136
  add_headers(response, :ref => ref)
113
137
  body(renderer.render(:commits, data))
@@ -123,7 +147,11 @@ module Dolt
123
147
  end
124
148
 
125
149
  def tree_history(repo, ref, path, count = 1)
126
- actions.tree_history(repo, ref, path, count) do |err, data|
150
+ if oid = lookup_ref_oid(repo, ref)
151
+ redirect(tree_history_url(repo, oid, path)) and return
152
+ end
153
+
154
+ actions.tree_history(repo, u(ref), path, count) do |err, data|
127
155
  begin
128
156
  if !err.nil?
129
157
  error(err, repo, ref)
@@ -137,7 +165,22 @@ module Dolt
137
165
  end
138
166
  end
139
167
 
168
+ def resolve_repository(repo)
169
+ actions.resolve_repository(repo)
170
+ end
171
+
140
172
  private
173
+ def lookup_ref_oid(repo, ref)
174
+ return if !respond_to?(:redirect_refs?) || !redirect_refs? || ref.length == 40
175
+ actions.rev_parse_oid(repo, ref)
176
+ end
177
+
178
+ def u(str)
179
+ # Temporarily swap the + out with a magic byte, so
180
+ # filenames/branches with +'s won't get unescaped to a space
181
+ CGI.unescape(str.gsub("+", "\001")).gsub("\001", '+')
182
+ end
183
+
141
184
  def add_headers(response, headers = {})
142
185
  default_ct = "text/html; charset=utf-8"
143
186
  response["Content-Type"] = headers[:content_type] || default_ct
@@ -48,6 +48,30 @@ class DummySinatraApp
48
48
  def blob_url(repo, ref, path)
49
49
  "/#{repo}/blob/#{ref}:#{path}"
50
50
  end
51
+
52
+ def tree_entry_url(repo, ref, path)
53
+ "/#{repo}/source/#{ref}:#{path}"
54
+ end
55
+
56
+ def blame_url(repo, ref, path)
57
+ "/#{repo}/blame/#{ref}:#{path}"
58
+ end
59
+
60
+ def history_url(repo, ref, path)
61
+ "/#{repo}/history/#{ref}:#{path}"
62
+ end
63
+
64
+ def tree_history_url(repo, ref, path)
65
+ "/#{repo}/tree_history/#{ref}:#{path}"
66
+ end
67
+
68
+ def raw_url(repo, ref, path)
69
+ "/#{repo}/raw/#{ref}:#{path}"
70
+ end
71
+ end
72
+
73
+ class RedirectingDummySinatraApp < DummySinatraApp
74
+ def redirect_refs?; true; end
51
75
  end
52
76
 
53
77
  class Renderer
@@ -119,6 +143,10 @@ class Actions
119
143
  data[type != :tree_entry ? type : (@response.class.to_s =~ /Tree/ ? :tree : :blob)] = @response
120
144
  block.call(nil, data)
121
145
  end
146
+
147
+ def rev_parse_oid(repo, ref)
148
+ "a" * 40
149
+ end
122
150
  end
123
151
 
124
152
  describe Dolt::Sinatra::Actions do
@@ -151,11 +179,30 @@ describe Dolt::Sinatra::Actions do
151
179
  end
152
180
 
153
181
  it "unescapes ref" do
154
- app = DummySinatraApp.new(Actions.new(BlobStub.new), Renderer.new("Blob"))
182
+ actions = Actions.new(BlobStub.new)
183
+ app = DummySinatraApp.new(actions, Renderer.new("Blob"))
155
184
  app.blob("gitorious", "issue-%23221", "app/my documents")
156
185
 
157
186
  assert_equal "issue-#221", actions.ref
158
187
  end
188
+
189
+ it "does not redirect ref to oid by default" do
190
+ app = DummySinatraApp.new(Actions.new(BlobStub.new), Renderer.new("Blob"))
191
+ app.blob("gitorious", "master", "lib/gitorious.rb")
192
+
193
+ location = app.response["Location"]
194
+ refute_equal 302, app.response.status
195
+ end
196
+
197
+ it "redirects ref to oid if configured so" do
198
+ app = RedirectingDummySinatraApp.new(Actions.new(BlobStub.new), Renderer.new("Blob"))
199
+ app.blob("gitorious", "master", "lib/gitorious.rb")
200
+
201
+ location = app.response["Location"]
202
+ assert_equal 302, app.response.status
203
+ assert_equal "/gitorious/blob/#{'a' * 40}:lib/gitorious.rb", location
204
+ assert_equal "", app.body
205
+ end
159
206
  end
160
207
 
161
208
  describe "#tree" do
@@ -208,6 +255,21 @@ describe Dolt::Sinatra::Actions do
208
255
  assert_equal "max-age=315360000, public", app.response["Cache-Control"]
209
256
  refute_nil app.response["Expires"]
210
257
  end
258
+
259
+ it "unescapes ref" do
260
+ actions = Actions.new(TreeStub.new)
261
+ app = DummySinatraApp.new(actions, Renderer.new("Tree"))
262
+ app.tree("gitorious", "issue-%23221", "app")
263
+
264
+ assert_equal "issue-#221", actions.ref
265
+ end
266
+
267
+ it "redirects ref to oid if configured so" do
268
+ app = RedirectingDummySinatraApp.new(Actions.new(TreeStub.new), Renderer.new("Tree"))
269
+ app.tree("gitorious", "master", "lib")
270
+
271
+ assert_equal "/gitorious/tree/#{'a' * 40}:lib", app.response["Location"]
272
+ end
211
273
  end
212
274
 
213
275
  describe "#tree_entry" do
@@ -226,6 +288,21 @@ describe Dolt::Sinatra::Actions do
226
288
  assert_equal "text/html; charset=utf-8", app.response["Content-Type"]
227
289
  assert_equal "blob:Blob", app.body
228
290
  end
291
+
292
+ it "unescapes ref" do
293
+ actions = Actions.new(TreeStub.new)
294
+ app = DummySinatraApp.new(actions, Renderer.new("Tree"))
295
+ app.tree_entry("gitorious", "issue-%23221", "app")
296
+
297
+ assert_equal "issue-#221", actions.ref
298
+ end
299
+
300
+ it "redirects ref to oid if configured so" do
301
+ app = RedirectingDummySinatraApp.new(Actions.new(TreeStub.new), Renderer.new("Tree"))
302
+ app.tree_entry("gitorious", "master", "lib")
303
+
304
+ assert_equal "/gitorious/source/#{'a' * 40}:lib", app.response["Location"]
305
+ end
229
306
  end
230
307
 
231
308
  describe "#raw" do
@@ -256,6 +333,21 @@ describe Dolt::Sinatra::Actions do
256
333
  assert_equal "/gitorious/tree/master:app/models", location
257
334
  assert_equal "", app.body
258
335
  end
336
+
337
+ it "unescapes ref" do
338
+ actions = Actions.new(BlobStub.new)
339
+ app = DummySinatraApp.new(actions, Renderer.new("Blob"))
340
+ app.raw("gitorious", "issue-%23221", "app/models/repository.rb")
341
+
342
+ assert_equal "issue-#221", actions.ref
343
+ end
344
+
345
+ it "redirects ref to oid if configured so" do
346
+ app = RedirectingDummySinatraApp.new(Actions.new(BlobStub.new), Renderer.new("Blob"))
347
+ app.raw("gitorious", "master", "lib/gitorious.rb")
348
+
349
+ assert_equal "/gitorious/raw/#{'a' * 40}:lib/gitorious.rb", app.response["Location"]
350
+ end
259
351
  end
260
352
 
261
353
  describe "#blame" do
@@ -276,6 +368,21 @@ describe Dolt::Sinatra::Actions do
276
368
  assert_equal "text/html; charset=utf-8", app.response["Content-Type"]
277
369
  assert_equal "blame:Text", app.body
278
370
  end
371
+
372
+ it "unescapes ref" do
373
+ actions = Actions.new(BlobStub.new)
374
+ app = DummySinatraApp.new(actions, Renderer.new("Blob"))
375
+ app.blame("gitorious", "issue-%23221", "app/models/repository.rb")
376
+
377
+ assert_equal "issue-#221", actions.ref
378
+ end
379
+
380
+ it "redirects ref to oid if configured so" do
381
+ app = RedirectingDummySinatraApp.new(Actions.new(BlobStub.new), Renderer.new("Blob"))
382
+ app.blame("gitorious", "master", "lib/gitorious.rb")
383
+
384
+ assert_equal "/gitorious/blame/#{'a' * 40}:lib/gitorious.rb", app.response["Location"]
385
+ end
279
386
  end
280
387
 
281
388
  describe "#history" do
@@ -296,6 +403,21 @@ describe Dolt::Sinatra::Actions do
296
403
  assert_equal "text/html; charset=utf-8", app.response["Content-Type"]
297
404
  assert_equal "commits:Text", app.body
298
405
  end
406
+
407
+ it "unescapes ref" do
408
+ actions = Actions.new(BlobStub.new)
409
+ app = DummySinatraApp.new(actions, Renderer.new("Blob"))
410
+ app.history("gitorious", "issue-%23221", "lib/gitorious.rb", 10)
411
+
412
+ assert_equal "issue-#221", actions.ref
413
+ end
414
+
415
+ it "redirects ref to oid if configured so" do
416
+ app = RedirectingDummySinatraApp.new(Actions.new(BlobStub.new), Renderer.new("Blob"))
417
+ app.history("gitorious", "master", "lib/gitorious.rb", 10)
418
+
419
+ assert_equal "/gitorious/history/#{'a' * 40}:lib/gitorious.rb", app.response["Location"]
420
+ end
299
421
  end
300
422
 
301
423
  describe "#refs" do
@@ -310,11 +432,26 @@ describe Dolt::Sinatra::Actions do
310
432
 
311
433
  describe "#tree_history" do
312
434
  it "renders the tree_history template as json" do
313
- app = DummySinatraApp.new(Actions.new(BlobStub.new), Renderer.new("JSON"))
435
+ app = DummySinatraApp.new(Actions.new(TreeStub.new), Renderer.new("JSON"))
314
436
  app.tree_history("gitorious", "master", "", 1)
315
437
 
316
438
  assert_equal "application/json", app.response["Content-Type"]
317
439
  assert_equal "tree_history:JSON", app.body
318
440
  end
441
+
442
+ it "unescapes ref" do
443
+ actions = Actions.new(TreeStub.new)
444
+ app = DummySinatraApp.new(actions, Renderer.new("Tree"))
445
+ app.tree_history("gitorious", "issue-%23221", "app/models")
446
+
447
+ assert_equal "issue-#221", actions.ref
448
+ end
449
+
450
+ it "redirects ref to oid if configured so" do
451
+ app = RedirectingDummySinatraApp.new(Actions.new(TreeStub.new), Renderer.new("Tree"))
452
+ app.tree_history("gitorious", "master", "lib", 10)
453
+
454
+ assert_equal "/gitorious/tree_history/#{'a' * 40}:lib", app.response["Location"]
455
+ end
319
456
  end
320
457
  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.10.0
4
+ version: 0.11.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '0.14'
21
+ version: '0.15'
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.14'
29
+ version: '0.15'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: thin
32
32
  requirement: !ruby/object:Gem::Requirement