Class: Gitlab::Git::Compare
- Inherits:
-
Object
- Object
- Gitlab::Git::Compare
- Defined in:
- lib/gitlab_git/compare.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#head ⇒ Object
readonly
Returns the value of attribute head.
-
#straight ⇒ Object
readonly
Returns the value of attribute straight.
Instance Method Summary collapse
- #commits ⇒ Object
- #diffs(options = {}) ⇒ Object
-
#initialize(repository, base, head, straight = false) ⇒ Compare
constructor
A new instance of Compare.
- #same ⇒ Object
Constructor Details
#initialize(repository, base, head, straight = false) ⇒ Compare
Returns a new instance of Compare.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/gitlab_git/compare.rb', line 6 def initialize(repository, base, head, straight = false) @repository = repository @straight = straight unless base && head @commits = [] return end @base = Gitlab::Git::Commit.find(repository, base.try(:strip)) @head = Gitlab::Git::Commit.find(repository, head.try(:strip)) @commits = [] unless @base && @head @commits = [] if same end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
4 5 6 |
# File 'lib/gitlab_git/compare.rb', line 4 def base @base end |
#head ⇒ Object (readonly)
Returns the value of attribute head.
4 5 6 |
# File 'lib/gitlab_git/compare.rb', line 4 def head @head end |
#straight ⇒ Object (readonly)
Returns the value of attribute straight.
4 5 6 |
# File 'lib/gitlab_git/compare.rb', line 4 def straight @straight end |
Instance Method Details
#commits ⇒ Object
26 27 28 29 30 |
# File 'lib/gitlab_git/compare.rb', line 26 def commits return @commits if defined?(@commits) @commits = Gitlab::Git::Commit.between(@repository, @base.id, @head.id) end |
#diffs(options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/gitlab_git/compare.rb', line 32 def diffs( = {}) unless @head && @base return Gitlab::Git::DiffCollection.new([]) end paths = .delete(:paths) || [] [:straight] = @straight Gitlab::Git::Diff.between(@repository, @head.id, @base.id, , *paths) end |
#same ⇒ Object
22 23 24 |
# File 'lib/gitlab_git/compare.rb', line 22 def same @base && @head && @base.id == @head.id end |