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
Boxiang Sun
gitlab-ce
Commits
0a5b005d
Commit
0a5b005d
authored
Aug 20, 2015
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix blame view line groupings
Closes #2305
parent
55fc58bd
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
19 deletions
+86
-19
app/controllers/projects/blame_controller.rb
app/controllers/projects/blame_controller.rb
+23
-1
app/views/projects/blame/show.html.haml
app/views/projects/blame/show.html.haml
+20
-18
spec/controllers/blame_controller_spec.rb
spec/controllers/blame_controller_spec.rb
+43
-0
No files found.
app/controllers/projects/blame_controller.rb
View file @
0a5b005d
...
@@ -8,6 +8,28 @@ class Projects::BlameController < Projects::ApplicationController
...
@@ -8,6 +8,28 @@ class Projects::BlameController < Projects::ApplicationController
def
show
def
show
@blob
=
@repository
.
blob_at
(
@commit
.
id
,
@path
)
@blob
=
@repository
.
blob_at
(
@commit
.
id
,
@path
)
@blame
=
Gitlab
::
Git
::
Blame
.
new
(
@repository
,
@commit
.
id
,
@path
)
@blame
=
group_blame_lines
end
def
group_blame_lines
blame
=
Gitlab
::
Git
::
Blame
.
new
(
@repository
,
@commit
.
id
,
@path
)
prev_sha
=
nil
groups
=
[]
current_group
=
nil
blame
.
each
do
|
commit
,
line
|
if
prev_sha
&&
prev_sha
==
commit
.
sha
current_group
[
:lines
]
<<
line
else
groups
<<
current_group
if
current_group
.
present?
current_group
=
{
commit:
commit
,
lines:
[
line
]
}
end
prev_sha
=
commit
.
sha
end
groups
<<
current_group
if
current_group
.
present?
groups
end
end
end
end
app/views/projects/blame/show.html.haml
View file @
0a5b005d
...
@@ -13,12 +13,11 @@
...
@@ -13,12 +13,11 @@
.file-content.blame.highlight
.file-content.blame.highlight
%table
%table
-
current_line
=
1
-
current_line
=
1
-
@blame
.
each
do
|
raw_commit
,
line
|
-
@blame
.
each
do
|
blame_group
|
%tr
%tr
%td
.blame-commit
%td
.blame-commit
.commit
.commit
-
unless
@prev_commit
&&
@prev_commit
.
sha
==
raw_commit
.
sha
-
commit
=
Commit
.
new
(
blame_group
[
:commit
],
@project
)
-
commit
=
Commit
.
new
(
raw_commit
,
@project
)
.commit-row-title
.commit-row-title
%strong
%strong
=
link_to_gfm
truncate
(
commit
.
title
,
length:
35
),
namespace_project_commit_path
(
@project
.
namespace
,
@project
,
commit
.
id
),
class:
"cdark"
=
link_to_gfm
truncate
(
commit
.
title
,
length:
35
),
namespace_project_commit_path
(
@project
.
namespace
,
@project
,
commit
.
id
),
class:
"cdark"
...
@@ -29,14 +28,17 @@
...
@@ -29,14 +28,17 @@
=
commit_author_link
(
commit
,
avatar:
false
)
=
commit_author_link
(
commit
,
avatar:
false
)
authored
authored
#{
time_ago_with_tooltip
(
commit
.
committed_date
)
}
#{
time_ago_with_tooltip
(
commit
.
committed_date
)
}
-
@prev_commit
=
raw_commit
%td
.lines.blame-numbers
%td
.lines.blame-numbers
%pre
%pre
=
current_line
-
line_count
=
blame_group
[
:lines
].
count
-
current_line
+=
1
-
(
current_line
...
(
current_line
+
line_count
)).
each
do
|
i
|
=
i
\
-
current_line
+=
line_count
%td
.lines
%td
.lines
%pre
{
class:
'code highlight white'
}
%pre
{
class:
'code highlight white'
}
%code
%code
-
blame_group
[
:lines
].
each
do
|
line
|
:erb
:erb
<%=
highlight
(
@blob
.
name
,
line
,
nowrap:
true
,
continue:
true
).
html_safe
%>
<%=
highlight
(
@blob
.
name
,
line
,
nowrap:
true
,
continue:
true
).
html_safe
%>
spec/controllers/blame_controller_spec.rb
0 → 100644
View file @
0a5b005d
require
'spec_helper'
describe
Projects
::
BlameController
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
create
(
:user
)
}
before
do
sign_in
(
user
)
project
.
team
<<
[
user
,
:master
]
controller
.
instance_variable_set
(
:@project
,
project
)
end
describe
"GET show"
do
render_views
before
do
get
(
:show
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
id:
id
)
end
context
"valid file"
do
let
(
:id
)
{
'master/files/ruby/popen.rb'
}
it
{
is_expected
.
to
respond_with
(
:success
)
}
it
'groups blames properly'
do
blame
=
assigns
(
:blame
)
# Sanity check a few items
expect
(
blame
.
count
).
to
eq
(
18
)
expect
(
blame
[
0
][
:commit
].
sha
).
to
eq
(
'913c66a37b4a45b9769037c55c2d238bd0942d2e'
)
expect
(
blame
[
0
][
:lines
]).
to
eq
([
"require 'fileutils'"
,
"require 'open3'"
,
""
])
expect
(
blame
[
1
][
:commit
].
sha
).
to
eq
(
'874797c3a73b60d2187ed6e2fcabd289ff75171e'
)
expect
(
blame
[
1
][
:lines
]).
to
eq
([
"module Popen"
,
" extend self"
])
expect
(
blame
[
-
1
][
:commit
].
sha
).
to
eq
(
'913c66a37b4a45b9769037c55c2d238bd0942d2e'
)
expect
(
blame
[
-
1
][
:lines
]).
to
eq
([
" end"
,
"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