grit 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grit might be problematic. Click here for more details.
- data/History.txt +9 -0
- data/README.md +37 -11
- data/VERSION.yml +3 -3
- data/examples/ex_add_commit.rb +13 -0
- data/examples/ex_index.rb +14 -0
- data/lib/grit.rb +10 -3
- data/lib/grit/actor.rb +5 -5
- data/lib/grit/blob.rb +12 -12
- data/lib/grit/commit.rb +3 -3
- data/lib/grit/commit_stats.rb +26 -26
- data/lib/grit/config.rb +9 -9
- data/lib/grit/diff.rb +16 -16
- data/lib/grit/errors.rb +1 -1
- data/lib/grit/git-ruby.rb +108 -27
- data/lib/grit/git-ruby/commit_db.rb +11 -11
- data/lib/grit/git-ruby/file_index.rb +28 -28
- data/lib/grit/git-ruby/git_object.rb +14 -14
- data/lib/grit/git-ruby/internal/file_window.rb +4 -4
- data/lib/grit/git-ruby/internal/loose.rb +10 -10
- data/lib/grit/git-ruby/internal/pack.rb +29 -29
- data/lib/grit/git-ruby/internal/raw_object.rb +4 -4
- data/lib/grit/git-ruby/object.rb +9 -9
- data/lib/grit/git-ruby/repository.rb +111 -107
- data/lib/grit/git.rb +191 -14
- data/lib/grit/index.rb +21 -21
- data/lib/grit/lazy.rb +1 -1
- data/lib/grit/merge.rb +9 -9
- data/lib/grit/ref.rb +6 -31
- data/lib/grit/repo.rb +110 -65
- data/lib/grit/ruby1.9.rb +1 -1
- data/lib/grit/status.rb +24 -24
- data/lib/grit/submodule.rb +15 -15
- data/lib/grit/tag.rb +7 -57
- data/lib/grit/tree.rb +12 -12
- data/test/bench/benchmarks.rb +126 -0
- data/test/helper.rb +18 -0
- data/test/profile.rb +21 -0
- data/test/suite.rb +6 -0
- data/test/test_actor.rb +35 -0
- data/test/test_blame.rb +32 -0
- data/test/test_blame_tree.rb +33 -0
- data/test/test_blob.rb +83 -0
- data/test/test_commit.rb +207 -0
- data/test/test_commit_stats.rb +33 -0
- data/test/test_commit_write.rb +20 -0
- data/test/test_config.rb +58 -0
- data/test/test_diff.rb +18 -0
- data/test/test_file_index.rb +56 -0
- data/test/test_git.rb +105 -0
- data/test/test_grit.rb +32 -0
- data/test/test_head.rb +47 -0
- data/test/test_index_status.rb +40 -0
- data/test/test_merge.rb +17 -0
- data/test/test_raw.rb +16 -0
- data/test/test_real.rb +19 -0
- data/test/test_reality.rb +17 -0
- data/test/test_remote.rb +14 -0
- data/test/test_repo.rb +349 -0
- data/test/test_rubygit.rb +192 -0
- data/test/test_rubygit_alt.rb +40 -0
- data/test/test_rubygit_index.rb +76 -0
- data/test/test_rubygit_iv2.rb +28 -0
- data/test/test_submodule.rb +69 -0
- data/test/test_tag.rb +67 -0
- data/test/test_tree.rb +101 -0
- metadata +43 -13
data/lib/grit/config.rb
CHANGED
@@ -1,32 +1,32 @@
|
|
1
1
|
module Grit
|
2
|
-
|
2
|
+
|
3
3
|
class Config
|
4
4
|
def initialize(repo)
|
5
5
|
@repo = repo
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def []=(key, value)
|
9
9
|
@repo.git.config({}, key, value)
|
10
10
|
@data = nil
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def [](key)
|
14
14
|
data[key]
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def fetch(key, default = nil)
|
18
18
|
data[key] || default || raise(IndexError.new("key not found"))
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def keys
|
22
22
|
data.keys
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
protected
|
26
26
|
def data
|
27
27
|
@data ||= load_config
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def load_config
|
31
31
|
hash = {}
|
32
32
|
config_lines.map do |line|
|
@@ -35,10 +35,10 @@ module Grit
|
|
35
35
|
end
|
36
36
|
hash
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def config_lines
|
40
40
|
@repo.git.config(:list => true).split(/\n/)
|
41
41
|
end
|
42
42
|
end # Config
|
43
|
-
|
43
|
+
|
44
44
|
end # Grit
|
data/lib/grit/diff.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Grit
|
2
|
-
|
2
|
+
|
3
3
|
class Diff
|
4
4
|
attr_reader :a_path, :b_path
|
5
5
|
attr_reader :a_blob, :b_blob
|
6
6
|
attr_reader :a_mode, :b_mode
|
7
7
|
attr_reader :new_file, :deleted_file
|
8
8
|
attr_reader :diff
|
9
|
-
|
9
|
+
|
10
10
|
def initialize(repo, a_path, b_path, a_blob, b_blob, a_mode, b_mode, new_file, deleted_file, diff)
|
11
11
|
@repo = repo
|
12
12
|
@a_path = a_path
|
@@ -15,32 +15,32 @@ module Grit
|
|
15
15
|
@b_blob = b_blob =~ /^0{40}$/ ? nil : Blob.create(repo, :id => b_blob)
|
16
16
|
@a_mode = a_mode
|
17
17
|
@b_mode = b_mode
|
18
|
-
@new_file = new_file
|
19
|
-
@deleted_file = deleted_file
|
18
|
+
@new_file = new_file || @a_blob.nil?
|
19
|
+
@deleted_file = deleted_file || @b_blob.nil?
|
20
20
|
@diff = diff
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def self.list_from_string(repo, text)
|
24
24
|
lines = text.split("\n")
|
25
|
-
|
25
|
+
|
26
26
|
diffs = []
|
27
|
-
|
27
|
+
|
28
28
|
while !lines.empty?
|
29
29
|
m, a_path, b_path = *lines.shift.match(%r{^diff --git a/(.+?) b/(.+)$})
|
30
|
-
|
30
|
+
|
31
31
|
if lines.first =~ /^old mode/
|
32
32
|
m, a_mode = *lines.shift.match(/^old mode (\d+)/)
|
33
33
|
m, b_mode = *lines.shift.match(/^new mode (\d+)/)
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
if lines.empty? || lines.first =~ /^diff --git/
|
37
37
|
diffs << Diff.new(repo, a_path, b_path, nil, nil, a_mode, b_mode, false, false, nil)
|
38
38
|
next
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
new_file = false
|
42
42
|
deleted_file = false
|
43
|
-
|
43
|
+
|
44
44
|
if lines.first =~ /^new file/
|
45
45
|
m, b_mode = lines.shift.match(/^new file mode (.+)$/)
|
46
46
|
a_mode = nil
|
@@ -50,21 +50,21 @@ module Grit
|
|
50
50
|
b_mode = nil
|
51
51
|
deleted_file = true
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
m, a_blob, b_blob, b_mode = *lines.shift.match(%r{^index ([0-9A-Fa-f]+)\.\.([0-9A-Fa-f]+) ?(.+)?$})
|
55
55
|
b_mode.strip! if b_mode
|
56
|
-
|
56
|
+
|
57
57
|
diff_lines = []
|
58
58
|
while lines.first && lines.first !~ /^diff/
|
59
59
|
diff_lines << lines.shift
|
60
60
|
end
|
61
61
|
diff = diff_lines.join("\n")
|
62
|
-
|
62
|
+
|
63
63
|
diffs << Diff.new(repo, a_path, b_path, a_blob, b_blob, a_mode, b_mode, new_file, deleted_file, diff)
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
diffs
|
67
67
|
end
|
68
68
|
end # Diff
|
69
|
-
|
69
|
+
|
70
70
|
end # Grit
|
data/lib/grit/errors.rb
CHANGED
data/lib/grit/git-ruby.rb
CHANGED
@@ -2,22 +2,22 @@ require 'grit/git-ruby/repository'
|
|
2
2
|
require 'grit/git-ruby/file_index'
|
3
3
|
|
4
4
|
module Grit
|
5
|
-
|
5
|
+
|
6
6
|
# the functions in this module intercept the calls to git binary
|
7
7
|
# made buy the grit objects and attempts to run them in pure ruby
|
8
8
|
# if it will be faster, or if the git binary is not available (!!TODO!!)
|
9
9
|
module GitRuby
|
10
|
-
|
10
|
+
|
11
11
|
attr_accessor :ruby_git_repo, :git_file_index
|
12
|
-
|
12
|
+
|
13
13
|
def init(options)
|
14
14
|
if options.size == 0
|
15
15
|
Grit::GitRuby::Repository.init(@git_dir)
|
16
16
|
else
|
17
|
-
method_missing('init', options)
|
17
|
+
method_missing('init', options)
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def cat_file(options, ref)
|
22
22
|
if options[:t]
|
23
23
|
file_type(ref)
|
@@ -29,7 +29,7 @@ module Grit
|
|
29
29
|
rescue Grit::GitRuby::Repository::NoSuchShaFound
|
30
30
|
''
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
# lib/grit/tree.rb:16: output = repo.git.ls_tree({}, treeish, *paths)
|
34
34
|
def ls_tree(options, treeish, *paths)
|
35
35
|
sha = rev_parse({}, treeish)
|
@@ -42,7 +42,7 @@ module Grit
|
|
42
42
|
def diff(options, sha1, sha2)
|
43
43
|
try_run { ruby_git.diff(sha1, sha2, options) }
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def rev_list(options, ref = 'master')
|
47
47
|
options.delete(:skip) if options[:skip].to_i == 0
|
48
48
|
allowed_options = [:max_count, :since, :until, :pretty] # this is all I can do right now
|
@@ -53,18 +53,18 @@ module Grit
|
|
53
53
|
begin
|
54
54
|
return file_index.commits_from(rev_parse({}, ref)).join("\n") + "\n"
|
55
55
|
rescue
|
56
|
-
return method_missing('rev-list', options, ref)
|
56
|
+
return method_missing('rev-list', options, ref)
|
57
57
|
end
|
58
58
|
else
|
59
59
|
aref = rev_parse({}, ref)
|
60
60
|
if aref.is_a? Array
|
61
|
-
return method_missing('rev-list', options, ref)
|
61
|
+
return method_missing('rev-list', options, ref)
|
62
62
|
else
|
63
63
|
return try_run { ruby_git.rev_list(aref, options) }
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
def rev_parse(options, string)
|
69
69
|
raise RuntimeError, "invalid string: #{string}" unless string.is_a?(String)
|
70
70
|
|
@@ -82,11 +82,11 @@ module Grit
|
|
82
82
|
|
83
83
|
head = File.join(@git_dir, 'refs', 'remotes', string)
|
84
84
|
return File.read(head).chomp if File.file?(head)
|
85
|
-
|
85
|
+
|
86
86
|
head = File.join(@git_dir, 'refs', 'tags', string)
|
87
87
|
return File.read(head).chomp if File.file?(head)
|
88
|
-
|
89
|
-
## check packed-refs file, too
|
88
|
+
|
89
|
+
## check packed-refs file, too
|
90
90
|
packref = File.join(@git_dir, 'packed-refs')
|
91
91
|
if File.file?(packref)
|
92
92
|
File.readlines(packref).each do |line|
|
@@ -96,21 +96,102 @@ module Grit
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
## !! more - partials and such !!
|
101
|
-
|
101
|
+
|
102
102
|
# revert to calling git - grr
|
103
103
|
return method_missing('rev-parse', {}, string).chomp
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
|
+
def refs(options, prefix)
|
107
|
+
refs = []
|
108
|
+
already = {}
|
109
|
+
Dir.chdir(@git_dir) do
|
110
|
+
files = Dir.glob(prefix + '/**/*')
|
111
|
+
files.each do |ref|
|
112
|
+
next if !File.file?(ref)
|
113
|
+
id = File.read(ref).chomp
|
114
|
+
name = ref.sub("#{prefix}/", '')
|
115
|
+
if !already[name]
|
116
|
+
refs << "#{name} #{id}"
|
117
|
+
already[name] = true
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
if File.file?('packed-refs')
|
122
|
+
File.readlines('packed-refs').each do |line|
|
123
|
+
if m = /^(\w{40}) (.*?)$/.match(line)
|
124
|
+
next if !Regexp.new('^' + prefix).match(m[2])
|
125
|
+
name = m[2].sub("#{prefix}/", '')
|
126
|
+
if !already[name]
|
127
|
+
refs << "#{name} #{m[1]}"
|
128
|
+
already[name] = true
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
refs.join("\n")
|
136
|
+
end
|
137
|
+
|
138
|
+
def tags(options, prefix)
|
139
|
+
refs = []
|
140
|
+
already = {}
|
141
|
+
|
142
|
+
Dir.chdir(repo.path) do
|
143
|
+
files = Dir.glob(prefix + '/**/*')
|
144
|
+
|
145
|
+
files.each do |ref|
|
146
|
+
next if !File.file?(ref)
|
147
|
+
|
148
|
+
id = File.read(ref).chomp
|
149
|
+
name = ref.sub("#{prefix}/", '')
|
150
|
+
|
151
|
+
if !already[name]
|
152
|
+
refs << "#{name} #{id}"
|
153
|
+
already[name] = true
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
if File.file?('packed-refs')
|
158
|
+
lines = File.readlines('packed-refs')
|
159
|
+
lines.each_with_index do |line, i|
|
160
|
+
if m = /^(\w{40}) (.*?)$/.match(line)
|
161
|
+
next if !Regexp.new('^' + prefix).match(m[2])
|
162
|
+
name = m[2].sub("#{prefix}/", '')
|
163
|
+
|
164
|
+
# Annotated tags in packed-refs include a reference
|
165
|
+
# to the commit object on the following line.
|
166
|
+
next_line = lines[i + 1]
|
167
|
+
|
168
|
+
id =
|
169
|
+
if next_line && next_line[0] == ?^
|
170
|
+
next_line[1..-1].chomp
|
171
|
+
else
|
172
|
+
m[1]
|
173
|
+
end
|
174
|
+
|
175
|
+
if !already[name]
|
176
|
+
refs << "#{name} #{id}"
|
177
|
+
already[name] = true
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
refs.join("\n")
|
185
|
+
end
|
186
|
+
|
106
187
|
def file_size(ref)
|
107
188
|
try_run { ruby_git.cat_file_size(ref).to_s }
|
108
189
|
end
|
109
|
-
|
190
|
+
|
110
191
|
def file_type(ref)
|
111
192
|
try_run { ruby_git.cat_file_type(ref).to_s }
|
112
193
|
end
|
113
|
-
|
194
|
+
|
114
195
|
def blame_tree(commit, path = nil)
|
115
196
|
begin
|
116
197
|
path = [path].join('/').to_s + '/' if (path && path != '')
|
@@ -121,17 +202,17 @@ module Grit
|
|
121
202
|
{}
|
122
203
|
end
|
123
204
|
end
|
124
|
-
|
205
|
+
|
125
206
|
def file_index
|
126
207
|
@git_file_index ||= FileIndex.new(@git_dir)
|
127
208
|
end
|
128
|
-
|
209
|
+
|
129
210
|
def ruby_git
|
130
211
|
@ruby_git_repo ||= Repository.new(@git_dir)
|
131
212
|
end
|
132
|
-
|
213
|
+
|
133
214
|
private
|
134
|
-
|
215
|
+
|
135
216
|
def try_run
|
136
217
|
ret = ''
|
137
218
|
Timeout.timeout(self.class.git_timeout) do
|
@@ -142,7 +223,7 @@ module Grit
|
|
142
223
|
#if @bytes_read > 5242880 # 5.megabytes
|
143
224
|
# bytes = @bytes_read
|
144
225
|
# @bytes_read = 0
|
145
|
-
# raise Grit::Git::GitTimeout.new(command, bytes)
|
226
|
+
# raise Grit::Git::GitTimeout.new(command, bytes)
|
146
227
|
#end
|
147
228
|
|
148
229
|
ret
|
@@ -151,7 +232,7 @@ module Grit
|
|
151
232
|
@bytes_read = 0
|
152
233
|
raise Grit::Git::GitTimeout.new(command, bytes)
|
153
234
|
end
|
154
|
-
|
235
|
+
|
155
236
|
def looking_for(commit, path = nil)
|
156
237
|
tree_sha = ruby_git.get_subtree(rev_parse({}, commit), path)
|
157
238
|
|
@@ -167,7 +248,7 @@ module Grit
|
|
167
248
|
end
|
168
249
|
looking_for
|
169
250
|
end
|
170
|
-
|
251
|
+
|
171
252
|
def clean_paths(commit_array)
|
172
253
|
new_commits = {}
|
173
254
|
commit_array.each do |file, sha|
|
@@ -177,10 +258,10 @@ module Grit
|
|
177
258
|
new_commits
|
178
259
|
end
|
179
260
|
|
180
|
-
# TODO
|
261
|
+
# TODO
|
181
262
|
# git grep -n 'foo' 'master'
|
182
263
|
# git log --pretty='raw' --max-count='1' 'master' -- 'LICENSE'
|
183
264
|
# git log --pretty='raw' --max-count='1' 'master' -- 'test'
|
184
|
-
|
265
|
+
|
185
266
|
end
|
186
267
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
begin
|
2
2
|
require 'sequel'
|
3
|
-
|
3
|
+
|
4
4
|
module Grit
|
5
|
-
|
5
|
+
|
6
6
|
class CommitDb
|
7
|
-
|
7
|
+
|
8
8
|
SCHEMA_VERSION = 1
|
9
9
|
|
10
10
|
attr_accessor :db, :git
|
11
|
-
|
11
|
+
|
12
12
|
def initialize(git_obj, index_location = nil)
|
13
13
|
@git = git_obj
|
14
14
|
db_file = File.join(index_location || @git.git_dir, 'commit_db')
|
@@ -19,10 +19,10 @@ begin
|
|
19
19
|
@db = Sequel.open "sqlite:///#{db_file}"
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def rev_list(branch, options)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def update_db(branch = nil)
|
27
27
|
# find all refs/heads, for each
|
28
28
|
# add branch if not there
|
@@ -35,18 +35,18 @@ begin
|
|
35
35
|
def setup_tables
|
36
36
|
@db << "create table meta (meta_key text, meta_value text)"
|
37
37
|
@db[:meta] << {:meta_key => 'schema', :meta_value => SCHEMA_VERSION}
|
38
|
-
|
38
|
+
|
39
39
|
@db << "create table commits (id integer, sha text, author_date integer)"
|
40
40
|
@db << "create table nodes (id integer, path text, type text)"
|
41
41
|
@db << "create table branches (id integer, ref text, commit_id integer)"
|
42
|
-
|
42
|
+
|
43
43
|
@db << "create table commit_branches (commit_id integer, branch_id integer)"
|
44
|
-
@db << "create table commit_nodes (commit_id integer, node_id integer, node_sha string)"
|
44
|
+
@db << "create table commit_nodes (commit_id integer, node_id integer, node_sha string)"
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
rescue LoadError
|
51
51
|
# no commit db
|
52
52
|
end
|
@@ -15,21 +15,21 @@ module Grit
|
|
15
15
|
module GitRuby
|
16
16
|
|
17
17
|
class FileIndex
|
18
|
-
|
18
|
+
|
19
19
|
class IndexFileNotFound < StandardError
|
20
20
|
end
|
21
21
|
|
22
22
|
class UnsupportedRef < StandardError
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
class << self
|
26
26
|
attr_accessor :max_file_size
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
self.max_file_size = 10_000_000 # ~10M
|
30
|
-
|
30
|
+
|
31
31
|
attr_reader :files
|
32
|
-
|
32
|
+
|
33
33
|
# initializes index given repo_path
|
34
34
|
def initialize(repo_path)
|
35
35
|
@index_file = File.join(repo_path, 'file-index')
|
@@ -39,30 +39,30 @@ module Grit
|
|
39
39
|
raise IndexFileNotFound
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
# returns count of all commits
|
44
44
|
def count_all
|
45
45
|
@sha_count
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
# returns count of all commits reachable from SHA
|
49
|
-
# note: originally did this recursively, but ruby gets pissed about that on
|
49
|
+
# note: originally did this recursively, but ruby gets pissed about that on
|
50
50
|
# really big repos where the stack level gets 'too deep' (thats what she said)
|
51
51
|
def count(commit_sha)
|
52
52
|
commits_from(commit_sha).size
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
# builds a list of all commits reachable from a single commit
|
56
56
|
def commits_from(commit_sha)
|
57
57
|
raise UnsupportedRef if commit_sha.is_a? Array
|
58
|
-
|
58
|
+
|
59
59
|
already = {}
|
60
60
|
final = []
|
61
61
|
left_to_do = [commit_sha]
|
62
|
-
|
62
|
+
|
63
63
|
while commit_sha = left_to_do.shift
|
64
64
|
next if already[commit_sha]
|
65
|
-
|
65
|
+
|
66
66
|
final << commit_sha
|
67
67
|
already[commit_sha] = true
|
68
68
|
|
@@ -74,34 +74,34 @@ module Grit
|
|
74
74
|
|
75
75
|
sort_commits(final)
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
def sort_commits(sha_array)
|
79
79
|
sha_array.sort { |a, b| @commit_order[b].to_i <=> @commit_order[a].to_i }
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
# returns files changed at commit sha
|
83
83
|
def files(commit_sha)
|
84
84
|
@commit_index[commit_sha][:files] rescue nil
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
# returns all commits for a file
|
88
88
|
def commits_for(file)
|
89
89
|
@all_files[file]
|
90
90
|
end
|
91
|
-
|
92
|
-
# returns the shas of the last commits for all
|
91
|
+
|
92
|
+
# returns the shas of the last commits for all
|
93
93
|
# the files in [] from commit_sha
|
94
94
|
# files_matcher can be a regexp or an array
|
95
95
|
def last_commits(commit_sha, files_matcher)
|
96
96
|
acceptable = commits_from(commit_sha)
|
97
|
-
|
97
|
+
|
98
98
|
matches = {}
|
99
|
-
|
99
|
+
|
100
100
|
if files_matcher.is_a? Regexp
|
101
101
|
files = @all_files.keys.select { |file| file =~ files_matcher }
|
102
102
|
files_matcher = files
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
if files_matcher.is_a? Array
|
106
106
|
# find the last commit for each file in the array
|
107
107
|
files_matcher.each do |f|
|
@@ -113,10 +113,10 @@ module Grit
|
|
113
113
|
end if @all_files[f]
|
114
114
|
end
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
matches
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
private
|
121
121
|
|
122
122
|
# read and parse the file-index data
|
@@ -151,7 +151,7 @@ module Grit
|
|
151
151
|
end
|
152
152
|
|
153
153
|
end
|
154
|
-
|
154
|
+
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
@@ -159,7 +159,7 @@ end
|
|
159
159
|
# benchmark testing on big-ass repos
|
160
160
|
|
161
161
|
if __FILE__ == $0
|
162
|
-
|
162
|
+
|
163
163
|
#repo = '/Users/schacon/projects/git/.git'
|
164
164
|
#commit = 'd8933f013a66cc1deadf83a9c24eccb6fee78a35'
|
165
165
|
#file_list = ["builtin-merge-recursive.c", "git-send-email-script", "git-parse-remote.sh", "builtin-add.c", "merge-base.c", "read-cache.c", "fsck.h", "diff.c", "refs.c", "diffcore-rename.c", "epoch.c", "pack-intersect.c", "fast-import.c", "git-applypatch.sh", "git.spec.in", "rpush.c", "git-clone-script", "utf8.c", "git-external-diff-script", "builtin-init-db.c", "pack-redundant.c", "builtin-diff-index.c", "index.c", "update-index.c", "fetch-clone.c", "pager.c", "diff.h", "unpack-trees.c", "git-browse-help.sh", "git-rename-script", "refs.h", "get-tar-commit-id.c", "git-push.sh", "README", "delta.c", "mailsplit.c", "gitweb.cgi", "var.c", "epoch.h", "gsimm.c", "archive.c", "sideband.c", "utf8.h", "local-fetch.c", "git-request-pull-script", "builtin-send-pack.c", "blob.c", "builtin-ls-remote.c", "pretty.c", "git-diff.sh", "diffcore-break.c", "unpack-trees.h", "git-mv.perl", "interpolate.c", "builtin-diff-files.c", "delta.h", "commit-tree.c", "git-diff-script", "decorate.c", "builtin-name-rev.c", "tree-walk.c", "git-revert-script", "git-sh-setup.sh", "transport.c", "gsimm.h", "archive.h", "count-delta.c", "sideband.h", "git-merge.sh", "git-gui.sh", "git-core.spec.in", "cvs2git.c", "blob.h", "git.sh", "http-push.c", "builtin-commit-tree.c", "diff-helper.c", "builtin-push.c", "interpolate.h", "decorate.h", "git-citool", "dotest", "builtin-verify-tag.c", "git-mergetool.sh", "tree-walk.h", "log-tree.c", "name-rev.c", "applypatch", "cat-file.c", "test-delta.c", "server-info.c", "count-delta.h", "write-tree.c", "local-pull.c", "transport.h", "git-rm.sh", "unpack-objects.c", "xdiff-interface.c", "git-repack-script", "commit.c", "hash-object.c", "git-merge-recursive.py", "git-clone-dumb-http", "thread-utils.c", "git-send-email.perl", "git-whatchanged.sh", "log-tree.h", "builtin-annotate.c", "show-index.c", "pkt-line.c", "ident.c", "git-rebase-script", "name-hash.c", "git-archimport.perl", "xdiff-interface.h", "commit.h", "diff-lib.c", "wt-status.c", "base85.c", "builtin-fetch--tool.c", "unpack-file.c", "builtin-diff-stages.c", "merge-index.c", "color.c", "diff-tree.c", "git-checkout.sh", "thread-utils.h", "grep.c", "pkt-line.h", "builtin-help.c", "test-parse-options.c", "show-files.c", "git.sh.in", "pack.h", "wt-status.h", "git-prune-script", "test-sha1.c", "git-octopus.sh", "dump-cache-tree.c", "git-web--browse.sh", "builtin-upload-tar.c", "builtin-clone.c", "copy.c", "color.h", "show-branch.c", "peek-remote.c", "git-merge-recursive-old.py", "cmd-rename.sh", "git-apply-patch-script", "git-export.c", "git-relink-script", "grep.h", "usage.c", "git-fetch-dumb-http", "fsck-objects.c", "update-cache.c", "diff-stages.c", "patch-ids.c", "builtin-rev-list.c", "builtin-bundle.c", "builtin-show-branch.c", "builtin-pack-refs.c", "tree.c", "git.c", "verify_pack.c", "update-ref.c", "builtin-peek-remote.c", "diffcore-pathspec.c", "git-merge-octopus.sh", "git-show-branches-script", "builtin-archive.c", "builtin-unpack-objects.c", "git-rerere.perl", "walker.c", "builtin-mailsplit.c", "convert.c", "builtin-branch.c", "export.c", "patch-ids.h", "check-builtins.sh", "git-pull-script", "tree.h", "alloc.c", "git-commit.sh", "git-lost-found.sh", "mailmap.c", "rsh.c", "exec_cmd.c", "git-compat-util.h", "ws.c", "rev-list.c", "git-verify-tag.sh", "git-ls-remote-script", "mktree.c", "walker.h", "builtin-blame.c", "builtin-fsck.c", "setup.c", "git-cvsimport-script", "git-add.sh", "symlinks.c", "checkout-index.c", "receive-pack.c", "git-merge-one-file-script", "mailmap.h", "git-cvsimport.perl", "builtin-count.c", "exec_cmd.h", "builtin-stripspace.c", "git-grep.sh", "hash.c", "builtin-prune-packed.c", "git-rebase--interactive.sh", "rsh.h", "match-trees.c", "git-format-patch.sh", "git-push-script", "parse-options.c", "git-status-script", "http-walker.c", "pack-write.c", "git-status.sh", "diff-delta.c", "hash.h", "generate-cmdlist.sh", "config-set.c", "builtin-fetch.c", "ll-merge.c", "t1300-config-set.sh", "ls-tree.c", "write_or_die.c", "builtin-check-ref-format.c", "fetch-pack.c", "git-commit-script", "builtin-describe.c", "parse-options.h", "builtin-checkout.c", "prune-packed.c", "fixup-builtins", "http-fetch.c", "test-absolute-path.c", "git-log.sh", "builtin-merge-ours.c", "git-whatchanged", "pull.c", "merge-tree.c", "ll-merge.h", "builtin.h", "Makefile", "cache-tree.c", "builtin-log.c", "merge-cache.c", "fetch-pack.h", "git-shortlog.perl", "git-bisect-script", "git-am.sh", "check-ref-format.c", "git-count-objects-script", "mkdelta.c", "builtin-diff.c", "merge-recursive.c", "builtin-config.c", "gitenv.c", "describe.c", "git-add--interactive.perl", "pull.h", "builtin-apply.c", "diff-index.c", "ssh-pull.c", "builtin-merge-file.c", "strbuf.c", "git-submodule.sh", "repo-config.c", "run-command.c", "git-applymbox.sh", "cache-tree.h", "builtin-clean.c", "cache.h", "git-prune.sh", "fsck-cache.c", "builtin-remote.c", "sha1_file.c", "shallow.c", "merge-recursive.h", "builtin-checkout-index.c", "git-clone.sh", "builtin-mv.c", "builtin-reflog.c", "lockfile.c", "git-octopus-script", ".mailmap", "strbuf.h", "git-p4import.py", "builtin-repo-config.c", "patch-delta.c", "builtin-merge-base.c", "run-command.h", "check-racy.c", "git-filter-branch.sh", "git-branch.sh", "git-merge-stupid.sh", "diff-files.c", "test-sha1.sh", "COPYING", "git-lost+found.sh", "git-tag.sh", "git-branch-script", "check-files.c", "builtin-reset.c", "builtin-ls-files.c", "builtin-fmt-merge-msg.c", "builtin-for-each-ref.c", "csum-file.c", "git-gc.sh", "git-parse-remote-script", "command-list.txt", "builtin-pack-objects.c", "dir.c", "test-date.c", "builtin-grep.c", "list-objects.c", "clone-pack.c", "git-gui", "convert-cache.c", "git-reset-script", "checkout-cache.c", "git-ls-remote.sh", "read-tree.c", "git-instaweb.sh", "progress.c", "rabinpoly.c", "ls-files.c", "mktag.c", "gitMergeCommon.py", "git-merge-ours.sh", "rpull.c", "git-annotate.perl", "csum-file.h", "builtin-shortlog.c", "builtin-commit.c", "http-pull.c", "git-fetch.sh", "apply.c", "git-add-script", "dir.h", "diff-tree-helper.c", "list-objects.h", "rev-tree.c", "builtin-tar-tree.c", "progress.h", "builtin-pickaxe.c", "git-merge-fredrik.py", "path.c", "builtin-diff-tree.c", "rabinpoly.h", "builtin-ls-tree.c", "tar.h", "trace.c", "graph.c", "ssh-fetch.c", "show-diff.c", "sha1-lookup.c", "builtin-revert.c", "builtin-symbolic-ref.c", "builtin-write-tree.c", "git-sh-setup-script", "rev-cache.c", "blame.c", "builtin-mailinfo.c", "git-cherry", "git-resolve-script", "INSTALL", "git-findtags.perl", "diffcore-delta.c", "entry.c", "git-applypatch", "connect.c", "tar-tree.c", "graph.h", "missing-revs.c", "builtin-fast-export.c", "sha1-lookup.h", "rev-parse.c", "configure.ac", "rev-cache.h", "build-rev-cache.c", "reachable.c", "index-pack.c", "git", "send-pack.c", "git-cherry.sh", "git-tag-script", "revision.c", "CREDITS-GEN", "bundle.c", "mailinfo.c", "symbolic-ref.c", "attr.c", "git-archimport-script", "archive-zip.c", "diff-cache.c", "fetch.c", "builtin-gc.c", "git-remote.perl", "path-list.c", "ssh-upload.c", "reachable.h", "diff-no-index.c", "diffcore.h", "send-pack.h", "tree-diff.c", "git-checkout-script", "pack-revindex.c", "show-rev-cache.c", "TODO", "revision.h", "bundle.h", "unresolve.c", "git-deltafy-script", "git-relink.perl", "archive-tar.c", "attr.h", "git-resolve.sh", "config.mak.in", "builtin-update-index.c", "convert-objects.c", "fetch.h", "builtin-runstatus.c", "quote.c", "init-db.c", "git-shortlog", "builtin-prune.c", "builtin-rerere.c", "verify-pack.c", "gitk", "patch-id.c", ".gitattributes", "date.c", "git-format-patch-script", "path-list.h", "pack-revindex.h", "GIT-VERSION-GEN", "combine-diff.c", "environment.c", "git-cvsserver.perl", "git-repack.sh", "diffcore-order.c", "reflog-walk.c", "config.c", "test-match-trees.c", "git-svnimport.perl", "quote.h", "write-blob.c", "diffcore-pickaxe.c", "builtin-update-ref.c", "stripspace.c", "help.c", "pack-objects.c", "branch.c", "git-verify-tag-script", "TEST", "daemon.c", "remote.c", "git-log-script", "git-pull.sh", "git-quiltimport.sh", "git-count-objects.sh", "reflog-walk.h", "git-applymbox", "builtin-show-ref.c", "RelNotes", "git-fmt-merge-msg.perl", "git-rebase.sh", "git-parse-remote", "git-browse--help.sh", "git-stash.sh", "alias.c", "branch.h", "gitweb.pl", "builtin-upload-archive.c", "builtin-cat-file.c", "sha1_name.c", "http.c", "test-chmtime.c", "remote.h", "ssh-push.c", "tag.c", "update-server-info.c", "git-cvsexportcommit.perl", "builtin-check-attr.c", "git-revert.sh", "builtin-verify-pack.c", "object.c", "git-merge-resolve.sh", "shortlog.h", "git-fetch-script", "test-genrandom.c", "shell.c", "builtin-rm.c", "builtin-zip-tree.c", "upload-pack.c", "git-rename.perl", ".gitignore", "tag.h", "http.h", "git-request-pull.sh", "object.h", "git-svn.perl", "builtin-fetch-pack.c", "git-bisect.sh", "pack-check.c", "builtin-rev-parse.c", "object-refs.c", "test-gsimm.c", "builtin-read-tree.c", "git-help--browse.sh", "merge-file.c", "fsck.c", "builtin-tag.c", "builtin-http-fetch.c", "builtin-count-objects.c", "git-reset.sh", "git-clean.sh", "git-merge-one-file.sh", "ctype.c", "git-mktag.c", "imap-send.c"]
|
@@ -168,7 +168,7 @@ if __FILE__ == $0
|
|
168
168
|
commit = 'c87612bc84c95ba9df17674d911dde10f34fefaa'
|
169
169
|
|
170
170
|
require 'benchmark'
|
171
|
-
|
171
|
+
|
172
172
|
Benchmark.bm(20) do |x|
|
173
173
|
x.report('index build') do
|
174
174
|
i = Grit::GitRuby::FileIndex.new(repo)
|
@@ -188,6 +188,6 @@ if __FILE__ == $0
|
|
188
188
|
end
|
189
189
|
end
|
190
190
|
end
|
191
|
-
|
192
|
-
|
193
|
-
|
191
|
+
|
192
|
+
|
193
|
+
|