Sha256: 7baac1c8a3bfebf1bdc3b8de769393dd7018eadd3eaabf68c2a84c58e4547ace

Contents?: true

Size: 1.33 KB

Versions: 17

Compression:

Stored size: 1.33 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)
        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, *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

17 entries across 17 versions & 1 rubygems

Version Path
gitlab_git-6.2.2 lib/gitlab_git/compare.rb
gitlab_git-7.0.0.rc12 lib/gitlab_git/compare.rb
gitlab_git-7.0.0.rc11 lib/gitlab_git/compare.rb
gitlab_git-7.0.0.rc10 lib/gitlab_git/compare.rb
gitlab_git-7.0.0.rc9 lib/gitlab_git/compare.rb
gitlab_git-7.0.0.rc8 lib/gitlab_git/compare.rb
gitlab_git-7.0.0.rc7 lib/gitlab_git/compare.rb
gitlab_git-7.0.0.rc6 lib/gitlab_git/compare.rb
gitlab_git-7.0.0.rc5 lib/gitlab_git/compare.rb
gitlab_git-7.0.0.rc4 lib/gitlab_git/compare.rb
gitlab_git-7.0.0.rc3 lib/gitlab_git/compare.rb
gitlab_git-7.0.0.rc2 lib/gitlab_git/compare.rb
gitlab_git-7.0.0.rc1 lib/gitlab_git/compare.rb
gitlab_git-6.3.0 lib/gitlab_git/compare.rb
gitlab_git-6.2.1 lib/gitlab_git/compare.rb
gitlab_git-6.2.0 lib/gitlab_git/compare.rb
gitlab_git-6.1.0 lib/gitlab_git/compare.rb