Module: Grit::GitRuby
- Included in:
- Git
- Defined in:
- lib/grit/lib/grit/git-ruby.rb,
lib/grit/lib/grit/git-ruby/object.rb,
lib/grit/lib/grit/git-ruby/file_index.rb,
lib/grit/lib/grit/git-ruby/git_object.rb,
lib/grit/lib/grit/git-ruby/repository.rb,
lib/grit/lib/grit/git-ruby/internal/pack.rb,
lib/grit/lib/grit/git-ruby/internal/loose.rb,
lib/grit/lib/grit/git-ruby/internal/raw_object.rb,
lib/grit/lib/grit/git-ruby/internal/file_window.rb
Overview
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!!)
Defined Under Namespace
Modules: Internal Classes: Blob, Commit, DirectoryEntry, FileIndex, GitObject, Object, Repository, Tag, Tree, UserInfo
Instance Attribute Summary collapse
-
#git_file_index ⇒ Object
Returns the value of attribute git_file_index.
-
#ruby_git_repo ⇒ Object
Returns the value of attribute ruby_git_repo.
Class Method Summary collapse
Instance Method Summary collapse
- #blame_tree(commit, path = nil) ⇒ Object
- #cat_file(options, ref) ⇒ Object
-
#diff(options, sha1, sha2 = nil) ⇒ Object
git diff –full-index ‘ec037431382e83c3e95d4f2b3d145afbac8ea55d’ ‘f1ec1aea10986159456846b8a05615b87828d6c6’.
- #file_index ⇒ Object
- #file_size(ref) ⇒ Object
- #file_type(ref) ⇒ Object
- #init(options) ⇒ Object
-
#ls_tree(options, treeish, *paths) ⇒ Object
lib/grit/tree.rb:16: output = repo.git.ls_tree({}, treeish, *paths).
- #refs(options, prefix) ⇒ Object
- #rev_list(options, ref = 'master') ⇒ Object
- #rev_parse(options, string) ⇒ Object
- #ruby_git ⇒ Object
- #tags(options, prefix) ⇒ Object
Instance Attribute Details
#git_file_index ⇒ Object
Returns the value of attribute git_file_index.
11 12 13 |
# File 'lib/grit/lib/grit/git-ruby.rb', line 11 def git_file_index @git_file_index end |
#ruby_git_repo ⇒ Object
Returns the value of attribute ruby_git_repo.
11 12 13 |
# File 'lib/grit/lib/grit/git-ruby.rb', line 11 def ruby_git_repo @ruby_git_repo end |
Class Method Details
.read_bytes_until(io, char) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/grit/lib/grit/git-ruby/object.rb', line 164 def self.read_bytes_until(io, char) string = '' if RUBY_VERSION > '1.9' while ((next_char = io.getc) != char) && !io.eof string += next_char end else while ((next_char = io.getc.chr) != char) && !io.eof string += next_char end end string end |
Instance Method Details
#blame_tree(commit, path = nil) ⇒ Object
195 196 197 198 199 200 201 202 203 204 |
# File 'lib/grit/lib/grit/git-ruby.rb', line 195 def blame_tree(commit, path = nil) begin path = [path].join('/').to_s + '/' if (path && path != '') path = '' if !path.is_a? String commits = file_index.last_commits(rev_parse({}, commit), looking_for(commit, path)) clean_paths(commits) rescue FileIndex::IndexFileNotFound {} end end |
#cat_file(options, ref) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/grit/lib/grit/git-ruby.rb', line 21 def cat_file(, ref) if [:t] file_type(ref) elsif [:s] file_size(ref) elsif [:p] try_run { ruby_git.cat_file(ref) } end rescue Grit::GitRuby::Repository::NoSuchShaFound '' end |
#diff(options, sha1, sha2 = nil) ⇒ Object
git diff –full-index ‘ec037431382e83c3e95d4f2b3d145afbac8ea55d’ ‘f1ec1aea10986159456846b8a05615b87828d6c6’
42 43 44 |
# File 'lib/grit/lib/grit/git-ruby.rb', line 42 def diff(, sha1, sha2 = nil) try_run { ruby_git.diff(sha1, sha2, ) } end |
#file_index ⇒ Object
206 207 208 |
# File 'lib/grit/lib/grit/git-ruby.rb', line 206 def file_index @git_file_index ||= FileIndex.new(@git_dir) end |
#file_size(ref) ⇒ Object
187 188 189 |
# File 'lib/grit/lib/grit/git-ruby.rb', line 187 def file_size(ref) try_run { ruby_git.cat_file_size(ref).to_s } end |
#file_type(ref) ⇒ Object
191 192 193 |
# File 'lib/grit/lib/grit/git-ruby.rb', line 191 def file_type(ref) try_run { ruby_git.cat_file_type(ref).to_s } end |
#init(options) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/grit/lib/grit/git-ruby.rb', line 13 def init() if .size == 0 Grit::GitRuby::Repository.init(@git_dir) else method_missing('init', ) end end |
#ls_tree(options, treeish, *paths) ⇒ Object
lib/grit/tree.rb:16: output = repo.git.ls_tree({}, treeish, *paths)
34 35 36 37 38 39 |
# File 'lib/grit/lib/grit/git-ruby.rb', line 34 def ls_tree(, treeish, *paths) sha = rev_parse({}, treeish) ruby_git.ls_tree(sha, paths.flatten, .delete(:r)) rescue Grit::GitRuby::Repository::NoSuchShaFound '' end |
#refs(options, prefix) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/grit/lib/grit/git-ruby.rb', line 106 def refs(, prefix) refs = [] already = {} Dir.chdir(@git_dir) do files = Dir.glob(prefix + '/**/*') files.each do |ref| next if !File.file?(ref) id = File.read(ref).chomp name = ref.sub("#{prefix}/", '') if !already[name] refs << "#{name} #{id}" already[name] = true end end if File.file?('packed-refs') File.readlines('packed-refs').each do |line| if m = /^(\w{40}) (.*?)$/.match(line) next if !Regexp.new('^' + prefix).match(m[2]) name = m[2].sub("#{prefix}/", '') if !already[name] refs << "#{name} #{m[1]}" already[name] = true end end end end end refs.join("\n") end |
#rev_list(options, ref = 'master') ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/grit/lib/grit/git-ruby.rb', line 46 def rev_list(, ref = 'master') .delete(:skip) if [:skip].to_i == 0 = [:max_count, :since, :until, :pretty] # this is all I can do right now if ((.keys - ).size > 0) return method_missing('rev-list', , ref) elsif (.size == 0) # pure rev-list begin return file_index.commits_from(rev_parse({}, ref)).join("\n") + "\n" rescue return method_missing('rev-list', , ref) end else aref = rev_parse({}, ref) if aref.is_a? Array return method_missing('rev-list', , ref) else return try_run { ruby_git.rev_list(aref, ) } end end end |
#rev_parse(options, string) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/grit/lib/grit/git-ruby.rb', line 68 def rev_parse(, string) raise RuntimeError, "invalid string: #{string}" unless string.is_a?(String) if string =~ /\.\./ (sha1, sha2) = string.split('..') return [rev_parse({}, sha1), rev_parse({}, sha2)] end if /^[0-9a-f]{40}$/.match(string) # passing in a sha - just no-op it return string.chomp end head = File.join(@git_dir, 'refs', 'heads', string) return File.read(head).chomp if File.file?(head) head = File.join(@git_dir, 'refs', 'remotes', string) return File.read(head).chomp if File.file?(head) head = File.join(@git_dir, 'refs', 'tags', string) return File.read(head).chomp if File.file?(head) ## check packed-refs file, too packref = File.join(@git_dir, 'packed-refs') if File.file?(packref) File.readlines(packref).each do |line| if m = /^(\w{40}) refs\/.+?\/(.*?)$/.match(line) next if !Regexp.new(Regexp.escape(string) + '$').match(m[3]) return m[1].chomp end end end ## !! more - partials and such !! # revert to calling git - grr return method_missing('rev-parse', , string).chomp end |
#ruby_git ⇒ Object
210 211 212 |
# File 'lib/grit/lib/grit/git-ruby.rb', line 210 def ruby_git @ruby_git_repo ||= Repository.new(@git_dir) end |
#tags(options, prefix) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/grit/lib/grit/git-ruby.rb', line 138 def (, prefix) refs = [] already = {} Dir.chdir(repo.path) do files = Dir.glob(prefix + '/**/*') files.each do |ref| next if !File.file?(ref) id = File.read(ref).chomp name = ref.sub("#{prefix}/", '') if !already[name] refs << "#{name} #{id}" already[name] = true end end if File.file?('packed-refs') lines = File.readlines('packed-refs') lines.each_with_index do |line, i| if m = /^(\w{40}) (.*?)$/.match(line) next if !Regexp.new('^' + prefix).match(m[2]) name = m[2].sub("#{prefix}/", '') # Annotated tags in packed-refs include a reference # to the commit object on the following line. next_line = lines[i + 1] id = if next_line && next_line[0] == ?^ next_line[1..-1].chomp else m[1] end if !already[name] refs << "#{name} #{id}" already[name] = true end end end end end refs.join("\n") end |