git_store 0.3.1
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/.gitignore +5 -0
- data/LICENSE +18 -0
- data/README.md +147 -0
- data/Rakefile +35 -0
- data/git_store.gemspec +40 -0
- data/lib/git_store/blob.rb +32 -0
- data/lib/git_store/commit.rb +65 -0
- data/lib/git_store/diff.rb +76 -0
- data/lib/git_store/handlers.rb +36 -0
- data/lib/git_store/pack.rb +425 -0
- data/lib/git_store/tag.rb +40 -0
- data/lib/git_store/tree.rb +183 -0
- data/lib/git_store/user.rb +29 -0
- data/lib/git_store.rb +392 -0
- data/test/bare_store_spec.rb +33 -0
- data/test/benchmark.rb +30 -0
- data/test/commit_spec.rb +81 -0
- data/test/git_store_spec.rb +257 -0
- data/test/tree_spec.rb +92 -0
- metadata +79 -0
@@ -0,0 +1,257 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../lib/git_store"
|
2
|
+
require "#{File.dirname(__FILE__)}/helper"
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
describe GitStore do
|
6
|
+
|
7
|
+
REPO = '/tmp/git_store_test'
|
8
|
+
|
9
|
+
attr_reader :store
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
FileUtils.rm_rf REPO
|
13
|
+
Dir.mkdir REPO
|
14
|
+
Dir.chdir REPO
|
15
|
+
|
16
|
+
`git init`
|
17
|
+
@store = GitStore.new(REPO)
|
18
|
+
end
|
19
|
+
|
20
|
+
def file(file, data)
|
21
|
+
FileUtils.mkpath(File.dirname(file))
|
22
|
+
open(file, 'w') { |io| io << data }
|
23
|
+
|
24
|
+
`git add #{file}`
|
25
|
+
`git commit -m 'added #{file}'`
|
26
|
+
File.unlink(file)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should fail to initialize without a valid git repository' do
|
30
|
+
lambda {
|
31
|
+
GitStore.new('/')
|
32
|
+
}.should raise_error(ArgumentError)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should find modified entries' do
|
36
|
+
store['a'] = 'Hello'
|
37
|
+
|
38
|
+
store.root.should be_modified
|
39
|
+
|
40
|
+
store.commit
|
41
|
+
|
42
|
+
store.root.should_not be_modified
|
43
|
+
|
44
|
+
store['a'] = 'Bello'
|
45
|
+
|
46
|
+
store.root.should be_modified
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should load a repo' do
|
50
|
+
file 'a', 'Hello'
|
51
|
+
file 'b', 'World'
|
52
|
+
|
53
|
+
store.load
|
54
|
+
|
55
|
+
store['a'].should == 'Hello'
|
56
|
+
store['b'].should == 'World'
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should load folders' do
|
60
|
+
file 'x/a', 'Hello'
|
61
|
+
file 'y/b', 'World'
|
62
|
+
|
63
|
+
store.load
|
64
|
+
store['x'].should be_kind_of(GitStore::Tree)
|
65
|
+
store['y'].should be_kind_of(GitStore::Tree)
|
66
|
+
|
67
|
+
store['x']['a'].should == 'Hello'
|
68
|
+
store['y']['b'].should == 'World'
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should load yaml' do
|
72
|
+
file 'x/a.yml', '[1, 2, 3, 4]'
|
73
|
+
|
74
|
+
store.load
|
75
|
+
|
76
|
+
store['x']['a.yml'].should == [1,2,3,4]
|
77
|
+
store['x']['a.yml'] = [1,2,3,4,5]
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should save yaml' do
|
81
|
+
store['x/a.yml'] = [1,2,3,4,5]
|
82
|
+
store['x/a.yml'].should == [1,2,3,4,5]
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should detect modification' do
|
86
|
+
store.transaction do
|
87
|
+
store['x/a'] = 'a'
|
88
|
+
end
|
89
|
+
|
90
|
+
store.load
|
91
|
+
|
92
|
+
store['x/a'].should == 'a'
|
93
|
+
|
94
|
+
store.transaction do
|
95
|
+
store['x/a'] = 'b'
|
96
|
+
store['x'].should be_modified
|
97
|
+
store.root.should be_modified
|
98
|
+
end
|
99
|
+
|
100
|
+
store.load
|
101
|
+
|
102
|
+
store['x/a'].should == 'b'
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should resolve paths' do
|
106
|
+
file 'x/a', 'Hello'
|
107
|
+
file 'y/b', 'World'
|
108
|
+
|
109
|
+
store.load
|
110
|
+
|
111
|
+
store['x/a'].should == 'Hello'
|
112
|
+
store['y/b'].should == 'World'
|
113
|
+
|
114
|
+
store['y/b'] = 'Now this'
|
115
|
+
|
116
|
+
store['y']['b'].should == 'Now this'
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should create new trees' do
|
120
|
+
store['new/tree'] = 'This tree'
|
121
|
+
store['new/tree'].should == 'This tree'
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'should delete entries' do
|
125
|
+
store['a'] = 'Hello'
|
126
|
+
store.delete('a')
|
127
|
+
|
128
|
+
store['a'].should be_nil
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should have a head commit' do
|
132
|
+
file 'a', 'Hello'
|
133
|
+
|
134
|
+
store.load
|
135
|
+
store.head.should_not be_nil
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should detect changes' do
|
139
|
+
file 'a', 'Hello'
|
140
|
+
|
141
|
+
store.should be_changed
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should rollback a transaction' do
|
145
|
+
file 'a/b', 'Hello'
|
146
|
+
file 'c/d', 'World'
|
147
|
+
|
148
|
+
begin
|
149
|
+
store.transaction do
|
150
|
+
store['a/b'] = 'Changed'
|
151
|
+
store['x/a'] = 'Added'
|
152
|
+
raise
|
153
|
+
end
|
154
|
+
rescue
|
155
|
+
end
|
156
|
+
|
157
|
+
store['a/b'].should == 'Hello'
|
158
|
+
store['c/d'].should == 'World'
|
159
|
+
store['x/a'].should be_nil
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'should commit a transaction' do
|
163
|
+
file 'a/b', 'Hello'
|
164
|
+
file 'c/d', 'World'
|
165
|
+
|
166
|
+
store.transaction do
|
167
|
+
store['a/b'] = 'Changed'
|
168
|
+
store['x/a'] = 'Added'
|
169
|
+
end
|
170
|
+
|
171
|
+
a = git_ls_tree(store['a'].id)
|
172
|
+
x = git_ls_tree(store['x'].id)
|
173
|
+
|
174
|
+
a.should == [["100644", "blob", "b653cf27cef08de46da49a11fa5016421e9e3b32", "b"]]
|
175
|
+
x.should == [["100644", "blob", "87d2b203800386b1cc8735a7d540a33e246357fa", "a"]]
|
176
|
+
|
177
|
+
git_show(a[0][2]).should == 'Changed'
|
178
|
+
git_show(x[0][2]).should == 'Added'
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should save blobs" do
|
182
|
+
store['a'] = 'a'
|
183
|
+
store['b'] = 'b'
|
184
|
+
store['c'] = 'c'
|
185
|
+
|
186
|
+
store.commit
|
187
|
+
|
188
|
+
a = store.id_for('blob', 'a')
|
189
|
+
b = store.id_for('blob', 'b')
|
190
|
+
c = store.id_for('blob', 'c')
|
191
|
+
|
192
|
+
git_show(a).should == 'a'
|
193
|
+
git_show(b).should == 'b'
|
194
|
+
git_show(c).should == 'c'
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should allow only one transaction' do
|
198
|
+
file 'a/b', 'Hello'
|
199
|
+
|
200
|
+
ready = false
|
201
|
+
|
202
|
+
store.transaction do
|
203
|
+
Thread.start do
|
204
|
+
store.transaction do
|
205
|
+
store['a/b'] = 'Changed by second thread'
|
206
|
+
end
|
207
|
+
ready = true
|
208
|
+
end
|
209
|
+
store['a/b'] = 'Changed'
|
210
|
+
end
|
211
|
+
|
212
|
+
sleep 0.01 until ready
|
213
|
+
|
214
|
+
store.load
|
215
|
+
|
216
|
+
store['a/b'].should == 'Changed by second thread'
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'should find all objects' do
|
220
|
+
store.load
|
221
|
+
store['c'] = 'Hello'
|
222
|
+
store['d'] = 'World'
|
223
|
+
store.commit
|
224
|
+
|
225
|
+
store.to_a.should == [['c', 'Hello'], ['d', 'World']]
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should load commits" do
|
229
|
+
store['a'] = 'a'
|
230
|
+
store.commit 'added a'
|
231
|
+
|
232
|
+
store['b'] = 'b'
|
233
|
+
store.commit 'added b'
|
234
|
+
|
235
|
+
store.commits[0].message.should == 'added b'
|
236
|
+
store.commits[1].message.should == 'added a'
|
237
|
+
end
|
238
|
+
|
239
|
+
it "should load tags" do
|
240
|
+
file 'a', 'init'
|
241
|
+
|
242
|
+
`git tag -m 'message' 0.1`
|
243
|
+
|
244
|
+
store.load
|
245
|
+
|
246
|
+
user = GitStore::User.from_config
|
247
|
+
id = File.read('.git/refs/tags/0.1')
|
248
|
+
tag = store.get(id)
|
249
|
+
|
250
|
+
tag.type.should == 'commit'
|
251
|
+
tag.object.should == store.head
|
252
|
+
tag.tagger.name.should == user.name
|
253
|
+
tag.tagger.email.should == user.email
|
254
|
+
tag.message.should =~ /message/
|
255
|
+
end
|
256
|
+
|
257
|
+
end
|
data/test/tree_spec.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../lib/git_store"
|
2
|
+
require "#{File.dirname(__FILE__)}/helper"
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
describe GitStore::Tree do
|
6
|
+
REPO = '/tmp/git_store_test'
|
7
|
+
|
8
|
+
attr_reader :store, :tree
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
FileUtils.rm_rf REPO
|
12
|
+
Dir.mkdir REPO
|
13
|
+
Dir.chdir REPO
|
14
|
+
|
15
|
+
`git init`
|
16
|
+
|
17
|
+
@store = GitStore.new(REPO)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should parse a table" do
|
21
|
+
tree = GitStore::Tree.new(store)
|
22
|
+
|
23
|
+
a = store.put_object("blob", "a")
|
24
|
+
b = store.put_object("blob", "b")
|
25
|
+
c = store.put_object("blob", "c")
|
26
|
+
|
27
|
+
data =
|
28
|
+
"100644 a\0#{ [a].pack("H*") }" +
|
29
|
+
"100644 b\0#{ [b].pack("H*") }" +
|
30
|
+
"100644 c\0#{ [c].pack("H*") }"
|
31
|
+
|
32
|
+
tree.parse(data)
|
33
|
+
|
34
|
+
tree.get('a').should == 'a'
|
35
|
+
tree.get('b').should == 'b'
|
36
|
+
tree.get('c').should == 'c'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should write a table" do
|
40
|
+
tree = GitStore::Tree.new(store)
|
41
|
+
|
42
|
+
tree['a'] = 'a'
|
43
|
+
tree['b'] = 'b'
|
44
|
+
tree['c'] = 'c'
|
45
|
+
|
46
|
+
id = tree.write
|
47
|
+
|
48
|
+
a = ["2e65efe2a145dda7ee51d1741299f848e5bf752e"].pack('H*')
|
49
|
+
b = ["63d8dbd40c23542e740659a7168a0ce3138ea748"].pack('H*')
|
50
|
+
c = ["3410062ba67c5ed59b854387a8bc0ec012479368"].pack('H*')
|
51
|
+
|
52
|
+
data =
|
53
|
+
"100644 a\0#{a}" +
|
54
|
+
"100644 b\0#{b}" +
|
55
|
+
"100644 c\0#{c}"
|
56
|
+
|
57
|
+
store.get_object(id).should == ['tree', data]
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should save trees" do
|
61
|
+
tree = GitStore::Tree.new(store)
|
62
|
+
|
63
|
+
tree['a'] = 'a'
|
64
|
+
tree['b'] = 'b'
|
65
|
+
tree['c'] = 'c'
|
66
|
+
|
67
|
+
tree.write
|
68
|
+
|
69
|
+
git_ls_tree(tree.id).should ==
|
70
|
+
[["100644", "blob", "2e65efe2a145dda7ee51d1741299f848e5bf752e", "a"],
|
71
|
+
["100644", "blob", "63d8dbd40c23542e740659a7168a0ce3138ea748", "b"],
|
72
|
+
["100644", "blob", "3410062ba67c5ed59b854387a8bc0ec012479368", "c"]]
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should save nested trees" do
|
76
|
+
tree = GitStore::Tree.new(store)
|
77
|
+
|
78
|
+
tree['x/a'] = 'a'
|
79
|
+
tree['x/b'] = 'b'
|
80
|
+
tree['x/c'] = 'c'
|
81
|
+
|
82
|
+
tree.write
|
83
|
+
|
84
|
+
git_ls_tree(tree.id).should ==
|
85
|
+
[["040000", "tree", "24e88cb96c396400000ef706d1ca1ed9a88251aa", "x"]]
|
86
|
+
|
87
|
+
git_ls_tree("24e88cb96c396400000ef706d1ca1ed9a88251aa").should ==
|
88
|
+
[["100644", "blob", "2e65efe2a145dda7ee51d1741299f848e5bf752e", "a"],
|
89
|
+
["100644", "blob", "63d8dbd40c23542e740659a7168a0ce3138ea748", "b"],
|
90
|
+
["100644", "blob", "3410062ba67c5ed59b854387a8bc0ec012479368", "c"]]
|
91
|
+
end
|
92
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git_store
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthias Georgi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-02-07 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: |
|
17
|
+
GitStore implements a versioned data store based on the revision
|
18
|
+
management system Git. You can store object hierarchies as nested
|
19
|
+
hashes, which will be mapped on the directory structure of a git
|
20
|
+
repository. GitStore checks out the repository into a in-memory
|
21
|
+
representation, which can be modified and finally committed.
|
22
|
+
|
23
|
+
email: matti.georgi@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README.md
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- LICENSE
|
33
|
+
- README.md
|
34
|
+
- Rakefile
|
35
|
+
- git_store.gemspec
|
36
|
+
- lib/git_store.rb
|
37
|
+
- lib/git_store/blob.rb
|
38
|
+
- lib/git_store/commit.rb
|
39
|
+
- lib/git_store/diff.rb
|
40
|
+
- lib/git_store/handlers.rb
|
41
|
+
- lib/git_store/pack.rb
|
42
|
+
- lib/git_store/tag.rb
|
43
|
+
- lib/git_store/tree.rb
|
44
|
+
- lib/git_store/user.rb
|
45
|
+
- test/bare_store_spec.rb
|
46
|
+
- test/benchmark.rb
|
47
|
+
- test/commit_spec.rb
|
48
|
+
- test/git_store_spec.rb
|
49
|
+
- test/tree_spec.rb
|
50
|
+
has_rdoc: true
|
51
|
+
homepage: http://ww.matthias-georgi.de/git_store
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
version:
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.3.5
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: a simple data store based on git
|
78
|
+
test_files: []
|
79
|
+
|