Class: VCSToolkit::Objects::Commit
- Defined in:
- lib/vcs_toolkit/objects/commit.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#parents ⇒ Object
readonly
Returns the value of attribute parents.
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Attributes inherited from Object
Instance Method Summary collapse
- #common_ancestor(other_commit, object_store) ⇒ Object
-
#history(object_store) ⇒ Object
Enumerates all commits in the current commit’s history.
-
#history_diff(object_store) ⇒ Object
Enumerates commits in the current commit’s history.
-
#initialize(message:, tree:, parents:, author:, date:, id: nil, **context) ⇒ Commit
constructor
A new instance of Commit.
Methods inherited from Object
Methods included from Serializable
Methods included from Utils::HashableObject
Constructor Details
#initialize(message:, tree:, parents:, author:, date:, id: nil, **context) ⇒ Commit
Returns a new instance of Commit.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/vcs_toolkit/objects/commit.rb', line 10 def initialize(message:, tree:, parents:, author:, date:, id: nil, **context) @message = @tree = tree @parents = parents @author = @date = date super id: id, object_type: :commit, **context end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
6 7 8 |
# File 'lib/vcs_toolkit/objects/commit.rb', line 6 def @author end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
6 7 8 |
# File 'lib/vcs_toolkit/objects/commit.rb', line 6 def date @date end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
6 7 8 |
# File 'lib/vcs_toolkit/objects/commit.rb', line 6 def @message end |
#parents ⇒ Object (readonly)
Returns the value of attribute parents.
6 7 8 |
# File 'lib/vcs_toolkit/objects/commit.rb', line 6 def parents @parents end |
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
6 7 8 |
# File 'lib/vcs_toolkit/objects/commit.rb', line 6 def tree @tree end |
Instance Method Details
#common_ancestor(other_commit, object_store) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/vcs_toolkit/objects/commit.rb', line 65 def common_ancestor(other_commit, object_store) my_ancestors = history(object_store).to_set other_commit.enum_for(:history, object_store).find do |ancestor| my_ancestors.include? ancestor end end |
#history(object_store) ⇒ Object
Enumerates all commits in the current commit’s history. If a block is given each commit is yielded to it.
26 27 28 29 30 31 32 |
# File 'lib/vcs_toolkit/objects/commit.rb', line 26 def history(object_store) history_diff(object_store) do |commit| yield commit if block_given? false end end |
#history_diff(object_store) ⇒ Object
Enumerates commits in the current commit’s history.
Each commit is yielded and if the block result is a trueish value the commit’s parents are not enumerated.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/vcs_toolkit/objects/commit.rb', line 40 def history_diff(object_store) commits = {id => self} commit_queue = [self] until commit_queue.empty? commit = commit_queue.shift if yield commit commits.delete commit.id next end commit.parents.each do |parent_id| unless commits.key? parent_id parent = object_store.fetch parent_id commits[parent_id] = parent commit_queue << parent end end end commits.values end |