Skip to content

Instantly share code, notes, and snippets.

@jwreagor
Created July 1, 2010 14:04
Show Gist options
  • Save jwreagor/460000 to your computer and use it in GitHub Desktop.
Save jwreagor/460000 to your computer and use it in GitHub Desktop.
class Commit
attr_reader :id
lazy_reader :parents
lazy_reader :tree
lazy_reader :author
lazy_reader :authored_date
lazy_reader :committer
lazy_reader :committed_date
lazy_reader :message
lazy_reader :short_message
lazy_reader :author_string
# Instantiate a new Commit
# +id+ is the id of the commit
# +parents+ is an array of commit ids (will be converted into Commit instances)
# +tree+ is the correspdonding tree id (will be converted into a Tree object)
# +author+ is the author string
# +authored_date+ is the authored Time
# +committer+ is the committer string
# +committed_date+ is the committed Time
# +message+ is an array of commit message lines
#
# Returns Grit::Commit (baked)
def initialize(repo, id, parents, tree, author, authored_date, committer, committed_date, message)
@repo = repo
@id = id
@parents = parents.map { |p| Commit.create(repo, :id => p) }
@tree = Tree.create(repo, :id => tree)
@author = author
@authored_date = authored_date
@committer = committer
@committed_date = committed_date
@message = message.join("\n")
@short_message = message.select { |x| !x.strip.empty? }[0] || ''
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment