gitrb 0.1.4 → 0.1.5
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.
- data/gitrb.gemspec +1 -1
- data/lib/gitrb/repository.rb +13 -14
- data/test/repository_spec.rb +16 -2
- metadata +2 -2
data/gitrb.gemspec
CHANGED
data/lib/gitrb/repository.rb
CHANGED
@@ -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
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
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)
|
data/test/repository_spec.rb
CHANGED
@@ -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(
|
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(
|
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
|