Class: Metior::Commit Abstract
- Includes:
- AutoIncludeVCS
- Defined in:
- lib/metior/commit.rb
Overview
It has to be subclassed to implement a commit representation for a specific VCS.
This class represents a commit in a source code repository
Although not all VCSs distinguish authors from committers this implementation forces a differentiation between the both.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#author ⇒ Actor
This commit's author.
-
#authored_date ⇒ Time
readonly
The date this commit has been authored.
-
#children ⇒ Array<Object>
readonly
The unique identifiers of the children of this commit.
-
#committed_date ⇒ Time
readonly
The date this commit has been committed.
-
#committer ⇒ Actor
This commit's committer.
-
#id ⇒ Object
readonly
A unique identifier of the commit in the repository.
-
#message ⇒ String
readonly
The commit message of this commit.
-
#parents ⇒ Array<Object>
readonly
The unique identifiers of one or more more parents of this commit.
-
#repo ⇒ Repository
readonly
The repository this commit belongs to.
Instance Method Summary collapse
-
#add_child(child) ⇒ Object
Adds the unique identifier of a child of this commit to the list of child commits.
-
#added_files ⇒ Array<String>
Returns the paths of all files that have been modified in this commit.
-
#additions ⇒ Fixnum
Returnes the number of lines of code added in this commit.
-
#deleted_files ⇒ Array<String>
Returns the paths of all files that have been modified in this commit.
-
#deletions ⇒ Fixnum
Returnes the number of lines of code deleted in this commit.
-
#initialize(repo) ⇒ Commit
constructor
Creates a new commit instance linked to the given repository and branch.
-
#inspect ⇒ String
Creates a string representation for this commit without recursing into actor and repository details.
-
#load_file_stats ⇒ Object
protected
abstract
Loads the file stats for this commit from the repository.
-
#load_line_stats ⇒ Object
protected
abstract
Loads the line stats for this commit from the repository.
-
#merge? ⇒ Boolean
Returns whether this commits is a merge commit.
-
#modifications ⇒ Fixnum
Returns the total of changed lines in this commit.
-
#modified_files ⇒ Array<String>
Returns the paths of all files that have been modified in this commit.
-
#subject ⇒ String
Returns the subject line of the commit message, i.e.
Methods included from AutoIncludeVCS
Constructor Details
#initialize(repo) ⇒ Commit
Creates a new commit instance linked to the given repository and branch
54 55 56 57 58 59 60 61 62 |
# File 'lib/metior/commit.rb', line 54 def initialize(repo) @additions = nil @added_files = nil @children = [] @deletions = nil @deleted_files = nil @modified_files = nil @repo = repo end |
Instance Attribute Details
#author ⇒ Actor
Returns This commit's author.
23 24 25 |
# File 'lib/metior/commit.rb', line 23 def @author end |
#authored_date ⇒ Time (readonly)
Returns The date this commit has been authored.
26 27 28 |
# File 'lib/metior/commit.rb', line 26 def @authored_date end |
#children ⇒ Array<Object> (readonly)
Returns The unique identifiers of the children of this commit.
33 34 35 |
# File 'lib/metior/commit.rb', line 33 def children @children end |
#committed_date ⇒ Time (readonly)
Returns The date this commit has been committed.
36 37 38 |
# File 'lib/metior/commit.rb', line 36 def committed_date @committed_date end |
#committer ⇒ Actor
Returns This commit's committer.
39 40 41 |
# File 'lib/metior/commit.rb', line 39 def committer @committer end |
#id ⇒ Object (readonly)
Returns A unique identifier of the commit in the repository.
29 30 31 |
# File 'lib/metior/commit.rb', line 29 def id @id end |
#message ⇒ String (readonly)
Returns The commit message of this commit.
42 43 44 |
# File 'lib/metior/commit.rb', line 42 def @message end |
#parents ⇒ Array<Object> (readonly)
Returns The unique identifiers of one or more more parents of this commit.
46 47 48 |
# File 'lib/metior/commit.rb', line 46 def parents @parents end |
#repo ⇒ Repository (readonly)
Returns The repository this commit belongs to.
49 50 51 |
# File 'lib/metior/commit.rb', line 49 def repo @repo end |
Instance Method Details
#add_child(child) ⇒ Object
Adds the unique identifier of a child of this commit to the list of child commits
80 81 82 |
# File 'lib/metior/commit.rb', line 80 def add_child(child) @children << child end |
#added_files ⇒ Array<String>
Returns the paths of all files that have been modified in this commit
This will load the file stats from the repository if not done yet.
90 91 92 93 |
# File 'lib/metior/commit.rb', line 90 def added_files load_file_stats if @added_files.nil? @added_files end |
#additions ⇒ Fixnum
Returnes the number of lines of code added in this commit
99 100 101 102 |
# File 'lib/metior/commit.rb', line 99 def additions load_line_stats if @additions.nil? @additions end |
#deleted_files ⇒ Array<String>
Returns the paths of all files that have been modified in this commit
This will load the file stats from the repository if not done yet.
122 123 124 125 |
# File 'lib/metior/commit.rb', line 122 def deleted_files load_file_stats if @deleted_files.nil? @deleted_files end |
#deletions ⇒ Fixnum
Returnes the number of lines of code deleted in this commit
131 132 133 134 |
# File 'lib/metior/commit.rb', line 131 def deletions load_line_stats if @deletions.nil? @deletions end |
#inspect ⇒ String
Creates a string representation for this commit without recursing into actor and repository details
172 173 174 175 176 177 178 |
# File 'lib/metior/commit.rb', line 172 def inspect '#<%s:0x%x: @author="%s" @committer="%s" @id="%s" @repo="%s" @subject="%s">' % [ self.class.name, __id__ * 2, @author.id, @committer.id, @id, @repo.path, subject ] end |
#load_file_stats ⇒ Object (protected)
Has to be implemented by VCS specific subclasses
Loads the file stats for this commit from the repository
185 186 187 |
# File 'lib/metior/commit.rb', line 185 def load_file_stats raise NotImplementedError end |
#load_line_stats ⇒ Object (protected)
Has to be implemented by VCS specific subclasses
Loads the line stats for this commit from the repository
192 193 194 |
# File 'lib/metior/commit.rb', line 192 def load_line_stats raise NotImplementedError end |
#merge? ⇒ Boolean
Returns whether this commits is a merge commit
139 140 141 |
# File 'lib/metior/commit.rb', line 139 def merge? @parents.size > 1 end |
#modifications ⇒ Fixnum
Returns the total of changed lines in this commit
146 147 148 |
# File 'lib/metior/commit.rb', line 146 def modifications additions + deletions end |
#modified_files ⇒ Array<String>
Returns the paths of all files that have been modified in this commit
This will load the file stats from the repository if not done yet.
156 157 158 159 |
# File 'lib/metior/commit.rb', line 156 def modified_files load_file_stats if @modified_files.nil? @modified_files end |
#subject ⇒ String
Returns the subject line of the commit message, i.e. the first line
164 165 166 |
# File 'lib/metior/commit.rb', line 164 def subject @message.split(/$/).first end |