Skip to content

Commit

Permalink
Fix merge error
Browse files Browse the repository at this point in the history
  • Loading branch information
gabynaiman committed Apr 5, 2016
1 parent 5e73611 commit 5467452
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 27 deletions.
19 changes: 6 additions & 13 deletions lib/eternity/delta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,15 @@ def merge(deltas, base_index)
union(deltas).each_with_object({}) do |(collection, elements), hash|
hash[collection] = {}
elements.each do |id, changes|
changes.each do |change|
current_change = change
if hash[collection][id]
current_change = TrackFlatter.flatten [hash[collection][id], change]
if current_change && [INSERT, UPDATE].include?(current_change['action'])
base_data = base_index[collection].include?(id) ? base_index[collection][id].data : {}
current_change['data'] = ConflictResolver.resolve hash[collection][id]['data'] || base_data,
change['data'],
base_data
end
elsif hash[collection].key?(id) && change['action'] == DELETE
current_change = nil
current_change = TrackFlatter.flatten changes
if current_change
if current_change['action'] == UPDATE
base_data = base_index[collection].include?(id) ? base_index[collection][id].data : {}
current_change['data'] = changes.select { |c| c['data'] }
.inject(base_data) { |d,c| ConflictResolver.resolve d, c['data'], base_data }
end
hash[collection][id] = current_change
end
hash[collection].delete id unless hash[collection][id]
end
hash.delete collection if hash[collection].empty?
end
Expand Down
11 changes: 0 additions & 11 deletions lib/eternity/patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,6 @@ def calculate_delta
hash[collection] = {}

elements.each do |id, change|

# if change['action'] == UPDATE
# if !current_index[collection].include?(id)
# change['action'] = INSERT
# elsif current_index[collection][id].sha1 == Blob.digest(Blob.serialize(change['data']))
# change = nil
# end
# elsif change['action'] == DELETE && !current_index[collection].include?(id)
# change = nil
# end

if change['action'] == UPDATE && current_index[collection][id].sha1 == Blob.digest(Blob.serialize(change['data']))
change = nil
elsif change['action'] == DELETE && !current_index[collection].include?(id)
Expand Down
3 changes: 0 additions & 3 deletions spec/delta_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
let(:repo_3) { Repository.new :test_3 }

it 'Merge -> Checkout (2 times)' do
skip
# P P P
# REPO 1: (*)--(1)---(4)---(5) (6)--(8) (10)
# \ \ / \ / \
Expand Down Expand Up @@ -116,7 +115,6 @@
end

it 'Commit -> Pull -> Push (multiple times)' do
skip
# P MP MP M
# REPO 1: (*)--(1)--(3)--(4)--(7)--(8)--(11)--(12)
# \ / \ / \ /
Expand Down Expand Up @@ -232,7 +230,6 @@
end

it 'Merge -> Merge -> Checkout' do
skip
# P MP P
# REPO 1: (*)--(1)--(2)------(6)--(7)
# \ MP / \
Expand Down

0 comments on commit 5467452

Please sign in to comment.