class Eternity::Commit
Attributes
id[R]
Public Class Methods
base_of(commit_1, commit_2)
click to toggle source
# File lib/eternity/commit.rb, line 119 def self.base_of(commit_1, commit_2) history_1 = [commit_1.id] history_2 = [commit_2.id] base_1 = commit_1 base_2 = commit_2 while (history_1 & history_2).empty? base_1 = base_1.base if base_1 base_2 = base_2.base if base_2 history_1 << base_1.id if base_1 history_2 << base_2.id if base_2 end Commit.new (history_1 & history_2).first end
clear_history_cache()
click to toggle source
# File lib/eternity/commit.rb, line 148 def self.clear_history_cache Eternity.connection.call('KEYS', history_cache_key['*']).each_slice(1000) do |keys| Eternity.connection.call 'DEL', *keys end end
create(options)
click to toggle source
# File lib/eternity/commit.rb, line 90 def self.create(options) raise 'Author must be present' if options[:author].to_s.strip.empty? raise 'Message must be present' if options[:message].to_s.strip.empty? # TODO: Move to Repository and Patch history = if options[:parents].count == 2 current_history_ids = [options[:parents][0]] + Commit.new(options[:parents][0]).history_ids target_history_ids = [options[:parents][1]] + Commit.new(options[:parents][1]).history_ids current_history_ids - target_history_ids + target_history_ids else parent_id = options[:parents][0] parent_id ? [parent_id] + Commit.new(parent_id).history_ids : [] end data = { time: Time.now, author: options.fetch(:author), message: options.fetch(:message), parents: options.fetch(:parents), index: options.fetch(:index), delta: options.fetch(:delta), base: options[:parents].count == 2 ? options.fetch(:base) : options[:parents].first, history: Blob.write(:history, history) } new Blob.write(:commit, data) end
exists?(id)
click to toggle source
# File lib/eternity/commit.rb, line 137 def self.exists?(id) Blob.read :commit, id true rescue false end
history_cache_key()
click to toggle source
# File lib/eternity/commit.rb, line 144 def self.history_cache_key Eternity.keyspace[:cache][:history] end
new(id)
click to toggle source
# File lib/eternity/commit.rb, line 6 def initialize(id) @id = id end
Public Instance Methods
==(commit)
click to toggle source
# File lib/eternity/commit.rb, line 76 def ==(commit) commit.class == self.class && commit.id == id end
Also aliased as: eql?
base()
click to toggle source
# File lib/eternity/commit.rb, line 45 def base Commit.new data['base'] end
delta()
click to toggle source
# File lib/eternity/commit.rb, line 41 def delta data['delta'] ? Blob.read(:delta, data['delta']) : {} end
fast_forward?(commit)
click to toggle source
# File lib/eternity/commit.rb, line 58 def fast_forward?(commit) return false if nil? return true if commit.nil? history_ids.include? commit.id end
first?()
click to toggle source
# File lib/eternity/commit.rb, line 64 def first? parent_ids.compact.empty? end
hash()
click to toggle source
# File lib/eternity/commit.rb, line 82 def hash id.hash end
history()
click to toggle source
# File lib/eternity/commit.rb, line 54 def history history_ids.map { |id| Commit.new id } end
history_ids()
click to toggle source
# File lib/eternity/commit.rb, line 49 def history_ids return [] if nil? Blob.read :history, data['history'] end
merge?()
click to toggle source
# File lib/eternity/commit.rb, line 68 def merge? parent_ids.count == 2 end
message()
click to toggle source
# File lib/eternity/commit.rb, line 22 def message data['message'] end
nil?()
click to toggle source
# File lib/eternity/commit.rb, line 72 def nil? id.nil? end
parent_ids()
click to toggle source
# File lib/eternity/commit.rb, line 26 def parent_ids data['parents'] || [nil] end
parents()
click to toggle source
# File lib/eternity/commit.rb, line 30 def parents parent_ids.map { |id| Commit.new id } end
short_id()
click to toggle source
# File lib/eternity/commit.rb, line 10 def short_id id ? id[0,7] : nil end
time()
click to toggle source
# File lib/eternity/commit.rb, line 14 def time Time.parse data['time'] if data['time'] end
to_s()
click to toggle source
# File lib/eternity/commit.rb, line 86 def to_s "#{time} - #{short_id} - #{author}: #{message}" end
with_index() { |index| ... }
click to toggle source
# File lib/eternity/commit.rb, line 34 def with_index index = data['index'] ? Index.read_blob(data['index']) : Index.new yield index ensure index.destroy if index end
Private Instance Methods
data()
click to toggle source
# File lib/eternity/commit.rb, line 156 def data @data ||= id ? Blob.read(:commit, id) : {} end