Skip to content

Commit

Permalink
NestedHash optimization.
Browse files Browse the repository at this point in the history
Commit optimization.
Fix pull without previous commit.
  • Loading branch information
Gabriel Naiman committed Jan 13, 2015
1 parent d4603ac commit a20b7b4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/eternity/commit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def base_delta
end

def fast_forward?(commit)
return true unless commit
return commit.nil? if base.nil?
base.id == commit.id || base.fast_forward?(commit)
end
Expand Down
6 changes: 3 additions & 3 deletions lib/eternity/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def pull
commit! author: 'System',
message: "Merge #{target_commit.id} into #{current_commit.id}",
parents: patch.commit_ids,
delta: nil,
index: write_index(patch.index_delta),
base: patch.base_commit.id,
base_delta: Blob.write(:delta, patch.base_delta)
Expand Down Expand Up @@ -125,9 +124,10 @@ def write_index(delta)
end

def commit!(options)
changes = delta
options[:parents] ||= current_commit? ? [current_commit.id] : []
options[:delta] ||= Blob.write :delta, delta
options[:index] ||= write_index delta
options[:delta] ||= Blob.write :delta, changes
options[:index] ||= write_index changes

tracker.clear

Expand Down
8 changes: 7 additions & 1 deletion lib/restruct/nested_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ def key?(field)
end

def empty?
keys.empty?
size == 0
end

def size
redis.call('KEYS', key['*']).count
end
alias_method :count, :size
alias_method :length, :size

def each
keys.each { |field| yield field, self[field] }
end
Expand Down
10 changes: 10 additions & 0 deletions spec/pull_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
error.message.must_equal 'Branch not found: master'
end

it 'Without previous commit' do
commit_id = '123456789'
Branch[:master] = commit_id

session.pull

session.current_commit.id.must_equal commit_id
session.branches[session.current_branch].must_equal commit_id
end

it 'Fast-forward' do
session[:countries].insert 'AR', name: 'Argentina'
commit_1 = session.commit author: 'User', message: 'Commit 1'
Expand Down

0 comments on commit a20b7b4

Please sign in to comment.