Sha256: 683a1e81d50f13fe3a33265f782cbc84925f42d8ad473e00105b1f7b562dac94
Contents?: true
Size: 1.56 KB
Versions: 9
Compression:
Stored size: 1.56 KB
Contents
module Gitlab module Git class Compare attr_accessor :commits, :commit, :diffs, :same, :limit, :timeout def initialize(repository, from, to, limit = 100) @commits, @diffs = [], [] @commit = nil @same = false @limit = limit @repository = repository @timeout = false return unless from && to @base = Gitlab::Git::Commit.find(repository, from.try(:strip)) @head = Gitlab::Git::Commit.find(repository, to.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? # Try to collect diff only if diffs is empty # Otherwise return cached version if @diffs.empty? && @timeout == false begin @diffs = Gitlab::Git::Diff.between(@repository, @head.id, @base.id, *paths) rescue Gitlab::Git::Diff::TimeoutError => ex @diffs = [] @timeout = true end end @diffs 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 end end end end
Version data entries
9 entries across 9 versions & 1 rubygems