5 require_gem 'git', '1.0.3'
9 @wbare = File.expand_path(File.join('tests', 'files', 'working.git'))
12 g = Git.clone(@wbare, 'test')
16 result = RubyProf.profile do
19 Benchmark.bm(8) do |x|
20 run_code(x, 'objects') do
21 @commit = g.gcommit('1cc8667014381')
22 @tree = g.gtree('1cc8667014381^{tree}')
23 @blob = g.gblob('v2.5:example.txt')
24 @obj = g.object('v2.5:example.txt')
28 x.report('config ') do
31 c = g.config('user.email')
32 c = g.config('user.email', 'schacon@gmail.com')
38 g.diff('gitsearch1', 'v2.5').lines
39 g.diff('gitsearch1', 'v2.5').stats
40 g.diff('gitsearch1', 'v2.5').patch
53 x.report('status ') do
55 g.status['example.txt'].mode_index
65 log = g.log.between('v2.5').object('example.txt')
69 g.log.between('v2.5').object('example.txt').size
70 g.log.since("2 years ago").size
75 x.report('branch ') do
78 g.branch('new_branch' + i.to_s).in_branch('test') do
80 new_file('new_file_' + i.to_s, 'hello')
84 g.branch('new_branch').merge('new_branch' + i.to_s)
85 g.checkout('new_branch')
92 tr = g.with_temp_index do
93 g.read_tree('new_branch' + i.to_s)
100 x.report('archive ') do
102 f = g.gcommit('v2.6').archive # returns path to temp file
111 # Print a graph profile to text
113 printer = RubyProf::GraphHtmlPrinter.new(result)
114 printer.print(STDOUT, 1)
115 printer = RubyProf::FlatPrinter.new(result)
117 printer.print(STDOUT, 1)
124 def run_code(x, name, times = 30)
125 #result = RubyProf.profile do
135 # Print a graph profile to text
136 #printer = RubyProf::FlatPrinter.new(result)
137 #printer.print(STDOUT, 0)
140 def new_file(name, contents)
141 File.open(name, 'w') do |f|
147 def in_temp_dir(remove_after = true)
148 filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
149 tmp_path = File.join("/tmp/", filename)
150 FileUtils.mkdir(tmp_path)
151 Dir.chdir tmp_path do
154 FileUtils.rm_r(tmp_path) if remove_after