lib/grit/git-ruby/git_object.rb in schacon-grit-0.9.4 vs lib/grit/git-ruby/git_object.rb in schacon-grit-1.1.1
- old
+ new
@@ -113,11 +113,11 @@
S_IFGITLINK = 0160000
attr_accessor :mode, :name, :sha1
def initialize(mode, filename, sha1o)
@mode = 0
mode.each_byte do |i|
- @mode = (@mode << 3) | (i-'0'[0])
+ @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"
@@ -177,12 +177,18 @@
end
def self.read_bytes_until(io, char)
string = ''
- while ((next_char = io.getc.chr) != char) && !io.eof
- string += next_char
+ 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
@@ -217,10 +223,20 @@
# TODO: sort correctly
#@entry.sort { |a,b| a.name <=> b.name }.
@entry.collect { |e| [[e.format_mode, e.format_type, e.sha1].join(' '), e.name].join("\t") }.join("\n")
end
+ def to_hash
+ hash = {}
+ @entry.each do |e|
+ hash[e.name] = { 'mode' => e.format_mode,
+ 'type' => e.format_type,
+ 'sha' => e.sha1 }
+ end
+ hash
+ end
+
def actual_raw
#@entry.collect { |e| e.raw.join(' '), e.name].join("\t") }.join("\n")
end
end
@@ -241,13 +257,10 @@
parent.push(value)
when "author"
author = UserInfo.new(value)
when "committer"
committer = UserInfo.new(value)
- else
- warn "unknown header '%s' in commit %s" % \
- [key, rawobject.sha1.unpack("H*")[0]]
end
end
if not tree && author && committer
raise RuntimeError, "incomplete raw commit object"
end
@@ -277,9 +290,19 @@
def raw_log(sha)
output = "commit #{sha}\n"
output += @headers + "\n\n"
output += @message.split("\n").map { |l| ' ' + l }.join("\n") + "\n\n"
+ end
+
+ def to_hash
+ h = {}
+ h['tree'] = @tree
+ h['author'] = @author
+ h['committer'] = @committer
+ h['message'] = @message
+ h['parents'] = @parent
+ h
end
end
class Tag < GitObject