the functions in this module intercept the calls to git binary made buy the grit objects and attempts to run them in pure ruby if it will be faster, or if the git binary is not available (!!TODO!!)
| git_file_index | [RW] | |
| ruby_git_repo | [RW] |
# File lib/grit/git-ruby/object.rb, line 164
164: def self.read_bytes_until(io, char)
165: string = ''
166: if RUBY_VERSION > '1.9'
167: while ((next_char = io.getc) != char) && !io.eof
168: string += next_char
169: end
170: else
171: while ((next_char = io.getc.chr) != char) && !io.eof
172: string += next_char
173: end
174: end
175: string
176: end
# File lib/grit/git-ruby/git_object.rb, line 180
180: def self.read_bytes_until(io, char)
181: string = ''
182: if RUBY_VERSION > '1.9'
183: while ((next_char = io.getc) != char) && !io.eof
184: string += next_char
185: end
186: else
187: while ((next_char = io.getc.chr) != char) && !io.eof
188: string += next_char
189: end
190: end
191: string
192: end
# File lib/grit/git-ruby.rb, line 114
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
# File lib/grit/git-ruby.rb, line 21
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
# File lib/grit/git-ruby.rb, line 125
125: def file_index
126: @git_file_index ||= FileIndex.new(@git_dir)
127: end
# File lib/grit/git-ruby.rb, line 106
106: def file_size(ref)
107: try_run { ruby_git.cat_file_size(ref).to_s }
108: end
# File lib/grit/git-ruby.rb, line 110
110: def file_type(ref)
111: try_run { ruby_git.cat_file_type(ref).to_s }
112: end
# File lib/grit/git-ruby.rb, line 13
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
# File lib/grit/git-ruby.rb, line 46
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
# File lib/grit/git-ruby.rb, line 68
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