schacon-grit 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/History.txt +13 -0
  2. data/Manifest.txt +57 -0
  3. data/README.txt +213 -0
  4. data/Rakefile +29 -0
  5. data/grit.gemspec +60 -0
  6. data/lib/grit.rb +53 -0
  7. data/lib/grit/actor.rb +36 -0
  8. data/lib/grit/blob.rb +117 -0
  9. data/lib/grit/commit.rb +221 -0
  10. data/lib/grit/commit_stats.rb +104 -0
  11. data/lib/grit/config.rb +44 -0
  12. data/lib/grit/diff.rb +70 -0
  13. data/lib/grit/errors.rb +7 -0
  14. data/lib/grit/git-ruby.rb +175 -0
  15. data/lib/grit/git-ruby/commit_db.rb +52 -0
  16. data/lib/grit/git-ruby/file_index.rb +186 -0
  17. data/lib/grit/git-ruby/git_object.rb +344 -0
  18. data/lib/grit/git-ruby/internal/loose.rb +136 -0
  19. data/lib/grit/git-ruby/internal/mmap.rb +59 -0
  20. data/lib/grit/git-ruby/internal/pack.rb +332 -0
  21. data/lib/grit/git-ruby/internal/raw_object.rb +37 -0
  22. data/lib/grit/git-ruby/object.rb +319 -0
  23. data/lib/grit/git-ruby/repository.rb +675 -0
  24. data/lib/grit/git.rb +130 -0
  25. data/lib/grit/head.rb +83 -0
  26. data/lib/grit/index.rb +102 -0
  27. data/lib/grit/lazy.rb +31 -0
  28. data/lib/grit/ref.rb +95 -0
  29. data/lib/grit/repo.rb +381 -0
  30. data/lib/grit/status.rb +149 -0
  31. data/lib/grit/tag.rb +71 -0
  32. data/lib/grit/tree.rb +100 -0
  33. data/test/test_actor.rb +35 -0
  34. data/test/test_blob.rb +79 -0
  35. data/test/test_commit.rb +184 -0
  36. data/test/test_config.rb +58 -0
  37. data/test/test_diff.rb +18 -0
  38. data/test/test_git.rb +70 -0
  39. data/test/test_grit.rb +32 -0
  40. data/test/test_head.rb +41 -0
  41. data/test/test_real.rb +19 -0
  42. data/test/test_reality.rb +17 -0
  43. data/test/test_remote.rb +14 -0
  44. data/test/test_repo.rb +277 -0
  45. data/test/test_tag.rb +25 -0
  46. data/test/test_tree.rb +96 -0
  47. metadata +110 -0
