Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
5f8f685b
Commit
5f8f685b
authored
Apr 15, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Init Gitlab::Git::Diff class
parent
a45e4721
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
0 deletions
+63
-0
lib/gitlab/git/diff.rb
lib/gitlab/git/diff.rb
+63
-0
No files found.
lib/gitlab/git/diff.rb
0 → 100644
View file @
5f8f685b
# Gitlab::Git::Diff is a wrapper around native Grit::Diff object
# We dont want to use grit objects inside app/
# It helps us easily migrate to rugged in future
module
Gitlab
module
Git
class
Diff
BROKEN_DIFF
=
"--broken-diff"
attr_accessor
:raw_diff
# Diff properties
attr_accessor
:old_path
,
:new_path
,
:a_mode
,
:b_mode
,
:diff
# Stats properties
attr_accessor
:new_file
,
:renamed_file
,
:deleted_file
def
initialize
(
raw_diff
,
head
=
nil
)
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
@head
=
head
end
def
serialize_keys
%w(diff new_path old_path a_mode b_mode new_file renamed_file deleted_file)
end
def
to_hash
hash
=
{}
keys
=
serialize_keys
keys
.
each
do
|
key
|
hash
[
key
]
=
send
(
key
)
end
hash
end
private
def
init_from_grit
(
grit
)
@raw_diff
=
grit
serialize_keys
.
each
do
|
key
|
send
(
:"
#{
key
}
="
,
grit
.
send
(
key
))
end
end
def
init_from_hash
(
hash
)
serialize_keys
.
each
do
|
key
|
send
(
:"
#{
key
}
="
,
hash
[
key
])
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment