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
iv
gitlab-ce
Commits
b636f83e
Commit
b636f83e
authored
Jan 28, 2016
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move blame group logic to dedicated class
parent
4be80f8a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
81 additions
and
43 deletions
+81
-43
app/controllers/projects/blame_controller.rb
app/controllers/projects/blame_controller.rb
+1
-27
app/views/projects/blame/show.html.haml
app/views/projects/blame/show.html.haml
+2
-2
lib/gitlab/blame.rb
lib/gitlab/blame.rb
+54
-0
spec/controllers/blame_controller_spec.rb
spec/controllers/blame_controller_spec.rb
+0
-14
spec/lib/gitlab/blame_spec.rb
spec/lib/gitlab/blame_spec.rb
+24
-0
No files found.
app/controllers/projects/blame_controller.rb
View file @
b636f83e
...
@@ -8,32 +8,6 @@ class Projects::BlameController < Projects::ApplicationController
...
@@ -8,32 +8,6 @@ class Projects::BlameController < Projects::ApplicationController
def
show
def
show
@blob
=
@repository
.
blob_at
(
@commit
.
id
,
@path
)
@blob
=
@repository
.
blob_at
(
@commit
.
id
,
@path
)
@blame
=
group_blame_lines
@blame_groups
=
Gitlab
::
Blame
.
new
(
@blob
,
@commit
).
groups
end
def
group_blame_lines
blame
=
Gitlab
::
Git
::
Blame
.
new
(
@repository
,
@commit
.
id
,
@path
)
prev_sha
=
nil
groups
=
[]
current_group
=
nil
highlighted_lines
=
Gitlab
::
Highlight
.
highlight
(
@blob
.
name
,
@blob
.
data
).
lines
i
=
0
blame
.
each
do
|
commit
,
line
|
line
=
highlighted_lines
[
i
].
html_safe
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
i
+=
1
end
groups
<<
current_group
if
current_group
.
present?
groups
end
end
end
end
app/views/projects/blame/show.html.haml
View file @
b636f83e
...
@@ -15,11 +15,11 @@
...
@@ -15,11 +15,11 @@
.file-content.blame.code.js-syntax-highlight
.file-content.blame.code.js-syntax-highlight
%table
%table
-
current_line
=
1
-
current_line
=
1
-
@blame
.
each
do
|
blame_group
|
-
@blame
_groups
.
each
do
|
blame_group
|
%tr
%tr
%td
.blame-commit
%td
.blame-commit
.commit
.commit
-
commit
=
Commit
.
new
(
blame_group
[
:commit
],
@project
)
-
commit
=
blame_group
[
:commit
]
.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"
...
...
lib/gitlab/blame.rb
0 → 100644
View file @
b636f83e
module
Gitlab
class
Blame
attr_accessor
:blob
,
:commit
def
initialize
(
blob
,
commit
)
@blob
=
blob
@commit
=
commit
end
def
groups
(
highlight:
true
)
prev_sha
=
nil
groups
=
[]
current_group
=
nil
i
=
0
blame
.
each
do
|
commit
,
line
|
commit
=
Commit
.
new
(
commit
,
project
)
sha
=
commit
.
sha
if
prev_sha
!=
sha
groups
<<
current_group
if
current_group
current_group
=
{
commit:
commit
,
lines:
[]
}
end
line
=
highlighted_lines
[
i
].
html_safe
if
highlight
current_group
[
:lines
]
<<
line
prev_sha
=
sha
i
+=
1
end
groups
<<
current_group
if
current_group
groups
end
private
def
blame
@blame
||=
Gitlab
::
Git
::
Blame
.
new
(
repository
,
@commit
.
id
,
@blob
.
path
)
end
def
highlighted_lines
@highlighted_lines
||=
Gitlab
::
Highlight
.
highlight
(
@blob
.
name
,
@blob
.
data
).
lines
end
def
project
commit
.
project
end
def
repository
project
.
repository
end
end
end
spec/controllers/blame_controller_spec.rb
View file @
b636f83e
...
@@ -24,20 +24,6 @@ describe Projects::BlameController do
...
@@ -24,20 +24,6 @@ describe Projects::BlameController do
context
"valid file"
do
context
"valid file"
do
let
(
:id
)
{
'master/files/ruby/popen.rb'
}
let
(
:id
)
{
'master/files/ruby/popen.rb'
}
it
{
is_expected
.
to
respond_with
(
:success
)
}
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
end
end
end
spec/lib/gitlab/blame_spec.rb
0 → 100644
View file @
b636f83e
require
'spec_helper'
describe
Gitlab
::
Blame
,
lib:
true
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:path
)
{
'files/ruby/popen.rb'
}
let
(
:commit
)
{
project
.
commit
(
'master'
)
}
let
(
:blob
)
{
project
.
repository
.
blob_at
(
commit
.
id
,
path
)
}
describe
"#groups"
do
let
(
:subject
)
{
described_class
.
new
(
blob
,
commit
).
groups
(
highlight:
false
)
}
it
'groups lines properly'
do
expect
(
subject
.
count
).
to
eq
(
18
)
expect
(
subject
[
0
][
:commit
].
sha
).
to
eq
(
'913c66a37b4a45b9769037c55c2d238bd0942d2e'
)
expect
(
subject
[
0
][
:lines
]).
to
eq
([
"require 'fileutils'"
,
"require 'open3'"
,
""
])
expect
(
subject
[
1
][
:commit
].
sha
).
to
eq
(
'874797c3a73b60d2187ed6e2fcabd289ff75171e'
)
expect
(
subject
[
1
][
:lines
]).
to
eq
([
"module Popen"
,
" extend self"
])
expect
(
subject
[
-
1
][
:commit
].
sha
).
to
eq
(
'913c66a37b4a45b9769037c55c2d238bd0942d2e'
)
expect
(
subject
[
-
1
][
:lines
]).
to
eq
([
" 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