gitrb 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/gitrb.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'gitrb'
3
- s.version = '0.1.4'
3
+ s.version = '0.1.5'
4
4
  s.summary = 'Pure ruby git implementation'
5
5
  s.author = 'Daniel Mendler'
6
6
  s.email = 'mail@daniel-mendler.de'
@@ -53,7 +53,6 @@ module Gitrb
53
53
 
54
54
  # Switch branch
55
55
  def branch=(branch)
56
- raise 'Forbidden from within a transaction' if in_transaction?
57
56
  @transaction.synchronize do
58
57
  @branch = branch
59
58
  load
@@ -72,7 +71,6 @@ module Gitrb
72
71
 
73
72
  # Clear cached objects
74
73
  def clear
75
- raise 'Forbidden from within a transaction' if in_transaction?
76
74
  @transaction.synchronize do
77
75
  @objects.clear
78
76
  load
@@ -104,15 +102,19 @@ module Gitrb
104
102
  # repository.transaction { repository['a'] = 'b' }
105
103
  #
106
104
  def transaction(message = '', author = nil, committer = nil)
107
- start_transaction
108
- result = yield
109
- commit(message, author, committer)
110
- result
111
- rescue
112
- rollback_transaction
113
- raise
114
- ensure
115
- finish_transaction
105
+ @transaction.synchronize do
106
+ begin
107
+ start_transaction
108
+ result = yield
109
+ commit(message, author, committer)
110
+ result
111
+ rescue
112
+ rollback_transaction
113
+ raise
114
+ ensure
115
+ finish_transaction
116
+ end
117
+ end
116
118
  end
117
119
 
118
120
  # Write a commit object to disk and set the head of the current branch.
@@ -332,7 +334,6 @@ module Gitrb
332
334
  # Tries to get lock on lock file, load the this repository if
333
335
  # has changed in the repository.
334
336
  def start_transaction
335
- @transaction.lock
336
337
  file = File.open("#{head_path}.lock", 'w')
337
338
  file.flock(File::LOCK_EX)
338
339
  @lock[Thread.current.object_id] = file
@@ -345,7 +346,6 @@ module Gitrb
345
346
  def rollback_transaction
346
347
  @objects.clear
347
348
  load
348
- finish_transaction
349
349
  end
350
350
 
351
351
  # Finish the transaction.
@@ -355,7 +355,6 @@ module Gitrb
355
355
  @lock[Thread.current.object_id].close rescue nil
356
356
  @lock.delete(Thread.current.object_id)
357
357
  File.unlink("#{head_path}.lock") rescue nil
358
- @transaction.unlock
359
358
  end
360
359
 
361
360
  def get_type(id, expected)
@@ -284,14 +284,28 @@ describe Gitrb do
284
284
 
285
285
  it 'should forbid branch switching from within transaction' do
286
286
  repo.transaction do
287
- lambda { repo.branch = 'test' }.should raise_error(RuntimeError)
287
+ lambda { repo.branch = 'test' }.should raise_error(ThreadError)
288
288
  end
289
289
  end
290
290
 
291
291
  it 'should forbid clearing from within transaction' do
292
292
  repo.transaction do
293
- lambda { repo.clear }.should raise_error(RuntimeError)
293
+ lambda { repo.clear }.should raise_error(ThreadError)
294
294
  end
295
295
  end
296
296
 
297
+ it 'should forbid nested transactions' do
298
+ repo.transaction do
299
+ lambda { repo.transaction {} }.should raise_error(ThreadError)
300
+ end
301
+ end
302
+
303
+ it 'should be in transaction' do
304
+ repo.should_not be_in_transaction
305
+ repo.transaction do
306
+ repo.should be_in_transaction
307
+ end
308
+ repo.should_not be_in_transaction
309
+ end
310
+
297
311
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Daniel Mendler