./lib/dolt/git/repository.rb in dolt-0.3.1 vs ./lib/dolt/git/repository.rb in dolt-0.4.0
- old
+ new
@@ -18,10 +18,11 @@
require "em_rugged/repository"
require "em_pessimistic/deferrable_child_process"
require "em/deferrable"
require "dolt/git/blame"
require "dolt/git/commit"
+require "dolt/async/when"
module Dolt
module Git
class Repository < EMRugged::Repository
def blame(ref, path)
@@ -29,26 +30,60 @@
Dolt::Git::Blame.parse_porcelain(output)
end
end
def log(ref, path, limit)
- deferred_method("log -n #{limit} #{ref} #{path}") do |out, s|
- Dolt::Git::Commit.parse_log(out)
+ entry_history(ref, path, limit)
+ end
+
+ def tree_history(ref, path, limit = 1)
+ d = EventMachine::DefaultDeferrable.new
+ rp = rev_parse("#{ref}:#{path}")
+ rp.errback { |err| d.fail(err) }
+ rp.callback do |tree|
+ if tree.class != Rugged::Tree
+ message = "#{ref}:#{path} is not a tree (#{tree.class.to_s})"
+ break d.fail(Exception.new(message))
+ end
+
+ building = build_history(path || "./", ref, tree, limit)
+ building.callback { |history| d.succeed(history) }
+ building.errback { |err| d.fail(err) }
end
+ d
end
private
+ def entry_history(ref, entry, limit)
+ deferred_method("log -n #{limit} #{ref} #{entry}") do |out, s|
+ Dolt::Git::Commit.parse_log(out)
+ end
+ end
+
+ def build_history(path, ref, entries, limit)
+ d = EventMachine::DefaultDeferrable.new
+ resolve = lambda { |p| path == "" ? p : File.join(path, p) }
+ progress = When.all(entries.map do |e|
+ entry_history(ref, resolve.call(e[:name]), limit)
+ end)
+ progress.errback { |e| d.fail(e) }
+ progress.callback do |history|
+ d.succeed(entries.map { |e| e.merge({ :history => history.shift }) })
+ end
+ d
+ end
+
def deferred_method(cmd, &block)
d = EventMachine::DefaultDeferrable.new
cmd = git(cmd)
p = EMPessimistic::DeferrableChildProcess.open(cmd)
p.callback do |output, status|
d.succeed(block.call(output, status))
end
- p.errback do |err|
- d.fail(err)
+ p.errback do |stderr, status|
+ d.fail(stderr)
end
d
end