data/lib/grit/diff.rb ADDED
@@ -0,0 +1,70 @@
1
+ module Grit
2
+
3
+ class Diff
4
+ attr_reader :a_path, :b_path
5
+ attr_reader :a_commit, :b_commit
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_commit, b_commit, a_mode, b_mode, new_file, deleted_file, diff)
11
+ @repo = repo
12
+ @a_path = a_path
13
+ @b_path = b_path
14
+ @a_commit = a_commit =~ /^0{40}$/ ? nil : Commit.create(repo, :id => a_commit)
15
+ @b_commit = b_commit =~ /^0{40}$/ ? nil : Commit.create(repo, :id => b_commit)
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_commit, b_commit, 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_commit, b_commit, 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,175 @@
1
+ require 'grit/git-ruby/repository'
2
+ require 'grit/git-ruby/file_index'
3
+ require 'grit/git-ruby/commit_db'
4
+
5
+ module Grit
6
+
7
+ # the functions in this module intercept the calls to git binary
8
+ # made buy the grit objects and attempts to run them in pure ruby
9
+ # if it will be faster, or if the git binary is not available (!!TODO!!)
10
+ module GitRuby
11
+
12
+ attr_accessor :ruby_git_repo, :git_file_index
13
+
14
+ def cat_file(options, ref)
15
+ if options[:t]
16
+ file_type(ref)
17
+ elsif options[:s]
18
+ file_size(ref)
19
+ elsif options[:p]
20
+ try_run { ruby_git.cat_file(ref) }
21
+ end
22
+ rescue Grit::GitRuby::Repository::NoSuchShaFound
23
+ ''
24
+ end
25
+
26
+ # lib/grit/tree.rb:16: output = repo.git.ls_tree({}, treeish, *paths)
27
+ def ls_tree(options, treeish, *paths)
28
+ sha = rev_parse({}, treeish)
29
+ ruby_git.ls_tree(sha, paths.flatten)
30
+ rescue Grit::GitRuby::Repository::NoSuchShaFound
31
+ ''
32
+ end
33
+
34
+ # git diff --full-index 'ec037431382e83c3e95d4f2b3d145afbac8ea55d' 'f1ec1aea10986159456846b8a05615b87828d6c6'
35
+ def diff(options, sha1, sha2)
36
+ try_run { ruby_git.diff(sha1, sha2, options) }
37
+ end
38
+
39
+ def rev_list(options, ref = 'master')
40
+ options.delete(:skip) if options[:skip].to_i == 0
41
+ allowed_options = [:max_count, :since, :until, :pretty] # this is all I can do right now
42
+ if ((options.keys - allowed_options).size > 0)
43
+ return method_missing('rev-list', options, ref)
44
+ elsif (options.size == 0)
45
+ # pure rev-list
46
+ begin
47
+ return file_index.commits_from(rev_parse({}, ref)).join("\n")
48
+ rescue
49
+ return method_missing('rev-list', options, ref)
50
+ end
51
+ else
52
+ aref = rev_parse({}, ref)
53
+ if aref.is_a? Array
54
+ return method_missing('rev-list', options, ref)
55
+ else
56
+ return try_run { ruby_git.rev_list(aref, options) }
57
+ end
58
+ end
59
+ end
60
+
61
+ def rev_parse(options, string)
62
+ if string =~ /\.\./
63
+ (sha1, sha2) = string.split('..')
64
+ return [rev_parse({}, sha1), rev_parse({}, sha2)]
65
+ end
66
+
67
+ if /\w{40}/.match(string) # passing in a sha - just no-op it
68
+ return string.chomp
69
+ end
70
+
71
+ head = File.join(@git_dir, 'refs', 'heads', string)
72
+ return File.read(head).chomp if File.file?(head)
73
+
74
+ head = File.join(@git_dir, 'refs', 'remotes', string)
75
+ return File.read(head).chomp if File.file?(head)
76
+
77
+ head = File.join(@git_dir, 'refs', 'tags', string)
78
+ return File.read(head).chomp if File.file?(head)
79
+
80
+ ## check packed-refs file, too
81
+ packref = File.join(@git_dir, 'packed-refs')
82
+ if File.file?(packref)
83
+ File.readlines(packref).each do |line|
84
+ if m = /^(\w{40}) refs\/.+?\/(.*?)$/.match(line)
85
+ next if !Regexp.new(string + '$').match(m[3])
86
+ return m[1].chomp
87
+ end
88
+ end
89
+ end
90
+
91
+ ## !! more - partials and such !!
92
+
93
+ # revert to calling git - grr
94
+ return method_missing('rev-parse', {}, string).chomp
95
+ end
96
+
97
+ def file_size(ref)
98
+ try_run { ruby_git.cat_file_size(ref).to_s }
99
+ end
100
+
101
+ def file_type(ref)
102
+ try_run { ruby_git.cat_file_type(ref).to_s }
103
+ end
104
+
105
+ def blame_tree(commit, path = nil)
106
+ begin
107
+ commits = file_index.last_commits(rev_parse({}, commit), looking_for(commit, path))
108
+ clean_paths(commits)
109
+ rescue FileIndex::IndexFileNotFound
110
+ {}
111
+ end
112
+ end
113
+
114
+ def file_index
115
+ @git_file_index ||= FileIndex.new(@git_dir)
116
+ end
117
+
118
+ def ruby_git
119
+ @ruby_git_repo ||= Repository.new(@git_dir)
120
+ end
121
+
122
+ private
123
+
124
+ def try_run
125
+ ret = ''
126
+ Timeout.timeout(self.class.git_timeout) do
127
+ ret = yield
128
+ end
129
+ @bytes_read += ret.size
130
+
131
+ #if @bytes_read > 5242880 # 5.megabytes
132
+ # bytes = @bytes_read
133
+ # @bytes_read = 0
134
+ # raise Grit::Git::GitTimeout.new(command, bytes)
135
+ #end
136
+
137
+ ret
138
+ rescue Timeout::Error => e
139
+ bytes = @bytes_read
140
+ @bytes_read = 0
141
+ raise Grit::Git::GitTimeout.new(command, bytes)
142
+ end
143
+
144
+ def looking_for(commit, path = nil)
145
+ tree_sha = ruby_git.get_subtree(rev_parse({}, commit), path)
146
+
147
+ looking_for = []
148
+ ruby_git.get_object_by_sha1(tree_sha).entry.each do |e|
149
+ if path && !(path == '' || path == '.' || path == './')
150
+ file = File.join(path, e.name)
151
+ else
152
+ file = e.name
153
+ end
154
+ file += '/' if e.type == :directory
155
+ looking_for << file
156
+ end
157
+ looking_for
158
+ end
159
+
160
+ def clean_paths(commit_array)
161
+ new_commits = {}
162
+ commit_array.each do |file, sha|
163
+ file = file.chop if file[file.size - 1 , 1] == '/'
164
+ new_commits[file] = sha
165
+ end
166
+ new_commits
167
+ end
168
+
169
+ # TODO
170
+ # git grep -n 'foo' 'master'
171
+ # git log --pretty='raw' --max-count='1' 'master' -- 'LICENSE'
172
+ # git log --pretty='raw' --max-count='1' 'master' -- 'test'
173
+
174
+ end
175
+ 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,186 @@
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
+ attr_reader :files
26
+
27
+ # initializes index given repo_path
28
+ def initialize(repo_path)
29
+ @index_file = File.join(repo_path, 'file-index')
30
+ if File.file?(@index_file)
31
+ read_index
32
+ else
33
+ raise IndexFileNotFound
34
+ end
35
+ end
36
+
37
+ # returns count of all commits
38
+ def count_all
39
+ @sha_count
40
+ end
41
+
42
+ # returns count of all commits reachable from SHA
43
+ # note: originally did this recursively, but ruby gets pissed about that on
44
+ # really big repos where the stack level gets 'too deep' (thats what she said)
45
+ def count(commit_sha)
46
+ commits_from(commit_sha).size
47
+ end
48
+
49
+ def commits_from(commit_sha)
50
+ raise UnsupportedRef if commit_sha.is_a? Array
51
+
52
+ already = {}
53
+ final = []
54
+ left_to_do = [commit_sha]
55
+
56
+ while commit_sha = left_to_do.shift
57
+ next if already[commit_sha]
58
+
59
+ final << commit_sha
60
+ already[commit_sha] = true
61
+
62
+ commit = @commit_index[commit_sha]
63
+ commit[:parents].each do |sha|
64
+ left_to_do << sha
65
+ end if commit
66
+ end
67
+
68
+ sort_commits(final)
69
+ end
70
+
71
+ def sort_commits(sha_array)
72
+ sha_array.sort { |a, b| @commit_order[b] <=> @commit_order[a] }
73
+ end
74
+
75
+ # returns files changed at commit sha
76
+ def files(commit_sha)
77
+ @commit_index[commit_sha][:files] rescue nil
78
+ end
79
+
80
+ # returns all commits for a file
81
+ def commits_for(file)
82
+ @all_files[file]
83
+ end
84
+
85
+ # returns the shas of the last commits for all
86
+ # the files in [] from commit_sha
87
+ # files_matcher can be a regexp or an array
88
+ def last_commits(commit_sha, files_matcher)
89
+ acceptable = commits_from(commit_sha)
90
+
91
+ matches = {}
92
+
93
+ if files_matcher.is_a? Regexp
94
+ files = @all_files.keys.select { |file| file =~ files_matcher }
95
+ files_matcher = files
96
+ end
97
+
98
+ if files_matcher.is_a? Array
99
+ # find the last commit for each file in the array
100
+ files_matcher.each do |f|
101
+ @all_files[f].each do |try|
102
+ if acceptable.include?(try)
103
+ matches[f] = try
104
+ break
105
+ end
106
+ end if @all_files[f]
107
+ end
108
+ end
109
+
110
+ matches
111
+ end
112
+
113
+ private
114
+
115
+ # read and parse the file-index data
116
+ def read_index
117
+ f = File.new(@index_file)
118
+ @sha_count = 0
119
+ @commit_index = {}
120
+ @commit_order = {}
121
+ @all_files = {}
122
+ while line = f.gets
123
+ if /^(\w{40})/.match(line)
124
+ shas = line.scan(/(\w{40})/)
125
+ current_sha = shas.shift.first
126
+ parents = shas.map { |sha| sha.first }
127
+ @commit_index[current_sha] = {:files => [], :parents => parents }
128
+ @commit_order[current_sha] = @sha_count
129
+ @sha_count += 1
130
+ else
131
+ file_name = line.chomp
132
+ tree = ''
133
+ File.dirname(file_name).split('/').each do |part|
134
+ next if part == '.'
135
+ tree += part + '/'
136
+ @all_files[tree] ||= []
137
+ @all_files[tree].unshift(current_sha)
138
+ end
139
+ @all_files[file_name] ||= []
140
+ @all_files[file_name].unshift(current_sha)
141
+ @commit_index[current_sha][:files] << file_name
142
+ end
143
+ end
144
+ end
145
+
146
+ end
147
+
148
+ end
149
+ end
150
+
151
+
152
+ # benchmark testing on big-ass repos
153
+
154
+ if __FILE__ == $0
155
+
156
+ #repo = '/Users/schacon/projects/git/.git'
157
+ #commit = 'd8933f013a66cc1deadf83a9c24eccb6fee78a35'
158
+ #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"]
159
+
160
+ repo = '/Users/schacon/projects/grit/.git'
161
+ commit = 'c87612bc84c95ba9df17674d911dde10f34fefaa'
162
+
163
+ require 'benchmark'
164
+
165
+ Benchmark.bm(20) do |x|
166
+ x.report('index build') do
167
+ i = Grit::GitRuby::FileIndex.new(repo)
168
+ end
169
+ x.report('commit count') do
170
+ i = Grit::GitRuby::FileIndex.new(repo)
171
+ i.count(commit)
172
+ end
173
+ x.report('commits list') do
174
+ i = Grit::GitRuby::FileIndex.new(repo)
175
+ i.commits_from(commit)
176
+ end
177
+ x.report('last commits') do
178
+ i = Grit::GitRuby::FileIndex.new(repo)
179
+ #arr = i.last_commits(commit, file_list)
180
+ arr = i.last_commits(commit, /^[^\/]*$/)
181
+ end
182
+ end
183
+ end
184
+
185
+
186
+