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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
9fc0e11e
Commit
9fc0e11e
authored
Jun 20, 2016
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add DiffFile#blob and #old_blob
parent
17ab745e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
25 deletions
+31
-25
app/helpers/diff_helper.rb
app/helpers/diff_helper.rb
+3
-2
app/models/repository.rb
app/models/repository.rb
+0
-10
app/views/notify/repository_push_email.html.haml
app/views/notify/repository_push_email.html.haml
+2
-3
app/views/projects/diffs/_diffs.html.haml
app/views/projects/diffs/_diffs.html.haml
+2
-2
app/views/projects/diffs/_file.html.haml
app/views/projects/diffs/_file.html.haml
+3
-3
lib/gitlab/diff/file.rb
lib/gitlab/diff/file.rb
+21
-5
No files found.
app/helpers/diff_helper.rb
View file @
9fc0e11e
...
...
@@ -100,10 +100,11 @@ module DiffHelper
end
end
def
diff_file_html_data
(
project
,
diff_commit
,
diff_file
)
def
diff_file_html_data
(
project
,
diff_file
)
commit
=
diff_file
.
content_commit
||
commit_for_diff
(
diff_file
)
{
blob_diff_path:
namespace_project_blob_diff_path
(
project
.
namespace
,
project
,
tree_join
(
diff_
commit
.
id
,
diff_file
.
file_path
))
tree_join
(
commit
.
id
,
diff_file
.
file_path
))
}
end
...
...
app/models/repository.rb
View file @
9fc0e11e
...
...
@@ -653,16 +653,6 @@ class Repository
end
end
def
blob_for_diff
(
commit
,
diff
)
blob_at
(
commit
.
id
,
diff
.
file_path
)
end
def
prev_blob_for_diff
(
commit
,
diff
)
if
commit
.
parent_id
blob_at
(
commit
.
parent_id
,
diff
.
old_path
)
end
end
def
refs_contains_sha
(
ref_type
,
sha
)
args
=
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
#{
ref_type
}
--contains
#{
sha
}
)
names
=
Gitlab
::
Popen
.
popen
(
args
,
path_to_repo
).
first
...
...
app/views/notify/repository_push_email.html.haml
View file @
9fc0e11e
...
...
@@ -72,12 +72,11 @@
The
diff
for
this
file
was
not
included
because
it
is
too
large
.
-
else
%hr
-
diff_commit
=
diff_file
.
deleted_file
?
@message
.
diff_refs
.
first
:
@message
.
diff_refs
.
last
-
blob
=
@message
.
project
.
repository
.
blob_for_diff
(
diff_commit
,
diff_file
)
-
blob
=
diff_file
.
blob
-
if
blob
&&
blob
.
respond_to?
(
:text?
)
&&
blob_text_viewable?
(
blob
)
%table
.code.white
-
diff_file
.
highlighted_diff_lines
.
each
do
|
line
|
=
render
"projects/diffs/line"
,
{
line:
line
,
diff_file:
diff_file
,
line_code:
nil
,
plain:
true
}
=
render
"projects/diffs/line"
,
line:
line
,
diff_file:
diff_file
,
plain:
true
-
else
No
preview
for
this
file
type
%br
app/views/projects/diffs/_diffs.html.haml
View file @
9fc0e11e
...
...
@@ -23,8 +23,8 @@
.files
-
diff_files
.
each_with_index
do
|
diff_file
,
index
|
-
diff_commit
=
commit_for_diff
(
diff_file
)
-
blob
=
project
.
repository
.
blob_for_diff
(
diff_commit
,
diff_file
)
-
diff_commit
=
diff_file
.
content_commit
||
commit_for_diff
(
diff_file
)
-
blob
=
diff_file
.
blob
(
diff_commit
)
-
next
unless
blob
-
blob
.
load_all_data!
(
project
.
repository
)
unless
blob
.
only_display_raw?
...
...
app/views/projects/diffs/_file.html.haml
View file @
9fc0e11e
.diff-file.file-holder
{
id:
"diff-#{i}"
,
data:
diff_file_html_data
(
project
,
diff_
commit
,
diff_
file
)}
.diff-file.file-holder
{
id:
"diff-#{i}"
,
data:
diff_file_html_data
(
project
,
diff_file
)}
.file-title
{
id:
"file-path-#{hexdigest(diff_file.file_path)}"
}
-
if
diff_file
.
diff
.
submodule?
%span
...
...
@@ -52,7 +52,7 @@
-
elsif
blob
.
only_display_raw?
.nothing-here-block
This file is too large to display.
-
elsif
blob
.
image?
-
old_
file
=
project
.
repository
.
prev_blob_for_diff
(
diff_commit
,
diff_file
)
=
render
"projects/diffs/image"
,
diff_file:
diff_file
,
old_file:
old_
file
,
file:
blob
,
index:
i
,
diff_refs:
diff_refs
-
old_
blob
=
diff_file
.
old_blob
(
diff_commit
)
=
render
"projects/diffs/image"
,
diff_file:
diff_file
,
old_file:
old_
blob
,
file:
blob
,
index:
i
-
else
.nothing-here-block
No preview for this file type
lib/gitlab/diff/file.rb
View file @
9fc0e11e
...
...
@@ -12,6 +12,12 @@ module Gitlab
@diff_refs
=
diff_refs
end
def
content_commit
return
unless
diff_refs
repository
.
commit
(
deleted_file
?
old_ref
:
new_ref
)
end
def
old_ref
diff_refs
.
try
(
:base_sha
)
end
...
...
@@ -56,11 +62,7 @@ module Gitlab
end
def
file_path
if
diff
.
new_path
.
present?
diff
.
new_path
elsif
diff
.
old_path
.
present?
diff
.
old_path
end
new_path
.
presence
||
old_path
.
presence
end
def
added_lines
...
...
@@ -70,6 +72,20 @@ module Gitlab
def
removed_lines
diff_lines
.
count
(
&
:removed?
)
end
def
old_blob
(
commit
=
content_commit
)
return
unless
commit
parent_id
=
commit
.
parent_id
return
unless
parent_id
repository
.
blob_at
(
parent_id
,
old_path
)
end
def
blob
(
commit
=
content_commit
)
return
unless
commit
repository
.
blob_at
(
commit
.
id
,
file_path
)
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