Class: GitStore::Commit
- Inherits:
-
Object
- Object
- GitStore::Commit
- Defined in:
- lib/git_store/commit.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#committer ⇒ Object
Returns the value of attribute committer.
-
#id ⇒ Object
Returns the value of attribute id.
-
#message ⇒ Object
Returns the value of attribute message.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#store ⇒ Object
Returns the value of attribute store.
-
#tree ⇒ Object
Returns the value of attribute tree.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #diff(commit, path = nil) ⇒ Object
- #diffs(path = nil) ⇒ Object
- #dump ⇒ Object
-
#initialize(store, id = nil, data = nil) ⇒ Commit
constructor
A new instance of Commit.
- #parse(data) ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(store, id = nil, data = nil) ⇒ Commit
Returns a new instance of Commit.
6 7 8 9 10 11 12 |
# File 'lib/git_store/commit.rb', line 6 def initialize(store, id = nil, data = nil) @store = store @id = id @parent = [] parse(data) if data end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
4 5 6 |
# File 'lib/git_store/commit.rb', line 4 def @author end |
#committer ⇒ Object
Returns the value of attribute committer.
4 5 6 |
# File 'lib/git_store/commit.rb', line 4 def committer @committer end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/git_store/commit.rb', line 4 def id @id end |
#message ⇒ Object
Returns the value of attribute message.
4 5 6 |
# File 'lib/git_store/commit.rb', line 4 def @message end |
#parent ⇒ Object
Returns the value of attribute parent.
4 5 6 |
# File 'lib/git_store/commit.rb', line 4 def parent @parent end |
#store ⇒ Object
Returns the value of attribute store.
4 5 6 |
# File 'lib/git_store/commit.rb', line 4 def store @store end |
#tree ⇒ Object
Returns the value of attribute tree.
4 5 6 |
# File 'lib/git_store/commit.rb', line 4 def tree @tree end |
Instance Method Details
#==(other) ⇒ Object
14 15 16 |
# File 'lib/git_store/commit.rb', line 14 def ==(other) Commit === other and id == other.id end |
#diff(commit, path = nil) ⇒ Object
41 42 43 44 |
# File 'lib/git_store/commit.rb', line 41 def diff(commit, path = nil) commit = commit.id if Commit === commit Diff.exec(store, "git diff --full-index #{commit} #{id} -- '#{path}'") end |
#diffs(path = nil) ⇒ Object
46 47 48 |
# File 'lib/git_store/commit.rb', line 46 def diffs(path = nil) diff(parent.first, path) end |
#dump ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/git_store/commit.rb', line 54 def dump [ "tree #{ tree.id }", parent.map { |parent| "parent #{parent}" }, "author #{ .dump }", "committer #{ committer.dump }", '', ].flatten.join("\n") end |
#parse(data) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/git_store/commit.rb', line 18 def parse(data) headers, @message = data.split(/\n\n/, 2) headers.split(/\n/).each do |header| key, value = header.split(/ /, 2) case key when 'parent' @parent << value when 'author' @author = User.parse(value) when 'committer' @committer = User.parse(value) when 'tree' @tree = store.get(value) end end self end |
#write ⇒ Object
50 51 52 |
# File 'lib/git_store/commit.rb', line 50 def write @id = store.put(self) end |