Skip to content

Commit b0d47b3

Browse files
author
scott Chacon
committed
significantly improved log performance
1 parent ba0f3cc commit b0d47b3

File tree

7 files changed

+28
-28
lines changed

7 files changed

+28
-28
lines changed

benchmark.rb

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
require 'fileutils'
22
require 'benchmark'
33
require 'rubygems'
4-
#require 'ruby-prof'
5-
#require_gem 'git', '1.0.2'
6-
require 'lib/git'
4+
require 'ruby-prof'
5+
require_gem 'git', '1.0.3'
6+
#require 'lib/git'
77

88
def main
99
@wbare = File.expand_path(File.join('tests', 'files', 'working.git'))
@@ -12,8 +12,9 @@ def main
1212
g = Git.clone(@wbare, 'test')
1313
g.chdir do
1414

15-
n = 30
16-
#result = RubyProf.profile do
15+
n = 40
16+
result = RubyProf.profile do
17+
puts "<pre>"
1718

1819
Benchmark.bm(8) do |x|
1920
run_code(x, 'objects') do
@@ -94,22 +95,27 @@ def main
9495
g.write_tree
9596
end
9697
end
97-
end
98+
end rescue nil
9899

99100
x.report('archive ') do
100101
n.times do
101102
f = g.gcommit('v2.6').archive # returns path to temp file
102103
end
103104
end rescue nil
104-
105+
106+
105107
end
106108

107-
#end
109+
end
108110

109111
# Print a graph profile to text
110-
#printer = RubyProf::FlatPrinter.new(result)
111-
#printer.print(STDOUT, 0)
112-
112+
puts "</pre>"
113+
printer = RubyProf::GraphHtmlPrinter.new(result)
114+
printer.print(STDOUT, 1)
115+
printer = RubyProf::FlatPrinter.new(result)
116+
puts "<pre>"
117+
printer.print(STDOUT, 1)
118+
puts "</pre>"
113119
end
114120
end
115121
end
@@ -148,4 +154,4 @@ def in_temp_dir(remove_after = true)
148154
FileUtils.rm_r(tmp_path) if remove_after
149155
end
150156

151-
main()
157+
main()

lib/git/lib.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def log_commits(opts = {})
6262
arr_opts = ['--pretty=oneline']
6363
arr_opts << "-#{opts[:count]}" if opts[:count]
6464
arr_opts << "--since=\"#{opts[:since]}\"" if opts[:since].is_a? String
65-
arr_opts << "#{opts[:between][0]}..#{opts[:between][1].to_s}" if (opts[:between] && opts[:between].size == 2)
65+
arr_opts << "#{opts[:between][0].to_s}..#{opts[:between][1].to_s}" if (opts[:between] && opts[:between].size == 2)
6666
arr_opts << opts[:object] if opts[:object].is_a? String
6767
arr_opts << '-- ' + opts[:path_limiter] if opts[:path_limiter].is_a? String
6868

lib/git/log.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ def since(date)
4141

4242
def between(sha1, sha2 = nil)
4343
dirty_log
44-
@between = [@base.lib.revparse(sha1), @base.lib.revparse(sha2)]
44+
@between = [sha1, sha2]
4545
return self
4646
end
4747

4848
def to_s
49-
self.map { |c| c.sha }.join("\n")
49+
self.map { |c| c.to_s }.join("\n")
5050
end
5151

5252

lib/git/object.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def setup
4242
end
4343

4444
def to_s
45-
sha
45+
@objectish
4646
end
4747

4848
def grep(string, path_limiter = nil, opts = {})

tests/units/test_lib.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ def test_log_commits
4242
a = @lib.log_commits :count => 20, :between => ['v2.5', 'v2.6']
4343
assert_equal(2, a.size)
4444

45-
a = @lib.log_commits :count => 20, :object => 'example.txt'
46-
assert_equal(20, a.size)
47-
48-
a = @lib.log_commits :count => 20, :object => 'ex_dir/ex.txt'
45+
a = @lib.log_commits :count => 20, :path_limiter => 'ex_dir/'
4946
assert_equal(1, a.size)
5047
end
5148

tests/units/test_log.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,10 @@ def test_get_log_since
3232
end
3333

3434
def test_get_log_since_file
35-
l = @git.log.object('example.txt')
35+
l = @git.log.path('example.txt')
3636
assert_equal(30, l.size)
37-
38-
l = @git.log.between('v2.5').object('example.txt')
39-
assert_equal(3, l.size)
4037

41-
l = @git.log.between('v2.5', 'test').object('example.txt')
38+
l = @git.log.between('v2.5', 'test').path('example.txt')
4239
assert_equal(1, l.size)
4340
end
4441

tests/units/test_object.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ def test_commit_contents
5050
end
5151

5252
def test_object_to_s
53-
assert_equal('1cc8667014381e2788a94777532a788307f38d26', @commit.to_s)
54-
assert_equal('94c827875e2cadb8bc8d4cdd900f19aa9e8634c7', @tree.to_s)
55-
assert_equal('ba492c62b6227d7f3507b4dcc6e6d5f13790eabf', @blob.to_s)
53+
assert_equal('1cc8667014381e2788a94777532a788307f38d26', @commit.sha)
54+
assert_equal('94c827875e2cadb8bc8d4cdd900f19aa9e8634c7', @tree.sha)
55+
assert_equal('ba492c62b6227d7f3507b4dcc6e6d5f13790eabf', @blob.sha)
5656
end
5757

5858
def test_object_size

0 commit comments

Comments
 (0)