./lib/dolt/git/repository.rb in dolt-0.1.1 vs ./lib/dolt/git/repository.rb in dolt-0.2.0
- old
+ new
@@ -13,47 +13,49 @@
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#++
-require "dolt/async/when"
-require "dolt/git/blob"
-require "dolt/git/tree"
+require "em_rugged/repository"
+require "em_pessimistic/deferrable_child_process"
+require "em/deferrable"
+require "dolt/git/blame"
+require "dolt/git/commit"
module Dolt
module Git
- class Repository
- attr_reader :name
-
- def initialize(name, git = nil)
- @name = name
- @git = git
- end
-
- def blob(path, ref = "HEAD")
- async_git(git.show(path, ref)) do |data, status|
- Dolt::Git::Blob.new(path, data)
+ class Repository < EMRugged::Repository
+ def blame(ref, path)
+ deferred_method("blame -l -t -p #{ref} #{path}") do |output, s|
+ Dolt::Git::Blame.parse_porcelain(output)
end
end
- def tree(path, ref = "HEAD")
- async_git(git.ls_tree(path, ref)) do |data, status|
- Dolt::Git::Tree.parse(path, data)
+ def log(ref, path, limit)
+ deferred_method("log -n #{limit} #{ref} #{path}") do |out, s|
+ Dolt::Git::Commit.parse_log(out)
end
end
private
- def git; @git; end
+ def deferred_method(cmd, &block)
+ d = EventMachine::DefaultDeferrable.new
+ cmd = git(cmd)
+ p = EMPessimistic::DeferrableChildProcess.open(cmd)
- def async_git(gitop, &block)
- deferred = When::Deferred.new
+ p.callback do |output, status|
+ d.succeed(block.call(output, status))
+ end
- gitop.callback do |data, status|
- deferred.resolve(block.call(data, status))
+ p.errback do |err|
+ d.fail(err)
end
- gitop.errback { |err| deferred.reject(err) }
- deferred.promise
+ d
+ end
+
+ def git(cmd)
+ "git --git-dir #{subject.path} #{cmd}"
end
end
end
end