Sha256: 20228b81e9b18315cc05bb66d9c38257ca29bb6fd135ab9e773c1207aae8bfff

Contents?: true

Size: 1.4 KB

Versions: 46

Compression:

Stored size: 1.4 KB

Contents

module Gitlab
  module Git
    class Compare
      attr_reader :commits, :diffs, :same, :timeout, :head, :base

      def initialize(repository, base, head)
        @commits, @diffs = [], []
        @same = false
        @repository = repository
        @timeout = false

        return unless base && head

        @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

        @commits = Gitlab::Git::Commit.between(repository, @base.id, @head.id)
      end

      def diffs(paths = nil, options = {})
        unless @head && @base
          return []
        end

        # 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,
                                               options, *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
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
gitlab_git-8.2.0 lib/gitlab_git/compare.rb
gitlab_git-8.1.0 lib/gitlab_git/compare.rb
gitlab_git-8.0.0 lib/gitlab_git/compare.rb
gitlab_git-7.2.24 lib/gitlab_git/compare.rb
gitlab_git-7.2.23 lib/gitlab_git/compare.rb
gitlab_git-7.2.22 lib/gitlab_git/compare.rb
gitlab_git-7.2.21 lib/gitlab_git/compare.rb
gitlab_git-7.2.20 lib/gitlab_git/compare.rb
gitlab_git-7.2.19 lib/gitlab_git/compare.rb
gitlab_git-7.2.18 lib/gitlab_git/compare.rb
gitlab_git-7.2.17 lib/gitlab_git/compare.rb
gitlab_git-7.2.16 lib/gitlab_git/compare.rb
gitlab_git-7.2.15 lib/gitlab_git/compare.rb
gitlab_git-7.2.14 lib/gitlab_git/compare.rb
gitlab_git-7.2.13 lib/gitlab_git/compare.rb
gitlab_git-7.2.12 lib/gitlab_git/compare.rb
gitlab_git-7.2.11 lib/gitlab_git/compare.rb
gitlab_git-7.2.10 lib/gitlab_git/compare.rb
gitlab_git-7.2.9 lib/gitlab_git/compare.rb
gitlab_git-7.2.8 lib/gitlab_git/compare.rb