robinluckey-grit 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,44 @@
1
+ module Grit
2
+
3
+ class Config
4
+ def initialize(repo)
5
+ @repo = repo
6
+ end
7
+
8
+ def []=(key, value)
9
+ @repo.git.config({}, key, value)
10
+ @data = nil
11
+ end
12
+
13
+ def [](key)
14
+ data[key]
15
+ end
16
+
17
+ def fetch(key, default = nil)
18
+ data[key] || default || raise(IndexError.new("key not found"))
19
+ end
20
+
21
+ def keys
22
+ data.keys
23
+ end
24
+
25
+ protected
26
+ def data
27
+ @data ||= load_config
28
+ end
29
+
30
+ def load_config
31
+ hash = {}
32
+ config_lines.map do |line|
33
+ key, value = line.split(/=/, 2)
34
+ hash[key] = value
35
+ end
36
+ hash
37
+ end
38
+
39
+ def config_lines
40
+ @repo.git.config(:list => true).split(/\n/)
41
+ end
42
+ end # Config
43
+
44
+ end # Grit
@@ -0,0 +1,70 @@
1
+ module Grit
2
+
3
+ class Diff
4
+ attr_reader :a_path, :b_path
5
+ attr_reader :a_blob, :b_blob
6
+ attr_reader :a_mode, :b_mode
7
+ attr_reader :new_file, :deleted_file
8
+ attr_reader :diff
9
+
10
+ def initialize(repo, a_path, b_path, a_blob, b_blob, a_mode, b_mode, new_file, deleted_file, diff)
11
+ @repo = repo
12
+ @a_path = a_path
13
+ @b_path = b_path
14
+ @a_blob = a_blob =~ /^0{40}$/ ? nil : Blob.create(repo, :id => a_blob)
15
+ @b_blob = b_blob =~ /^0{40}$/ ? nil : Blob.create(repo, :id => b_blob)
16
+ @a_mode = a_mode
17
+ @b_mode = b_mode
18
+ @new_file = new_file
19
+ @deleted_file = deleted_file
20
+ @diff = diff
21
+ end
22
+
23
+ def self.list_from_string(repo, text)
24
+ lines = text.split("\n")
25
+
26
+ diffs = []
27
+
28
+ while !lines.empty?
29
+ m, a_path, b_path = *lines.shift.match(%r{^diff --git a/(.+?) b/(.+)$})
30
+
31
+ if lines.first =~ /^old mode/
32
+ m, a_mode = *lines.shift.match(/^old mode (\d+)/)
33
+ m, b_mode = *lines.shift.match(/^new mode (\d+)/)
34
+ end
35
+
36
+ if lines.empty? || lines.first =~ /^diff --git/
37
+ diffs << Diff.new(repo, a_path, b_path, nil, nil, a_mode, b_mode, false, false, nil)
38
+ next
39
+ end
40
+
41
+ new_file = false
42
+ deleted_file = false
43
+
44
+ if lines.first =~ /^new file/
45
+ m, b_mode = lines.shift.match(/^new file mode (.+)$/)
46
+ a_mode = nil
47
+ new_file = true
48
+ elsif lines.first =~ /^deleted file/
49
+ m, a_mode = lines.shift.match(/^deleted file mode (.+)$/)
50
+ b_mode = nil
51
+ deleted_file = true
52
+ end
53
+
54
+ m, a_blob, b_blob, b_mode = *lines.shift.match(%r{^index ([0-9A-Fa-f]+)\.\.([0-9A-Fa-f]+) ?(.+)?$})
55
+ b_mode.strip! if b_mode
56
+
57
+ diff_lines = []
58
+ while lines.first && lines.first !~ /^diff/
59
+ diff_lines << lines.shift
60
+ end
61
+ diff = diff_lines.join("\n")
62
+
63
+ diffs << Diff.new(repo, a_path, b_path, a_blob, b_blob, a_mode, b_mode, new_file, deleted_file, diff)
64
+ end
65
+
66
+ diffs
67
+ end
68
+ end # Diff
69
+
70
+ end # Grit
@@ -0,0 +1,7 @@
1
+ module Grit
2
+ class InvalidGitRepositoryError < StandardError
3
+ end
4
+
5
+ class NoSuchPathError < StandardError
6
+ end
7
+ end
@@ -0,0 +1,186 @@
1
+ require 'grit/git-ruby/repository'
2
+ require 'grit/git-ruby/file_index'
3
+
4
+ module Grit
5
+
6
+ # the functions in this module intercept the calls to git binary
7
+ # made buy the grit objects and attempts to run them in pure ruby
8
+ # if it will be faster, or if the git binary is not available (!!TODO!!)
9
+ module GitRuby
10
+
11
+ attr_accessor :ruby_git_repo, :git_file_index
12
+
13
+ def init(options)
14
+ if options.size == 0
15
+ Grit::GitRuby::Repository.init(@git_dir)
16
+ else
17
+ method_missing('init', options)
18
+ end
19
+ end
20
+
21
+ def cat_file(options, ref)
22
+ if options[:t]
23
+ file_type(ref)
24
+ elsif options[:s]
25
+ file_size(ref)
26
+ elsif options[:p]
27
+ try_run { ruby_git.cat_file(ref) }
28
+ end
29
+ rescue Grit::GitRuby::Repository::NoSuchShaFound
30
+ ''
31
+ end
32
+
33
+ # lib/grit/tree.rb:16: output = repo.git.ls_tree({}, treeish, *paths)
34
+ def ls_tree(options, treeish, *paths)
35
+ sha = rev_parse({}, treeish)
36
+ ruby_git.ls_tree(sha, paths.flatten)
37
+ rescue Grit::GitRuby::Repository::NoSuchShaFound
38
+ ''
39
+ end
40
+
41
+ # git diff --full-index 'ec037431382e83c3e95d4f2b3d145afbac8ea55d' 'f1ec1aea10986159456846b8a05615b87828d6c6'
42
+ def diff(options, sha1, sha2)
43
+ try_run { ruby_git.diff(sha1, sha2, options) }
44
+ end
45
+
46
+ def rev_list(options, ref = 'master')
47
+ options.delete(:skip) if options[:skip].to_i == 0
48
+ allowed_options = [:max_count, :since, :until, :pretty] # this is all I can do right now
49
+ if ((options.keys - allowed_options).size > 0)
50
+ return method_missing('rev-list', options, ref)
51
+ elsif (options.size == 0)
52
+ # pure rev-list
53
+ begin
54
+ return file_index.commits_from(rev_parse({}, ref)).join("\n") + "\n"
55
+ rescue
56
+ return method_missing('rev-list', options, ref)
57
+ end
58
+ else
59
+ aref = rev_parse({}, ref)
60
+ if aref.is_a? Array
61
+ return method_missing('rev-list', options, ref)
62
+ else
63
+ return try_run { ruby_git.rev_list(aref, options) }
64
+ end
65
+ end
66
+ end
67
+
68
+ def rev_parse(options, string)
69
+ raise RuntimeError, "invalid string: #{string}" unless string.is_a?(String)
70
+
71
+ if string =~ /\.\./
72
+ (sha1, sha2) = string.split('..')
73
+ return [rev_parse({}, sha1), rev_parse({}, sha2)]
74
+ end
75
+
76
+ if /^[0-9a-f]{40}$/.match(string) # passing in a sha - just no-op it
77
+ return string.chomp
78
+ end
79
+
80
+ head = File.join(@git_dir, 'refs', 'heads', string)
81
+ return File.read(head).chomp if File.file?(head)
82
+
83
+ head = File.join(@git_dir, 'refs', 'remotes', string)
84
+ return File.read(head).chomp if File.file?(head)
85
+
86
+ head = File.join(@git_dir, 'refs', 'tags', string)
87
+ return File.read(head).chomp if File.file?(head)
88
+
89
+ ## check packed-refs file, too
90
+ packref = File.join(@git_dir, 'packed-refs')
91
+ if File.file?(packref)
92
+ File.readlines(packref).each do |line|
93
+ if m = /^(\w{40}) refs\/.+?\/(.*?)$/.match(line)
94
+ next if !Regexp.new(Regexp.escape(string) + '$').match(m[3])
95
+ return m[1].chomp
96
+ end
97
+ end
98
+ end
99
+
100
+ ## !! more - partials and such !!
101
+
102
+ # revert to calling git - grr
103
+ return method_missing('rev-parse', {}, string).chomp
104
+ end
105
+
106
+ def file_size(ref)
107
+ try_run { ruby_git.cat_file_size(ref).to_s }
108
+ end
109
+
110
+ def file_type(ref)
111
+ try_run { ruby_git.cat_file_type(ref).to_s }
112
+ end
113
+
114
+ def blame_tree(commit, path = nil)
115
+ begin
116
+ path = [path].join('/').to_s + '/' if (path && path != '')
117
+ path = '' if !path.is_a? String
118
+ commits = file_index.last_commits(rev_parse({}, commit), looking_for(commit, path))
119
+ clean_paths(commits)
120
+ rescue FileIndex::IndexFileNotFound
121
+ {}
122
+ end
123
+ end
124
+
125
+ def file_index
126
+ @git_file_index ||= FileIndex.new(@git_dir)
127
+ end
128
+
129
+ def ruby_git
130
+ @ruby_git_repo ||= Repository.new(@git_dir)
131
+ end
132
+
133
+ private
134
+
135
+ def try_run
136
+ ret = ''
137
+ Timeout.timeout(self.class.git_timeout) do
138
+ ret = yield
139
+ end
140
+ @bytes_read += ret.size
141
+
142
+ #if @bytes_read > 5242880 # 5.megabytes
143
+ # bytes = @bytes_read
144
+ # @bytes_read = 0
145
+ # raise Grit::Git::GitTimeout.new(command, bytes)
146
+ #end
147
+
148
+ ret
149
+ rescue Timeout::Error => e
150
+ bytes = @bytes_read
151
+ @bytes_read = 0
152
+ raise Grit::Git::GitTimeout.new(command, bytes)
153
+ end
154
+
155
+ def looking_for(commit, path = nil)
156
+ tree_sha = ruby_git.get_subtree(rev_parse({}, commit), path)
157
+
158
+ looking_for = []
159
+ ruby_git.get_object_by_sha1(tree_sha).entry.each do |e|
160
+ if path && !(path == '' || path == '.' || path == './')
161
+ file = File.join(path, e.name)
162
+ else
163
+ file = e.name
164
+ end
165
+ file += '/' if e.type == :directory
166
+ looking_for << file
167
+ end
168
+ looking_for
169
+ end
170
+
171
+ def clean_paths(commit_array)
172
+ new_commits = {}
173
+ commit_array.each do |file, sha|
174
+ file = file.chop if file[file.size - 1 , 1] == '/'
175
+ new_commits[file] = sha
176
+ end
177
+ new_commits
178
+ end
179
+
180
+ # TODO
181
+ # git grep -n 'foo' 'master'
182
+ # git log --pretty='raw' --max-count='1' 'master' -- 'LICENSE'
183
+ # git log --pretty='raw' --max-count='1' 'master' -- 'test'
184
+
185
+ end
186
+ end
@@ -0,0 +1,52 @@
1
+ begin
2
+ require 'sequel'
3
+
4
+ module Grit
5
+
6
+ class CommitDb
7
+
8
+ SCHEMA_VERSION = 1
9
+
10
+ attr_accessor :db, :git
11
+
12
+ def initialize(git_obj, index_location = nil)
13
+ @git = git_obj
14
+ db_file = File.join(index_location || @git.git_dir, 'commit_db')
15
+ if !File.exists?(db_file)
16
+ @db = Sequel.open "sqlite:///#{db_file}"
17
+ setup_tables
18
+ else
19
+ @db = Sequel.open "sqlite:///#{db_file}"
20
+ end
21
+ end
22
+
23
+ def rev_list(branch, options)
24
+ end
25
+
26
+ def update_db(branch = nil)
27
+ # find all refs/heads, for each
28
+ # add branch if not there
29
+ # go though all commits in branch
30
+ # add new commit_branches a
31
+ # and commit_nodes for each new one
32
+ # stop if reach commit that already has branch and node links
33
+ end
34
+
35
+ def setup_tables
36
+ @db << "create table meta (meta_key text, meta_value text)"
37
+ @db[:meta] << {:meta_key => 'schema', :meta_value => SCHEMA_VERSION}
38
+
39
+ @db << "create table commits (id integer, sha text, author_date integer)"
40
+ @db << "create table nodes (id integer, path text, type text)"
41
+ @db << "create table branches (id integer, ref text, commit_id integer)"
42
+
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)"
45
+ end
46
+
47
+ end
48
+ end
49
+
50
+ rescue LoadError
51
+ # no commit db
52
+ end
@@ -0,0 +1,193 @@
1
+ # this implements a file-based 'file index', an simple index of
2
+ # all of the reachable commits in a repo, along with the parents
3
+ # and which files were modified during each commit
4
+ #
5
+ # this class looks for a file named '[.git]/file-index', generated via:
6
+ #
7
+ # git log --pretty=oneline --name-only --parents --reverse --all > file-index
8
+ #
9
+ # for this to work properly, you'll want to add the following as a post-receive hook
10
+ # to keep the index up to date
11
+ #
12
+ # git log --pretty=oneline --name-only --parents --reverse [old-rev]..[new-rev] >> file-index
13
+ #
14
+ module Grit
15
+ module GitRuby
16
+
17
+ class FileIndex
18
+
19
+ class IndexFileNotFound < StandardError
20
+ end
21
+
22
+ class UnsupportedRef < StandardError
23
+ end
24
+
25
+ class << self
26
+ attr_accessor :max_file_size
27
+ end
28
+
29
+ self.max_file_size = 10_000_000 # ~10M
30
+
31
+ attr_reader :files
32
+
33
+ # initializes index given repo_path
34
+ def initialize(repo_path)
35
+ @index_file = File.join(repo_path, 'file-index')
36
+ if File.file?(@index_file) && (File.size(@index_file) < Grit::GitRuby::FileIndex.max_file_size)
37
+ read_index
38
+ else
39
+ raise IndexFileNotFound
40
+ end
41
+ end
42
+
43
+ # returns count of all commits
44
+ def count_all
45
+ @sha_count
46
+ end
47
+
48
+ # returns count of all commits reachable from SHA
49
+ # note: originally did this recursively, but ruby gets pissed about that on
50
+ # really big repos where the stack level gets 'too deep' (thats what she said)
51
+ def count(commit_sha)
52
+ commits_from(commit_sha).size
53
+ end
54
+
55
+ # builds a list of all commits reachable from a single commit
56
+ def commits_from(commit_sha)
57
+ raise UnsupportedRef if commit_sha.is_a? Array
58
+
59
+ already = {}
60
+ final = []
61
+ left_to_do = [commit_sha]
62
+
63
+ while commit_sha = left_to_do.shift
64
+ next if already[commit_sha]
65
+
66
+ final << commit_sha
67
+ already[commit_sha] = true
68
+
69
+ commit = @commit_index[commit_sha]
70
+ commit[:parents].each do |sha|
71
+ left_to_do << sha
72
+ end if commit
73
+ end
74
+
75
+ sort_commits(final)
76
+ end
77
+
78
+ def sort_commits(sha_array)
79
+ sha_array.sort { |a, b| @commit_order[b].to_i <=> @commit_order[a].to_i }
80
+ end
81
+
82
+ # returns files changed at commit sha
83
+ def files(commit_sha)
84
+ @commit_index[commit_sha][:files] rescue nil
85
+ end
86
+
87
+ # returns all commits for a file
88
+ def commits_for(file)
89
+ @all_files[file]
90
+ end
91
+
92
+ # returns the shas of the last commits for all
93
+ # the files in [] from commit_sha
94
+ # files_matcher can be a regexp or an array
95
+ def last_commits(commit_sha, files_matcher)
96
+ acceptable = commits_from(commit_sha)
97
+
98
+ matches = {}
99
+
100
+ if files_matcher.is_a? Regexp
101
+ files = @all_files.keys.select { |file| file =~ files_matcher }
102
+ files_matcher = files
103
+ end
104
+
105
+ if files_matcher.is_a? Array
106
+ # find the last commit for each file in the array
107
+ files_matcher.each do |f|
108
+ @all_files[f].each do |try|
109
+ if acceptable.include?(try)
110
+ matches[f] = try
111
+ break
112
+ end
113
+ end if @all_files[f]
114
+ end
115
+ end
116
+
117
+ matches
118
+ end
119
+
120
+ private
121
+
122
+ # read and parse the file-index data
123
+ def read_index
124
+ f = File.new(@index_file)
125
+ @sha_count = 0
126
+ @commit_index = {}
127
+ @commit_order = {}
128
+ @all_files = {}
129
+ while line = f.gets
130
+ if /^(\w{40})/.match(line)
131
+ shas = line.scan(/(\w{40})/)
132
+ current_sha = shas.shift.first
133
+ parents = shas.map { |sha| sha.first }
134
+ @commit_index[current_sha] = {:files => [], :parents => parents }
135
+ @commit_order[current_sha] = @sha_count
136
+ @sha_count += 1
137
+ else
138
+ file_name = line.chomp
139
+ tree = ''
140
+ File.dirname(file_name).split('/').each do |part|
141
+ next if part == '.'
142
+ tree += part + '/'
143
+ @all_files[tree] ||= []
144
+ @all_files[tree].unshift(current_sha)
145
+ end
146
+ @all_files[file_name] ||= []
147
+ @all_files[file_name].unshift(current_sha)
148
+ @commit_index[current_sha][:files] << file_name
149
+ end
150
+ end
151
+ end
152
+
153
+ end
154
+
155
+ end
156
+ end
157
+
158
+
159
+ # benchmark testing on big-ass repos
160
+
161
+ if __FILE__ == $0
162
+
163
+ #repo = '/Users/schacon/projects/git/.git'
164
+ #commit = 'd8933f013a66cc1deadf83a9c24eccb6fee78a35'
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"]
166
+
167
+ repo = '/Users/schacon/projects/grit/.git'
168
+ commit = 'c87612bc84c95ba9df17674d911dde10f34fefaa'
169
+
170
+ require 'benchmark'
171
+
172
+ Benchmark.bm(20) do |x|
173
+ x.report('index build') do
174
+ i = Grit::GitRuby::FileIndex.new(repo)
175
+ end
176
+ x.report('commit count') do
177
+ i = Grit::GitRuby::FileIndex.new(repo)
178
+ i.count(commit)
179
+ end
180
+ x.report('commits list') do
181
+ i = Grit::GitRuby::FileIndex.new(repo)
182
+ i.commits_from(commit)
183
+ end
184
+ x.report('last commits') do
185
+ i = Grit::GitRuby::FileIndex.new(repo)
186
+ #arr = i.last_commits(commit, file_list)
187
+ arr = i.last_commits(commit, /^[^\/]*$/)
188
+ end
189
+ end
190
+ end
191
+
192
+
193
+