Commit bb06e905efb1722502d71059c21add8cfde851aa

Authored by Dmitriy Zaporozhets
1 parent 51c16755

added Gitlab::Git::Compare for git compare feature

Showing 1 changed file with 37 additions and 0 deletions   Show diff stats
lib/gitlab/git/compare.rb 0 → 100644
@@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
  1 +module Gitlab
  2 + module Git
  3 + class Compare
  4 + attr_accessor :commits, :commit, :diffs, :same
  5 +
  6 + def initialize(repository, from, to)
  7 + @commits, @diffs = [], []
  8 + @commit = nil
  9 + @same = false
  10 +
  11 + return unless from && to
  12 +
  13 + first = repository.commit(to.try(:strip))
  14 + last = repository.commit(from.try(:strip))
  15 +
  16 + return unless first && last
  17 +
  18 + if first.id == last.id
  19 + @same = true
  20 + return
  21 + end
  22 +
  23 + @commit = Commit.new(first)
  24 +
  25 + @commits = repository.commits_between(last.id, first.id)
  26 + @commits = @commits.map { |c| Commit.new(c) }
  27 +
  28 + @diffs = if @commits.size > 100
  29 + []
  30 + else
  31 + repository.repo.diff(last.id, first.id) rescue []
  32 + end
  33 + end
  34 + end
  35 + end
  36 +end
  37 +