Module Grit::GitRuby
In: lib/grit/git-ruby/file_index.rb
lib/grit/git-ruby/git_object.rb
lib/grit/git-ruby/internal/file_window.rb
lib/grit/git-ruby/internal/loose.rb
lib/grit/git-ruby/internal/pack.rb
lib/grit/git-ruby/internal/raw_object.rb
lib/grit/git-ruby/object.rb
lib/grit/git-ruby/repository.rb
lib/grit/git-ruby.rb

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!!)

Methods

Classes and Modules

Module Grit::GitRuby::Internal
Class Grit::GitRuby::Blob
Class Grit::GitRuby::Commit
Class Grit::GitRuby::DirectoryEntry
Class Grit::GitRuby::FileIndex
Class Grit::GitRuby::GitObject
Class Grit::GitRuby::Object
Class Grit::GitRuby::Repository
Class Grit::GitRuby::Tag
Class Grit::GitRuby::Tree
Class Grit::GitRuby::UserInfo

Attributes

git_file_index  [RW] 
ruby_git_repo  [RW] 

Public Class methods

[Source]

# File 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

[Source]

# File lib/grit/git-ruby/git_object.rb, line 180
  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

Public Instance methods

[Source]

# File lib/grit/git-ruby.rb, line 114
    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

[Source]

# File lib/grit/git-ruby.rb, line 21
    def cat_file(options, ref)
      if options[:t]
        file_type(ref)
      elsif options[:s]
        file_size(ref)
      elsif options[:p]
        try_run { ruby_git.cat_file(ref) }
      end
    rescue Grit::GitRuby::Repository::NoSuchShaFound
      ''
    end

git diff —full-index ‘ec037431382e83c3e95d4f2b3d145afbac8ea55d’ ‘f1ec1aea10986159456846b8a05615b87828d6c6‘

[Source]

# File lib/grit/git-ruby.rb, line 42
    def diff(options, sha1, sha2)
      try_run { ruby_git.diff(sha1, sha2, options) }
    end

[Source]

# File lib/grit/git-ruby.rb, line 125
    def file_index
      @git_file_index ||= FileIndex.new(@git_dir)
    end

[Source]

# File lib/grit/git-ruby.rb, line 106
    def file_size(ref)
      try_run { ruby_git.cat_file_size(ref).to_s }
    end

[Source]

# File lib/grit/git-ruby.rb, line 110
    def file_type(ref)
      try_run { ruby_git.cat_file_type(ref).to_s }
    end

[Source]

# File lib/grit/git-ruby.rb, line 13
    def init(options)
      if options.size == 0
        Grit::GitRuby::Repository.init(@git_dir)
      else
        method_missing('init', options) 
      end
    end

lib/grit/tree.rb:16: output = repo.git.ls_tree({}, treeish, *paths)

[Source]

# File lib/grit/git-ruby.rb, line 34
    def ls_tree(options, treeish, *paths)
      sha = rev_parse({}, treeish)
      ruby_git.ls_tree(sha, paths.flatten)
    rescue Grit::GitRuby::Repository::NoSuchShaFound
      ''
    end

[Source]

# File lib/grit/git-ruby.rb, line 46
    def rev_list(options, ref = 'master')
      options.delete(:skip) if options[:skip].to_i == 0
      allowed_options = [:max_count, :since, :until, :pretty]  # this is all I can do right now
      if ((options.keys - allowed_options).size > 0)
        return method_missing('rev-list', options, ref)
      elsif (options.size == 0)
        # pure rev-list
        begin
          return file_index.commits_from(rev_parse({}, ref)).join("\n") + "\n"
        rescue
          return method_missing('rev-list', options, ref) 
        end
      else
        aref = rev_parse({}, ref)
        if aref.is_a? Array
          return method_missing('rev-list', options, ref) 
        else
          return try_run { ruby_git.rev_list(aref, options) }
        end
      end
    end

[Source]

# File lib/grit/git-ruby.rb, line 68
    def rev_parse(options, 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

[Source]

# File lib/grit/git-ruby.rb, line 129
    def ruby_git
      @ruby_git_repo ||= Repository.new(@git_dir)
    end

[Validate]