eternity 2.0.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +14 -1
- data/lib/eternity/commit.rb +1 -21
- data/lib/eternity/delta.rb +9 -4
- data/lib/eternity/patch.rb +3 -3
- data/lib/eternity/track_flatter.rb +2 -2
- data/lib/eternity/version.rb +2 -2
- data/spec/merge_spec.rb +50 -23
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f537658382ba4f3dd470886816e95c83318241b
|
4
|
+
data.tar.gz: a1adaa2d8cd91bc760752f08d17029ae992bf278
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8da66be778bc5fc98cb9afb69315d239b438ab9cce05e49a75268293ed6c7357f2f1dfa0c6202518757f4ac3316925ccaddc755c42d7c351783df184e4252df
|
7
|
+
data.tar.gz: 0cd4241e82f74c5d9f87e977847d5a4864d20a003705fb6cde8aa60422182f1eaae88a9fb1ecd13ed121f8cd0509d7f673fb737dde362507ed0702f69ea7f5e0
|
data/.travis.yml
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
language: ruby
|
2
|
+
|
2
3
|
rvm:
|
3
4
|
- 1.9.3
|
4
5
|
- 2.0
|
@@ -6,8 +7,20 @@ rvm:
|
|
6
7
|
- 2.2
|
7
8
|
- 2.3.0
|
8
9
|
- 2.4.0
|
9
|
-
-
|
10
|
+
- 2.5.0
|
11
|
+
- jruby-1.7.25
|
12
|
+
- jruby-9.1.7.0
|
13
|
+
- ruby-head
|
14
|
+
- jruby-head
|
15
|
+
|
16
|
+
matrix:
|
17
|
+
fast_finish: true
|
18
|
+
allow_failures:
|
19
|
+
- rvm: ruby-head
|
20
|
+
- rvm: jruby-head
|
21
|
+
|
10
22
|
services:
|
11
23
|
- redis-server
|
24
|
+
|
12
25
|
before_install:
|
13
26
|
- gem install bundler
|
data/lib/eternity/commit.rb
CHANGED
@@ -48,27 +48,7 @@ module Eternity
|
|
48
48
|
|
49
49
|
def history_ids
|
50
50
|
return [] if nil?
|
51
|
-
|
52
|
-
Blob.read :history, data['history']
|
53
|
-
else
|
54
|
-
# Backward compatibility
|
55
|
-
cache_key = self.class.history_cache_key[id]
|
56
|
-
return Eternity.connection.call 'LRANGE', cache_key, 0, -1 if Eternity.connection.call('EXISTS', cache_key) == 1
|
57
|
-
|
58
|
-
commit_ids =
|
59
|
-
if parent_ids.count == 2
|
60
|
-
current_history_ids = [parent_ids[0]] + Commit.new(parent_ids[0]).history_ids
|
61
|
-
target_history_ids = [parent_ids[1]] + Commit.new(parent_ids[1]).history_ids
|
62
|
-
current_history_ids - target_history_ids + target_history_ids
|
63
|
-
else
|
64
|
-
parent_id = parent_ids[0]
|
65
|
-
parent_id ? [parent_id] + Commit.new(parent_id).history_ids : []
|
66
|
-
end
|
67
|
-
|
68
|
-
Eternity.connection.call 'RPUSH', cache_key, *commit_ids
|
69
|
-
|
70
|
-
commit_ids
|
71
|
-
end
|
51
|
+
Blob.read :history, data['history']
|
72
52
|
end
|
73
53
|
|
74
54
|
def history
|
data/lib/eternity/delta.rb
CHANGED
@@ -14,16 +14,21 @@ module Eternity
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def merge(deltas, base_index)
|
17
|
+
def merge(deltas, base_index=nil)
|
18
18
|
union(deltas).each_with_object({}) do |(collection, elements), hash|
|
19
19
|
hash[collection] = {}
|
20
20
|
elements.each do |id, changes|
|
21
21
|
current_change = TrackFlatter.flatten changes
|
22
22
|
if current_change
|
23
23
|
if current_change['action'] == UPDATE
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
if base_index
|
25
|
+
base_data = base_index[collection].include?(id) ? base_index[collection][id].data : {}
|
26
|
+
current_change['data'] = changes.select { |c| c['data'] }
|
27
|
+
.inject(base_data) { |d,c| ConflictResolver.resolve d, c['data'], base_data }
|
28
|
+
else
|
29
|
+
current_change['data'] = changes.select { |c| c['data'] }
|
30
|
+
.inject({}) { |d,c| ConflictResolver.resolve d, c['data'] }
|
31
|
+
end
|
27
32
|
end
|
28
33
|
hash[collection][id] = current_change
|
29
34
|
end
|
data/lib/eternity/patch.rb
CHANGED
@@ -48,8 +48,8 @@ module Eternity
|
|
48
48
|
base_commit.with_index do |base_index|
|
49
49
|
current_commit.with_index do |current_index|
|
50
50
|
|
51
|
-
current_delta = Delta.merge current_history.reverse.map(&:delta)
|
52
|
-
target_delta = Delta.merge target_history.reverse.map(&:delta)
|
51
|
+
current_delta = Delta.merge current_history.reverse.map(&:delta)
|
52
|
+
target_delta = Delta.merge target_history.reverse.map(&:delta)
|
53
53
|
revert_delta = Delta.revert current_delta, base_index
|
54
54
|
|
55
55
|
merged_delta = merge_deltas target_delta, revert_delta, base_index
|
@@ -93,7 +93,7 @@ module Eternity
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def merge_deltas(target_delta, revert_delta, base_index)
|
96
|
-
remaining_delta = Delta.merge remaining_history.reverse.map(&:delta)
|
96
|
+
remaining_delta = Delta.merge remaining_history.reverse.map(&:delta)
|
97
97
|
Delta.merge [revert_delta, target_delta, remaining_delta], base_index
|
98
98
|
end
|
99
99
|
|
@@ -45,8 +45,8 @@ module Eternity
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def expand(change)
|
48
|
-
return change if change.key? 'data'
|
49
|
-
change.tap do |ch|
|
48
|
+
return change.dup if change.key? 'data'
|
49
|
+
change.dup.tap do |ch|
|
50
50
|
sha1 = ch.delete 'blob'
|
51
51
|
ch['data'] = Blob.read(:data, sha1) if sha1
|
52
52
|
end
|
data/lib/eternity/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Eternity
|
2
|
-
VERSION = '
|
3
|
-
end
|
2
|
+
VERSION = '3.0.0'
|
3
|
+
end
|
data/spec/merge_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe Repository, 'Merge' do
|
|
8
8
|
let(:commits) { Hash.new }
|
9
9
|
|
10
10
|
def commit(id, repo, &block)
|
11
|
-
repo[:countries].instance_eval
|
11
|
+
repo[:countries].instance_eval(&block)
|
12
12
|
commits[id] = repo.commit author: repo.name, message: "Commit #{id}"
|
13
13
|
end
|
14
14
|
|
@@ -31,10 +31,9 @@ describe Repository, 'Merge' do
|
|
31
31
|
commits[id].must_equal_index 'countries' => expected
|
32
32
|
end
|
33
33
|
|
34
|
-
describe '
|
34
|
+
describe 'Errors' do
|
35
35
|
|
36
36
|
it 'case 1' do
|
37
|
-
skip
|
38
37
|
commit 1, repo_1 do
|
39
38
|
insert 'AR', name: 'Argentina'
|
40
39
|
end
|
@@ -54,16 +53,14 @@ describe Repository, 'Merge' do
|
|
54
53
|
end
|
55
54
|
|
56
55
|
merge 5, repo_2, 4 do |delta|
|
57
|
-
|
56
|
+
delta.must_be_nil
|
58
57
|
end
|
59
58
|
|
60
|
-
|
61
|
-
|
62
|
-
end
|
59
|
+
assert_index 5, 'AR' => digest(name: 'Argentina'),
|
60
|
+
'UY' => digest(name: 'Uruguay')
|
63
61
|
end
|
64
62
|
|
65
63
|
it 'case 2' do
|
66
|
-
skip
|
67
64
|
commit 1, repo_1 do
|
68
65
|
insert 'AR', name: 'Argentina'
|
69
66
|
end
|
@@ -88,16 +85,14 @@ describe Repository, 'Merge' do
|
|
88
85
|
end
|
89
86
|
|
90
87
|
merge 6, repo_2, 5 do |delta|
|
91
|
-
|
88
|
+
delta.must_be_nil
|
92
89
|
end
|
93
90
|
|
94
|
-
|
95
|
-
|
96
|
-
end
|
91
|
+
assert_index 6, 'AR' => digest(name: 'Argentina'),
|
92
|
+
'UY' => digest(name: 'Uruguay')
|
97
93
|
end
|
98
94
|
|
99
95
|
it 'case 3 (patched)' do
|
100
|
-
skip
|
101
96
|
commit 1, repo_1 do
|
102
97
|
insert 'AR', name: 'Argentina'
|
103
98
|
end
|
@@ -110,33 +105,65 @@ describe Repository, 'Merge' do
|
|
110
105
|
end
|
111
106
|
|
112
107
|
commit 3, repo_2 do
|
113
|
-
update 'AR', name: 'Argentina
|
108
|
+
update 'AR', name: 'Republica Argentina'
|
114
109
|
end
|
115
110
|
|
111
|
+
assert_index 3, 'AR' => digest(name: 'Republica Argentina'),
|
112
|
+
'UY' => digest(name: 'Uruguay')
|
113
|
+
|
116
114
|
commit 4, repo_1 do
|
117
115
|
update 'AR', name: 'Arg'
|
118
116
|
end
|
119
117
|
|
120
118
|
commit 5, repo_1 do
|
121
|
-
update 'AR', name: 'Argentina'
|
119
|
+
update 'AR', name: 'Argentina', code: 'ARG'
|
122
120
|
end
|
123
121
|
|
124
122
|
merge 6, repo_2, 5 do |delta|
|
125
|
-
|
123
|
+
delta['AR'].must_equal 'action' => 'update', 'data' => {'name' => 'Republica Argentina', 'code' => 'ARG'}
|
126
124
|
end
|
127
125
|
|
128
|
-
|
129
|
-
|
130
|
-
end
|
126
|
+
assert_index 6, 'AR' => digest(name: 'Republica Argentina', code: 'ARG'),
|
127
|
+
'UY' => digest(name: 'Uruguay')
|
131
128
|
|
132
129
|
merge 7, repo_1, 3 do |delta|
|
133
|
-
|
130
|
+
delta['AR'].must_equal 'action' => 'update', 'data' => {'name' => 'Republica Argentina', 'code' => 'ARG'}
|
131
|
+
end
|
132
|
+
|
133
|
+
assert_index 7, 'AR' => digest(name: 'Republica Argentina', code: 'ARG'),
|
134
|
+
'UY' => digest(name: 'Uruguay')
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'case 4' do
|
138
|
+
commit 1, repo_1 do
|
139
|
+
insert 'AR', name: 'Argentina'
|
134
140
|
end
|
135
141
|
|
136
|
-
|
137
|
-
|
138
|
-
|
142
|
+
checkout 1, repo_2
|
143
|
+
|
144
|
+
commit 2, repo_1 do
|
145
|
+
update 'AR', name: 'Republica Argentina'
|
146
|
+
end
|
147
|
+
|
148
|
+
commit 3, repo_2 do
|
149
|
+
update 'AR', name: 'Argentina', code: 'ARG'
|
150
|
+
end
|
151
|
+
|
152
|
+
merge 4, repo_2, 2 do |delta|
|
153
|
+
delta['AR'].must_equal 'action' => 'update', 'data' => {'name' => 'Republica Argentina', 'code' => 'ARG'}
|
154
|
+
end
|
155
|
+
|
156
|
+
assert_index 4, 'AR' => digest(name: 'Republica Argentina', code: 'ARG')
|
157
|
+
|
158
|
+
commit 5, repo_1 do
|
159
|
+
update 'AR', name: 'Argentina'
|
160
|
+
end
|
161
|
+
|
162
|
+
merge 6, repo_2, 5 do |delta|
|
163
|
+
delta['AR'].must_equal 'action' => 'update', 'data' => {'name' => 'Argentina', 'code' => 'ARG'}
|
164
|
+
end
|
139
165
|
|
166
|
+
assert_index 6, 'AR' => digest(name: 'Argentina', code: 'ARG')
|
140
167
|
end
|
141
168
|
|
142
169
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eternity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Naiman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: restruct
|