class Grit::GitRuby::DirectoryEntry
Constants
- S_IFDIR
- S_IFGITLINK
- S_IFLNK
- S_IFMT
- S_IFREG
Attributes
mode[RW]
name[RW]
sha1[RW]
Public Class Methods
new(mode, filename, sha1o)
click to toggle source
# File lib/grit/git-ruby/git_object.rb, line 116 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
Public Instance Methods
format_mode()
click to toggle source
# File lib/grit/git-ruby/git_object.rb, line 176 def format_mode "%06o" % @mode end
format_type()
click to toggle source
# File lib/grit/git-ruby/git_object.rb, line 163 def format_type case type when :link 'link' when :directory 'tree' when :file 'blob' when :submodule 'commit' end end
raw()
click to toggle source
# File lib/grit/git-ruby/git_object.rb, line 180 def raw "%o %s\0%s" % [@mode, @name, [@sha1].pack("H*")] end
safe_name()
click to toggle source
Filenames can have weird characters that throw grit's text parsing
# File lib/grit/git-ruby/git_object.rb, line 129 def safe_name name.gsub(/[\r\n\0]/, '') end
type()
click to toggle source
# File lib/grit/git-ruby/git_object.rb, line 133 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
type=(type)
click to toggle source
# File lib/grit/git-ruby/git_object.rb, line 148 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