Class: Gitlab::Git::Diff
- Inherits:
-
Object
- Object
- Gitlab::Git::Diff
- Defined in:
- lib/gitlab_git/diff.rb
Defined Under Namespace
Classes: TimeoutError
Instance Attribute Summary collapse
-
#a_mode ⇒ Object
Diff properties.
-
#b_mode ⇒ Object
Diff properties.
-
#deleted_file ⇒ Object
Stats properties.
-
#diff ⇒ Object
Diff properties.
-
#new_file ⇒ Object
Stats properties.
-
#new_path ⇒ Object
Diff properties.
-
#old_path ⇒ Object
Diff properties.
-
#raw_diff ⇒ Object
Returns the value of attribute raw_diff.
-
#renamed_file ⇒ Object
Stats properties.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(raw_diff) ⇒ Diff
constructor
A new instance of Diff.
- #serialize_keys ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(raw_diff) ⇒ Diff
Returns a new instance of Diff.
32 33 34 35 36 37 38 39 40 |
# 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 |
Instance Attribute Details
#a_mode ⇒ Object
Diff properties
12 13 14 |
# File 'lib/gitlab_git/diff.rb', line 12 def a_mode @a_mode end |
#b_mode ⇒ Object
Diff properties
12 13 14 |
# File 'lib/gitlab_git/diff.rb', line 12 def b_mode @b_mode end |
#deleted_file ⇒ Object
Stats properties
15 16 17 |
# File 'lib/gitlab_git/diff.rb', line 15 def deleted_file @deleted_file end |
#diff ⇒ Object
Diff properties
12 13 14 |
# File 'lib/gitlab_git/diff.rb', line 12 def diff @diff end |
#new_file ⇒ Object
Stats properties
15 16 17 |
# File 'lib/gitlab_git/diff.rb', line 15 def new_file @new_file end |
#new_path ⇒ Object
Diff properties
12 13 14 |
# File 'lib/gitlab_git/diff.rb', line 12 def new_path @new_path end |
#old_path ⇒ Object
Diff properties
12 13 14 |
# File 'lib/gitlab_git/diff.rb', line 12 def old_path @old_path end |
#raw_diff ⇒ Object
Returns the value of attribute raw_diff.
9 10 11 |
# File 'lib/gitlab_git/diff.rb', line 9 def raw_diff @raw_diff end |
#renamed_file ⇒ Object
Stats properties
15 16 17 |
# File 'lib/gitlab_git/diff.rb', line 15 def renamed_file @renamed_file end |
Class Method Details
.between(repo, head, base, *paths) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gitlab_git/diff.rb', line 18 def between(repo, head, base, *paths) # 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(head, base) repo.diff(common_commit, head, *paths).map do |diff| Gitlab::Git::Diff.new(diff) end rescue Grit::Git::GitTimeout raise TimeoutError.new("Diff.between exited with timeout") end |
Instance Method Details
#serialize_keys ⇒ Object
42 43 44 |
# 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 ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# 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 |