Class Grit::GitRuby::DirectoryEntry
In: lib/grit/git-ruby/git_object.rb
lib/grit/git-ruby/object.rb
Parent: Object

Methods

format_mode   format_mode   format_type   format_type   new   new   raw   raw   type   type   type=   type=  

Constants

S_IFMT = 00170000
S_IFLNK = 0120000
S_IFREG = 0100000
S_IFDIR = 0040000
S_IFGITLINK = 0160000
S_IFMT = 00170000
S_IFLNK = 0120000
S_IFREG = 0100000
S_IFDIR = 0040000

Attributes

mode  [RW] 
mode  [RW] 
name  [RW] 
name  [RW] 
sha1  [RW] 
sha1  [RW] 

Public Class methods

[Source]

# File lib/grit/git-ruby/git_object.rb, line 115
    def initialize(mode, filename, sha1o)
      @mode = 0
      mode.each_byte do |i|
        @mode = (@mode << 3) | (i-'0'.getord(0))
      end
      @name = filename
      @sha1 = sha1o
      if ![S_IFLNK, S_IFDIR, S_IFREG, S_IFGITLINK].include?(@mode & S_IFMT)
        raise RuntimeError, "unknown type for directory entry"
      end
    end

[Source]

# File lib/grit/git-ruby/object.rb, line 105
    def initialize(mode, filename, sha1o)
      @mode = 0
      mode.each_byte do |i|
        @mode = (@mode << 3) | (i-'0'[0])
      end
      @name = filename
      @sha1 = sha1o
      if ![S_IFLNK, S_IFDIR, S_IFREG].include?(@mode & S_IFMT)
        raise RuntimeError, "unknown type for directory entry"
      end
    end

Public Instance methods

[Source]

# File lib/grit/git-ruby/git_object.rb, line 170
    def format_mode
      "%06o" % @mode
    end

[Source]

# File lib/grit/git-ruby/object.rb, line 154
    def format_mode
      "%06o" % @mode
    end

[Source]

# File lib/grit/git-ruby/git_object.rb, line 157
    def format_type
      case type
      when :link
        'link'
      when :directory
        'tree'
      when :file
        'blob'
      when :submodule
        'commit'
      end
    end

[Source]

# File lib/grit/git-ruby/object.rb, line 143
    def format_type
      case type
      when :link
        'link'
      when :directory
        'tree'
      when :file
        'blob'
      end
    end

[Source]

# File lib/grit/git-ruby/git_object.rb, line 174
    def raw
      "%o %s\0%s" % [@mode, @name, [@sha1].pack("H*")]
    end

[Source]

# File lib/grit/git-ruby/object.rb, line 158
    def raw
      "%o %s\0%s" % [@mode, @name, [@sha1].pack("H*")]
    end

[Source]

# File lib/grit/git-ruby/git_object.rb, line 127
    def type
      case @mode & S_IFMT
      when S_IFGITLINK
        @type = :submodule
      when S_IFLNK
        @type = :link
      when S_IFDIR
        @type = :directory
      when S_IFREG
        @type = :file
      else
        raise RuntimeError, "unknown type for directory entry"
      end
    end

[Source]

# File lib/grit/git-ruby/object.rb, line 117
    def type
      case @mode & S_IFMT
      when S_IFLNK
        @type = :link
      when S_IFDIR
        @type = :directory
      when S_IFREG
        @type = :file
      else
        raise RuntimeError, "unknown type for directory entry"
      end
    end

[Source]

# File lib/grit/git-ruby/object.rb, line 130
    def type=(type)
      case @type
      when :link
        @mode = (@mode & ~S_IFMT) | S_IFLNK
      when :directory
        @mode = (@mode & ~S_IFMT) | S_IFDIR
      when :file
        @mode = (@mode & ~S_IFMT) | S_IFREG
      else
        raise RuntimeError, "invalid type"
      end
    end

[Source]

# File lib/grit/git-ruby/git_object.rb, line 142
    def type=(type)
      case @type
      when :link
        @mode = (@mode & ~S_IFMT) | S_IFLNK
      when :directory
        @mode = (@mode & ~S_IFMT) | S_IFDIR
      when :file
        @mode = (@mode & ~S_IFMT) | S_IFREG
      when :submodule
        @mode = (@mode & ~S_IFMT) | S_IFGITLINK
      else
        raise RuntimeError, "invalid type"
      end
    end

[Validate]