git-ds 0.9.8 → 0.9.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +4 -0
- data/lib/git-ds/database.rb +43 -1
- data/lib/git-ds/index.rb +23 -0
- data/lib/git-ds/model.rb +2 -26
- data/lib/git-ds/transaction.rb +38 -17
- data/tests/ut_database.rb +2 -1
- metadata +4 -3
data/ChangeLog
CHANGED
data/lib/git-ds/database.rb
CHANGED
@@ -223,7 +223,6 @@ See Transaction.
|
|
223
223
|
return transaction_in_staging(true, &block) if self.staging?
|
224
224
|
|
225
225
|
begin
|
226
|
-
self.staging
|
227
226
|
transaction_in_staging(false, &block)
|
228
227
|
ensure
|
229
228
|
self.unstage
|
@@ -339,6 +338,49 @@ See Database#transaction .
|
|
339
338
|
rv
|
340
339
|
end
|
341
340
|
|
341
|
+
=begin rdoc
|
342
|
+
Execute a block using an in-memory Staging index.
|
343
|
+
|
344
|
+
This is an optimization. It writes the current index to the git staging index
|
345
|
+
on disk, replaces it with an in-memory index that DOES NOT write to the object
|
346
|
+
tree on disk, invokes the block, writes the in-memory index to the git staging
|
347
|
+
index on disk, then reads the staging index into the repo/database and makes
|
348
|
+
it the current index.
|
349
|
+
|
350
|
+
The idea is to reduce disk writes caused by exec and transaction, which can
|
351
|
+
end up being very costly when nested.
|
352
|
+
|
353
|
+
NOTE: branch-and-merge will fail if in batch mode (TODO: FIX).
|
354
|
+
=end
|
355
|
+
def batch(&block)
|
356
|
+
# NOTE: the use of 'self.staging' is quite important in this method.
|
357
|
+
|
358
|
+
# write current index to git-staging-index
|
359
|
+
idx = self.staging? ? self.staging : nil
|
360
|
+
idx.sync if idx
|
361
|
+
|
362
|
+
# replace current index with an in-mem staging index
|
363
|
+
unstage
|
364
|
+
self.staging=StageMemIndex.read(self)
|
365
|
+
|
366
|
+
begin
|
367
|
+
yield staging if block_given?
|
368
|
+
|
369
|
+
rescue Exception => e
|
370
|
+
# ensure index is discarded if there is a problem
|
371
|
+
unstage
|
372
|
+
self.staging if idx
|
373
|
+
raise e
|
374
|
+
end
|
375
|
+
|
376
|
+
# write in-mem staging index to git-staging-index
|
377
|
+
self.staging.sync
|
378
|
+
|
379
|
+
# read git-staging-index if appropriate
|
380
|
+
unstage
|
381
|
+
self.staging if idx
|
382
|
+
end
|
383
|
+
|
342
384
|
# ----------------------------------------------------------------------
|
343
385
|
private
|
344
386
|
|
data/lib/git-ds/index.rb
CHANGED
@@ -203,10 +203,33 @@ This can be used to access index contents created by command-line tools.
|
|
203
203
|
|
204
204
|
end
|
205
205
|
|
206
|
+
=begin rdoc
|
207
|
+
In-memory staging index.
|
208
|
+
|
209
|
+
This replaces the StageIndex#build method with a nop, so that the index is
|
210
|
+
not written to disk.
|
211
|
+
|
212
|
+
This is primarily useful in transactions or in methods such as Database#batch.
|
213
|
+
Keepin the tree in-memory as long as necessary reduces disk writes and
|
214
|
+
speeds up bulk insert/delete operations.
|
215
|
+
=end
|
206
216
|
class StageMemIndex < StageIndex
|
217
|
+
|
218
|
+
=begin rdoc
|
219
|
+
Return the sha of the stage index on disk. This DOES NOT synchronize the
|
220
|
+
in-memory index with the on-disk index.
|
221
|
+
=end
|
207
222
|
def build
|
208
223
|
return @sha
|
209
224
|
end
|
225
|
+
|
226
|
+
=begin rdoc
|
227
|
+
Override StageIndex#sync to not rely on StageIndex#build.
|
228
|
+
=end
|
229
|
+
def sync
|
230
|
+
self.read_tree(self.write)
|
231
|
+
@repo.exec_in_git_dir { `git read-tree #{@sha}` }
|
232
|
+
end
|
210
233
|
end
|
211
234
|
|
212
235
|
|
data/lib/git-ds/model.rb
CHANGED
@@ -136,34 +136,10 @@ See Database#branch_and_merge.
|
|
136
136
|
=begin
|
137
137
|
Execute a block using an in-memory Staging index.
|
138
138
|
|
139
|
-
This
|
140
|
-
on disk, replaces it with an in-memory index that DOES NOT write to the object
|
141
|
-
tree on disk, invokes the block, writes the in-memory index to the git staging
|
142
|
-
index on disk, then reads the staging index into the repo/database and makes
|
143
|
-
it the current index.
|
144
|
-
|
145
|
-
The idea is to reduce disk writes caused by exec and transaction, which can
|
146
|
-
end up being very costly when nested.
|
147
|
-
|
148
|
-
NOTE: branch-and-merge will fail if in batch mode.
|
139
|
+
This isjust a wrapper for Database#batch.
|
149
140
|
=end
|
150
141
|
def batch(&block)
|
151
|
-
|
152
|
-
idx = (@db.staging?) ? @db.staging : nil
|
153
|
-
idx.sync if idx
|
154
|
-
|
155
|
-
# replace current index with an in-mem staging index
|
156
|
-
@db.unstage
|
157
|
-
@db.staging=StageMemIndex.read(@db)
|
158
|
-
|
159
|
-
yield @db.staging if block_given?
|
160
|
-
|
161
|
-
# write in-mem staging index to git-staging-index
|
162
|
-
@db.staging.sync
|
163
|
-
|
164
|
-
# read git-staging-index if appropriate
|
165
|
-
@db.unstage
|
166
|
-
@db.staging if idx
|
142
|
+
@db.batch(&block)
|
167
143
|
end
|
168
144
|
|
169
145
|
end
|
data/lib/git-ds/transaction.rb
CHANGED
@@ -38,25 +38,13 @@ rollback() is called.
|
|
38
38
|
=end
|
39
39
|
def perform
|
40
40
|
@propagate_exceptions = false # propagation off by default
|
41
|
-
rv = true
|
42
|
-
begin
|
43
|
-
instance_eval(&self.block)
|
44
|
-
rescue Exception => e
|
45
|
-
raise e if self.nested
|
46
|
-
raise e if (not e.kind_of? TransactionRollback) && @propagate_exceptions
|
47
|
-
|
48
|
-
rv = false
|
49
|
-
end
|
50
41
|
|
51
|
-
if
|
52
|
-
self.index.build # required during nesting to support merge_and_branch
|
53
|
-
if not self.nested
|
54
|
-
commit
|
55
|
-
@database.notify
|
56
|
-
end
|
57
|
-
end
|
42
|
+
return perform_top_level if not self.nested
|
58
43
|
|
59
|
-
|
44
|
+
instance_eval(&self.block)
|
45
|
+
index.build
|
46
|
+
|
47
|
+
true
|
60
48
|
end
|
61
49
|
|
62
50
|
=begin rdoc
|
@@ -76,5 +64,38 @@ Abort the transaction.
|
|
76
64
|
raise TransactionRollback.new
|
77
65
|
end
|
78
66
|
|
67
|
+
=begin rdoc
|
68
|
+
Overrides ExecCmd#index accessor as the Transaction index will change if
|
69
|
+
batch mode is used.
|
70
|
+
=end
|
71
|
+
def index
|
72
|
+
database.index
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
=begin rdoc
|
78
|
+
Top-level transactions are performed in batch mode to speed things up.
|
79
|
+
=end
|
80
|
+
def perform_top_level
|
81
|
+
@propagate_exceptions = true
|
82
|
+
rv = true
|
83
|
+
|
84
|
+
begin
|
85
|
+
xact = self
|
86
|
+
database.batch do
|
87
|
+
xact.instance_eval(&xact.block)
|
88
|
+
end
|
89
|
+
|
90
|
+
commit
|
91
|
+
@database.notify
|
92
|
+
rescue Exception => e
|
93
|
+
raise e if (not e.kind_of? TransactionRollback) && @propagate_exceptions
|
94
|
+
rv = false
|
95
|
+
end
|
96
|
+
|
97
|
+
rv
|
98
|
+
end
|
99
|
+
|
79
100
|
end
|
80
101
|
end
|
data/tests/ut_database.rb
CHANGED
@@ -215,8 +215,9 @@ class TC_GitDatabaseTest < Test::Unit::TestCase
|
|
215
215
|
|
216
216
|
# test rollback on raise
|
217
217
|
@db.transaction {
|
218
|
+
propagate
|
218
219
|
index.add(name1, data1)
|
219
|
-
|
220
|
+
rollback
|
220
221
|
}
|
221
222
|
blob = index.current_tree./(name1)
|
222
223
|
assert_nil(blob, "transaction raise still created '#{name1}' in staging")
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-ds
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 37
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
9
|
- 8
|
10
|
-
|
10
|
+
- 1
|
11
|
+
version: 0.9.8.1
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- TG Community
|
@@ -15,7 +16,7 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2011-07-
|
19
|
+
date: 2011-07-31 00:00:00 -04:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|