From 1535929b529617192aedeb41ed0373c886bf754e Mon Sep 17 00:00:00 2001 From: Scott Chacon Date: Thu, 29 May 2008 10:29:59 -0700 Subject: [PATCH] bunch of changes --- PURE_TODO | 8 +++++--- lib/grit.rb | 4 +++- lib/grit/git-ruby.rb | 6 +++--- lib/grit/git-ruby/repository.rb | 9 ++++++--- lib/grit/repo.rb | 8 ++++++++ test/bench/benchmarks.rb | 9 +++++++-- test/bench/benchmarks.txt | 30 ++++++++++++++++-------------- test/test_rubygit.rb | 22 ++++++++++++++++++++++ 8 files changed, 70 insertions(+), 26 deletions(-) diff --git a/PURE_TODO b/PURE_TODO index 94cf34f8..5f398835 100644 --- a/PURE_TODO +++ b/PURE_TODO @@ -8,6 +8,11 @@ Completed ** lib/grit/tree.rb:16: output = repo.git.ls_tree({}, treeish, *paths) +lib/grit/commit.rb:74: repo.git.rev_list({}, ref).strip.split("\n").size +lib/grit/commit.rb:92: output = repo.git.rev_list(actual_options, ref) +lib/grit/commit.rb:94: output = repo.git.rev_list(actual_options.merge(:all => true)) + + Next to do =========================== lib/grit/tag.rb:28: output = repo.git.for_each_ref(actual_options, "refs/tags") @@ -19,9 +24,6 @@ lib/grit/config.rb:40: @repo.git.config(:list => true).split(/\n/) May not be fast enough ============================= -lib/grit/commit.rb:74: repo.git.rev_list({}, ref).strip.split("\n").size -lib/grit/commit.rb:92: output = repo.git.rev_list(actual_options, ref) -lib/grit/commit.rb:94: output = repo.git.rev_list(actual_options.merge(:all => true)) lib/grit/blob.rb:58: data = repo.git.blame({:p => true}, commit, '--', file) diff --git a/lib/grit.rb b/lib/grit.rb index 94c40640..62a6be21 100644 --- a/lib/grit.rb +++ b/lib/grit.rb @@ -32,9 +32,11 @@ module Grit class << self attr_accessor :debug + attr_accessor :use_git_ruby end self.debug = false + self.use_git_ruby = true - VERSION = '0.8.1' + VERSION = '0.8.2' end diff --git a/lib/grit/git-ruby.rb b/lib/grit/git-ruby.rb index 3cbeb0d4..9fe36694 100644 --- a/lib/grit/git-ruby.rb +++ b/lib/grit/git-ruby.rb @@ -8,9 +8,9 @@ module Grit module GitRuby class << self - attr_accessor :cache_client + attr_accessor :use_commit_db end - self.cache_client = false + self.use_commit_db = false attr_accessor :ruby_git_repo @@ -69,7 +69,7 @@ def file_type(ref) end def ruby_git - @ruby_git_repo ||= Repository.new(@git_dir, GitRuby.cache_client) + @ruby_git_repo ||= Repository.new(self, @git_dir, GitRuby.use_commit_db) end end diff --git a/lib/grit/git-ruby/repository.rb b/lib/grit/git-ruby/repository.rb index fd84ef05..c35b08c0 100644 --- a/lib/grit/git-ruby/repository.rb +++ b/lib/grit/git-ruby/repository.rb @@ -13,6 +13,7 @@ require 'grit/git-ruby/internal/pack' require 'grit/git-ruby/internal/loose' require 'grit/git-ruby/object' +require 'grit/git-ruby/commit_db' module Grit module GitRuby @@ -21,10 +22,12 @@ class Repository class NoSuchShaFound < StandardError end - attr_accessor :git_dir, :cache + attr_accessor :git_dir, :commit_db - def initialize(git_dir, cache_client = nil) - @cache = cache_client || false + def initialize(git_dir, commit_db = nil) + if use_commit_db + @commit_db = CommitDb.new(git_dir) + end @git_dir = git_dir end diff --git a/lib/grit/repo.rb b/lib/grit/repo.rb index 71df4b3b..71e930d5 100644 --- a/lib/grit/repo.rb +++ b/lib/grit/repo.rb @@ -60,6 +60,14 @@ def head Head.current(self) end + + # Commits current index + # + # Returns true/false if commit worked + def commit_index(message) + self.git.commit({}, a, b, '--', *paths) + end + # An array of Tag objects that are available in this repo # # Returns Grit::Tag[] (baked) diff --git a/test/bench/benchmarks.rb b/test/bench/benchmarks.rb index 590a3e51..52346be2 100644 --- a/test/bench/benchmarks.rb +++ b/test/bench/benchmarks.rb @@ -5,8 +5,8 @@ require 'memcache' require 'pp' -#require 'grit' -require '../../lib/grit' +gem 'grit', '=0.7.0' +#require '../../lib/grit' def main @wbare = File.expand_path(File.join('../../', 'test', 'dot_git')) @@ -15,6 +15,7 @@ def main #result = RubyProf.profile do git = Grit::Repo.new('.') + puts Grit::VERSION #Grit::GitRuby.cache_client = MemCache.new 'localhost:11211', :namespace => 'grit' #Grit.debug = true @@ -44,6 +45,10 @@ def main git.commits('testing').map { |c| c.message } end + run_code(x, 'big revlist') do + c = git.commits('master', 200) + end + run_code(x, 'log') do log = git.log('master') log.size diff --git a/test/bench/benchmarks.txt b/test/bench/benchmarks.txt index f9d9a7b2..2750bb29 100644 --- a/test/bench/benchmarks.txt +++ b/test/bench/benchmarks.txt @@ -1,21 +1,23 @@ Grit : user system total real -packobj 0.030000 0.270000 1.380000 ( 1.507250) -commits 1 0.030000 0.070000 0.390000 ( 0.409931) -commits 2 0.110000 0.170000 0.860000 ( 0.896371) -log 0.350000 0.130000 0.850000 ( 0.875035) -diff 0.190000 0.140000 1.940000 ( 2.031911) -commit-diff 0.540000 0.220000 1.390000 ( 1.463839) -heads 0.010000 0.070000 0.390000 ( 0.413918) +packobj 0.030000 0.260000 1.320000 ( 1.344565) +commits 1 0.030000 0.070000 0.380000 ( 0.366209) +commits 2 0.110000 0.160000 0.830000 ( 0.802311) +big revlist 0.330000 0.130000 0.830000 ( 0.795258) +log 0.380000 0.140000 0.880000 ( 0.856951) +diff 0.330000 0.190000 2.080000 ( 2.072242) +commit-diff 0.690000 0.250000 1.560000 ( 1.521016) +heads 0.000000 0.070000 0.360000 ( 0.376296) Grit (with GitRuby) : user system total real -packobj 0.050000 0.010000 0.060000 ( 0.078318) -commits 1 0.150000 0.010000 0.160000 ( 0.174296) -commits 2 0.440000 0.040000 0.480000 ( 0.522310) -log 0.490000 0.040000 0.530000 ( 0.538128) -diff 0.370000 0.230000 2.250000 ( 2.255974) -commit-diff 0.580000 0.260000 1.500000 ( 1.553000) -heads 0.020000 0.100000 0.430000 ( 0.455464) +packobj 0.050000 0.000000 0.050000 ( 0.051167) +commits 1 0.140000 0.010000 0.150000 ( 0.164900) +commits 2 0.430000 0.030000 0.460000 ( 0.454646) +big revlist 1.540000 0.100000 1.640000 ( 1.637204) +log 0.480000 0.030000 0.510000 ( 0.512445) +diff 0.200000 0.190000 1.970000 ( 1.905014) +commit-diff 0.550000 0.240000 1.420000 ( 1.366508) +heads 0.020000 0.090000 0.410000 ( 0.402519) diff --git a/test/test_rubygit.rb b/test/test_rubygit.rb index 5cf37222..c6506397 100644 --- a/test/test_rubygit.rb +++ b/test/test_rubygit.rb @@ -45,6 +45,28 @@ def test_ls_tree_paths assert_equal out, fixture('ls_tree_paths_ruby').chomp end + + def test_log + end + + def test_rev_list + end + + def test_rev_list_max_count + end + + def test_rev_list_since + end + + def test_rev_list_until + end + + def test_rev_list_range + end + + def test_rev_list_skip + end + def test_file_type out = @git.file_type(@tree_sha).to_s