initializes index given repo_path
# File lib/grit/git-ruby/file_index.rb, line 34 def initialize(repo_path) @index_file = File.join(repo_path, 'file-index') if File.file?(@index_file) && (File.size(@index_file) < Grit::GitRuby::FileIndex.max_file_size) read_index else raise IndexFileNotFound end end
returns all commits for a file
# File lib/grit/git-ruby/file_index.rb, line 88 def commits_for(file) @all_files[file] end
builds a list of all commits reachable from a single commit
# File lib/grit/git-ruby/file_index.rb, line 56 def commits_from(commit_sha) raise UnsupportedRef if commit_sha.is_a? Array already = {} final = [] left_to_do = [commit_sha] while commit_sha = left_to_do.shift next if already[commit_sha] final << commit_sha already[commit_sha] = true commit = @commit_index[commit_sha] commit[:parents].each do |sha| left_to_do << sha end if commit end sort_commits(final) 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 def count(commit_sha) commits_from(commit_sha).size end
returns count of all commits
# File lib/grit/git-ruby/file_index.rb, line 44 def count_all @sha_count 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 def last_commits(commit_sha, files_matcher) acceptable = commits_from(commit_sha) matches = {} if files_matcher.is_a? Regexp files = @all_files.keys.select { |file| file =~ files_matcher } files_matcher = files end if files_matcher.is_a? Array # find the last commit for each file in the array files_matcher.each do |f| @all_files[f].each do |try| if acceptable.include?(try) matches[f] = try break end end if @all_files[f] end end matches end
Generated with the Darkfish Rdoc Generator 2.