lib/eternity/repository.rb in eternity-0.0.4 vs lib/eternity/repository.rb in eternity-0.0.5

- old
+ new

@@ -1,10 +1,8 @@ module Eternity class Repository - extend Log - attr_reader :name, :id, :branches def initialize(name, options={}) @name = name.to_s @id = Eternity.keyspace[:repository][@name] @@ -75,10 +73,12 @@ def checkout(options) raise "Can't checkout with uncommitted changes" if changes? locker.lock! :checkout do + Eternity.logger.info(self.class) { "Checkout #{name} (#{options.map { |k,v| "#{k}: #{v}" }.join(', ')})" } + original_commit = current_commit commit_id, branch = extract_commit_and_branch options if commit_id @@ -111,19 +111,24 @@ push! end def push! raise "Can't push without commit" unless current_commit? + + Eternity.logger.info(self.class) { "Push #{name} (#{current_commit.id})" } + Branch[current_branch] = current_commit.id end def pull raise "Can't pull with uncommitted changes" if changes? raise "Branch not found: #{current_branch}" unless Branch.exists? current_branch target_commit = Branch[current_branch] + Eternity.logger.info(self.class) { "Pull #{name} (#{target_commit.id})" } + if current_commit == target_commit || current_commit.fast_forward?(target_commit) {} elsif target_commit.fast_forward?(current_commit) checkout commit: target_commit.id else @@ -131,10 +136,12 @@ end end def revert locker.lock! :revert do + Eternity.logger.info(self.class) { "Revert #{name}" } + current_commit.with_index do |index| Delta.revert(delta, index).tap { tracker.revert } end end end @@ -162,17 +169,17 @@ current.merge! dump['current'] branches.merge! dump['branches'] self.delta = dump['delta'] end - [:delta, :delta=, :commit, :pull, :push, :checkout, :merge, :revert, :destroy, :dump].each { |m| log m } - private attr_reader :tracker, :current, :locker def commit!(options) + Eternity.logger.info(self.class) { "Commit #{name} (author: #{options[:author]}, message: #{options[:message]})" } + changes = delta options[:parents] ||= [current_commit.id] options[:delta] ||= write_delta changes options[:index] ||= write_index changes @@ -184,9 +191,11 @@ end end def merge!(target_commit) locker.lock! :merge do + Eternity.logger.info(self.class) { "Merge #{name} (#{target_commit.short_id} into #{current_commit.short_id})" } + patch = Patch.merge current_commit, target_commit raise 'Already merged' if patch.merged? commit! message: "Merge #{target_commit.short_id} into #{current_commit.short_id} (#{name})", \ No newline at end of file