lib/gitlab_git/compare.rb in gitlab_git-6.0.1 vs lib/gitlab_git/compare.rb in gitlab_git-6.1.0

- old
+ new

@@ -1,38 +1,35 @@ module Gitlab module Git class Compare - attr_accessor :commits, :commit, :diffs, :same, :limit, :timeout + attr_reader :commits, :diffs, :same, :timeout, :head, :base - def initialize(repository, from, to, limit = 100) + def initialize(repository, base, head) @commits, @diffs = [], [] - @commit = nil @same = false - @limit = limit @repository = repository @timeout = false - return unless from && to + return unless base && head - @base = Gitlab::Git::Commit.find(repository, from.try(:strip)) - @head = Gitlab::Git::Commit.find(repository, to.try(:strip)) + @base = Gitlab::Git::Commit.find(repository, base.try(:strip)) + @head = Gitlab::Git::Commit.find(repository, head.try(:strip)) return unless @base && @head if @base.id == @head.id @same = true return end - @commit = @head @commits = Gitlab::Git::Commit.between(repository, @base.id, @head.id) end def diffs(paths = nil) - # Return empty array if amount of commits - # more than specified limit - return [] if commits_over_limit? + unless @head && @base + return [] + end # Try to collect diff only if diffs is empty # Otherwise return cached version if @diffs.empty? && @timeout == false begin @@ -47,14 +44,10 @@ end # Check if diff is empty because it is actually empty # and not because its impossible to get it def empty_diff? - diffs.empty? && timeout == false && commits.size < limit - end - - def commits_over_limit? - commits.size > limit + diffs.empty? && timeout == false end end end end