| Class | Grit::GitRuby::FileIndex |
| In: |
lib/grit/git-ruby/file_index.rb
|
| Parent: | Object |
| files | [R] | |
| max_file_size | [RW] |
initializes index given repo_path
# File lib/grit/git-ruby/file_index.rb, line 34
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
returns all commits for a file
# File lib/grit/git-ruby/file_index.rb, line 88
88: def commits_for(file)
89: @all_files[file]
90: end
builds a list of all commits reachable from a single commit
# File lib/grit/git-ruby/file_index.rb, line 56
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
returns count of all commits reachable from SHA note: originally did this recursively, but ruby gets pissed about that on really big repos where the stack level gets ‘too deep’ (thats what she said)
# File lib/grit/git-ruby/file_index.rb, line 51
51: def count(commit_sha)
52: commits_from(commit_sha).size
53: end
returns the shas of the last commits for all the files in [] from commit_sha files_matcher can be a regexp or an array
# File lib/grit/git-ruby/file_index.rb, line 95
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