class Gitlab::Git::Diff

Constants

BROKEN_DIFF

Attributes

a_mode[RW]

Diff properties

b_mode[RW]

Diff properties

deleted_file[RW]

Stats properties

diff[RW]

Diff properties

new_file[RW]

Stats properties

new_path[RW]

Diff properties

old_path[RW]

Diff properties

raw_diff[RW]
renamed_file[RW]

Stats properties

Public Class Methods

between(repo, from, to) click to toggle source
# File lib/gitlab_git/diff.rb, line 18
def between(repo, from, to)
  # Only show what is new in the source branch compared to the target branch, not the other way around.
  # The linex below with merge_base is equivalent to diff with three dots (git diff branch1...branch2)
  # From the git documentation: "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B"
  common_commit = repo.merge_base_commit(from, to)

  repo.diff(common_commit, from).map do |diff|
    Gitlab::Git::Diff.new(diff)
  end
rescue Grit::Git::GitTimeout
  [Gitlab::Git::Diff::BROKEN_DIFF]
end
new(raw_diff) click to toggle source
# File lib/gitlab_git/diff.rb, line 32
def initialize(raw_diff)
  raise "Nil as raw diff passed" unless raw_diff

  if raw_diff.is_a?(Hash)
    init_from_hash(raw_diff)
  else
    init_from_grit(raw_diff)
  end
end

Public Instance Methods

serialize_keys() click to toggle source
# File lib/gitlab_git/diff.rb, line 42
def serialize_keys
  @serialize_keys ||= %w(diff new_path old_path a_mode b_mode new_file renamed_file deleted_file).map(&:to_sym)
end
to_hash() click to toggle source
# File lib/gitlab_git/diff.rb, line 46
def to_hash
  hash = {}

  keys = serialize_keys

  keys.each do |key|
    hash[key] = send(key)
  end

  hash
end

Private Instance Methods

init_from_grit(grit) click to toggle source
# File lib/gitlab_git/diff.rb, line 60
def init_from_grit(grit)
  @raw_diff = grit

  serialize_keys.each do |key|
    send(:"#{key}=", grit.send(key))
  end
end
init_from_hash(hash) click to toggle source
# File lib/gitlab_git/diff.rb, line 68
def init_from_hash(hash)
  raw_diff = hash.symbolize_keys

  serialize_keys.each do |key|
    send(:"#{key}=", raw_diff[key.to_sym])
  end
end