Class: Grit::GitRuby::Commit

Inherits:
GitObject show all
Defined in:
lib/grit/git-ruby/git_object.rb

Instance Attribute Summary collapse

Attributes inherited from GitObject

#repository, #sha

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from GitObject

#sha1

Constructor Details

#initialize(tree, parent, author, committer, message, headers, repository = nil) ⇒ Commit

Returns a new instance of Commit.



266
267
268
269
270
271
272
273
274
# File 'lib/grit/git-ruby/git_object.rb', line 266

def initialize(tree, parent, author, committer, message, headers, repository=nil)
  @tree = tree
  @author = author
  @parent = parent
  @committer = committer
  @message = message
  @headers = headers
  @repository = repository
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



240
241
242
# File 'lib/grit/git-ruby/git_object.rb', line 240

def author
  @author
end

#committerObject

Returns the value of attribute committer.



240
241
242
# File 'lib/grit/git-ruby/git_object.rb', line 240

def committer
  @committer
end

#headersObject

Returns the value of attribute headers.



240
241
242
# File 'lib/grit/git-ruby/git_object.rb', line 240

def headers
  @headers
end

#messageObject

Returns the value of attribute message.



240
241
242
# File 'lib/grit/git-ruby/git_object.rb', line 240

def message
  @message
end

#parentObject

Returns the value of attribute parent.



240
241
242
# File 'lib/grit/git-ruby/git_object.rb', line 240

def parent
  @parent
end

#treeObject

Returns the value of attribute tree.



240
241
242
# File 'lib/grit/git-ruby/git_object.rb', line 240

def tree
  @tree
end

Class Method Details

.from_raw(rawobject, repository = nil) ⇒ Object



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/grit/git-ruby/git_object.rb', line 242

def self.from_raw(rawobject, repository=nil)
  parent = []
  tree = author = committer = nil

  headers, message = rawobject.content.split(/\n\n/, 2)
  all_headers = headers.split(/\n/).map { |header| header.split(/ /, 2) }
  all_headers.each do |key, value|
    case key
    when "tree"
      tree = value
    when "parent"
      parent.push(value)
    when "author"
      author = UserInfo.new(value)
    when "committer"
      committer = UserInfo.new(value)
    end
  end
  if not tree && author && committer
    raise RuntimeError, "incomplete raw commit object"
  end
  new(tree, parent, author, committer, message, headers, repository)
end

Instance Method Details

#raw_contentObject



280
281
282
283
284
285
# File 'lib/grit/git-ruby/git_object.rb', line 280

def raw_content
  "tree %s\n%sauthor %s\ncommitter %s\n\n" % [
    @tree,
    @parent.collect { |i| "parent %s\n" % i }.join,
    @author, @committer] + @message
end

#raw_log(sha) ⇒ Object



287
288
289
290
291
# File 'lib/grit/git-ruby/git_object.rb', line 287

def raw_log(sha)
  output = "commit #{sha}\n"
  output += @headers + "\n\n"
  output += @message.split("\n").map { |l| '    ' + l }.join("\n") + "\n\n"
end

#typeObject



276
277
278
# File 'lib/grit/git-ruby/git_object.rb', line 276

def type
  :commit
end