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
b4cc04d7
Commit
b4cc04d7
authored
Jan 25, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit diff fixes, per-line comments fixed
parent
73efb837
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
83 deletions
+66
-83
app/helpers/commits_helper.rb
app/helpers/commits_helper.rb
+49
-14
app/models/note.rb
app/models/note.rb
+0
-17
app/views/commits/_text_file.html.haml
app/views/commits/_text_file.html.haml
+15
-36
app/views/commits/show.html.haml
app/views/commits/show.html.haml
+1
-1
spec/models/note_spec.rb
spec/models/note_spec.rb
+1
-15
No files found.
app/helpers/commits_helper.rb
View file @
b4cc04d7
...
@@ -7,16 +7,6 @@ module CommitsHelper
...
@@ -7,16 +7,6 @@ module CommitsHelper
end
end
def
diff_line_class
(
line
)
if
line
[
0
]
==
"+"
"new"
elsif
line
[
0
]
==
"-"
"old"
else
nil
end
end
def
more_commits_link
def
more_commits_link
offset
=
params
[
:offset
]
||
0
offset
=
params
[
:offset
]
||
0
limit
=
params
[
:limit
]
||
100
limit
=
params
[
:limit
]
||
100
...
@@ -42,11 +32,56 @@ module CommitsHelper
...
@@ -42,11 +32,56 @@ module CommitsHelper
preserve
out
preserve
out
end
end
def
build_line_code
(
line
,
index
,
line_new
,
line_old
)
def
diff_line_class
(
line
)
if
diff_line_class
(
line
)
==
"new"
if
line
[
0
]
==
"+"
"NEW_
#{
index
}
_
#{
line_new
}
"
"new"
elsif
line
[
0
]
==
"-"
"old"
else
else
"OLD_
#{
index
}
_
#{
line_old
}
"
nil
end
end
def
build_line_code
(
line
,
index
,
line_new
,
line_old
)
"
#{
index
}
_
#{
line_old
}
_
#{
line_new
}
"
end
def
each_diff_line
(
diff_arr
,
index
)
line_old
=
1
line_new
=
1
type
=
nil
lines_arr
=
diff_arr
lines_arr
.
each
do
|
line
|
full_line
=
html_escape
(
line
.
gsub
(
/\n/
,
''
))
next
if
line
.
match
(
/^--- \/dev\/null/
)
next
if
line
.
match
(
/^--- a/
)
next
if
line
.
match
(
/^\+\+\+ b/
)
if
line
.
match
(
/^@@ -/
)
next
if
line_old
==
1
&&
line_new
==
1
type
=
"match"
line_old
=
line
.
match
(
/\-[0-9]*/
)[
0
].
to_i
.
abs
rescue
0
line_new
=
line
.
match
(
/\+[0-9]*/
)[
0
].
to_i
.
abs
rescue
0
yield
(
nil
,
type
,
nil
,
nil
,
nil
)
next
else
type
=
diff_line_class
(
line
)
line_code
=
build_line_code
(
line
,
index
,
line_new
,
line_old
)
yield
(
full_line
,
type
,
line_code
,
line_new
,
line_old
)
end
if
line
[
0
]
==
"+"
line_new
+=
1
elsif
line
[
0
]
==
"-"
line_old
+=
1
else
line_new
+=
1
line_old
+=
1
end
end
end
end
end
end
end
app/models/note.rb
View file @
b4cc04d7
...
@@ -57,23 +57,6 @@ class Note < ActiveRecord::Base
...
@@ -57,23 +57,6 @@ class Note < ActiveRecord::Base
rescue
rescue
nil
nil
end
end
def
line_file_id
@line_file_id
||=
line_code
.
split
(
"_"
)[
1
].
to_i
if
line_code
end
def
line_type_id
@line_type_id
||=
line_code
.
split
(
"_"
).
first
if
line_code
end
def
line_number
@line_number
||=
line_code
.
split
(
"_"
).
last
.
to_i
if
line_code
end
def
for_line?
(
file_id
,
old_line
,
new_line
)
line_file_id
==
file_id
&&
((
line_type_id
==
"NEW"
&&
line_number
==
new_line
)
||
(
line_type_id
==
"OLD"
&&
line_number
==
old_line
))
end
end
end
# == Schema Information
# == Schema Information
#
#
...
...
app/views/commits/_text_file.html.haml
View file @
b4cc04d7
%table
%table
-
line_old
=
0
-
each_diff_line
(
diff
.
diff
.
lines
.
to_a
,
index
)
do
|
line
,
type
,
line_code
,
line_new
,
line_old
|
-
line_new
=
0
-
diff_str
=
diff
.
diff
-
lines_arr
=
diff_str
.
lines
.
to_a
-
lines_arr
.
each
do
|
line
|
-
next
if
line
.
match
(
/^--- \/dev\/null/
)
-
next
if
line
.
match
(
/^--- a/
)
-
next
if
line
.
match
(
/^\+\+\+ b/
)
-
if
line
.
match
(
/^@@ -/
)
-
unless
line_old
.
zero?
&&
line_new
.
zero?
%tr
.line_holder
%td
.old_line
=
"..."
%td
.new_line
=
"..."
%td
.line_content
-
line_old
=
line
.
match
(
/\-[0-9]*/
)[
0
].
to_i
.
abs
rescue
0
-
line_new
=
line
.
match
(
/\+[0-9]*/
)[
0
].
to_i
.
abs
rescue
0
-
next
-
full_line
=
html_escape
(
line
.
gsub
(
/\n/
,
''
))
%tr
.line_holder
%tr
.line_holder
%td
.old_line
-
if
type
==
"match"
=
link_to
raw
(
diff_line_class
(
line
)
==
"new"
?
" "
:
line_old
),
"#OLD
#{
index
}
-
#{
line_old
}
"
,
:id
=>
"OLD
#{
index
}
-
#{
line_old
}
"
%td
.old_line
=
"..."
%td
.new_line
%td
.new_line
=
"..."
=
link_to
raw
(
diff_line_class
(
line
)
==
"old"
?
" "
:
line_new
)
,
"#NEW
#{
index
}
-
#{
line_new
}
"
,
:id
=>
"NEW
#{
index
}
-
#{
line_new
}
"
%td
.line_content
%td
.line_content
{
:class
=>
"#{diff_line_class(full_line)} #{build_line_code(line, index, line_new, line_old)}"
,
"line_code"
=>
build_line_code
(
line
,
index
,
line_new
,
line_old
)}=
raw
"
#{
full_line
}
"
-
else
-
comments
=
@line_notes
.
select
{
|
n
|
n
.
for_line?
(
index
,
line_old
,
line_new
)
}.
sort_by
(
&
:created_at
).
reverse
%td
.old_line
=
link_to
raw
(
type
==
"new"
?
" "
:
line_old
),
"#
#{
line_code
}
"
,
:id
=>
line_code
-
unless
comments
.
empty?
%td
.new_line
=
link_to
raw
(
type
==
"old"
?
" "
:
line_new
)
,
"#
#{
line_code
}
"
,
:id
=>
line_code
-
comments
.
each
do
|
note
|
%td
.line_content
{
:class
=>
"noteable_line #{type} #{line_code}"
,
"line_code"
=>
line_code
}=
raw
"
#{
line
}
"
=
render
"notes/per_line_show"
,
:note
=>
note
-
if
line
[
0
]
==
"+"
-
comments
=
@line_notes
.
select
{
|
n
|
n
.
line_code
==
line_code
}.
sort_by
(
&
:created_at
).
reverse
-
line_new
+=
1
-
unless
comments
.
empty?
-
elsif
line
[
0
]
==
"-"
-
comments
.
each
do
|
note
|
-
line_old
+=
1
=
render
"notes/per_line_show"
,
:note
=>
note
-
else
-
@line_notes
.
reject!
{
|
n
|
n
==
note
}
-
line_new
+=
1
-
line_old
+=
1
app/views/commits/show.html.haml
View file @
b4cc04d7
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
:javascript
:javascript
$
(
document
).
ready
(
function
(){
$
(
document
).
ready
(
function
(){
$
(
"
.
line_content
"
).
live
(
"
dblclick
"
,
function
(
e
)
{
$
(
"
.
noteable_line
"
).
live
(
"
dblclick
"
,
function
(
e
)
{
var
form
=
$
(
"
.per_line_form
"
);
var
form
=
$
(
"
.per_line_form
"
);
$
(
this
).
parent
().
after
(
form
);
$
(
this
).
parent
().
after
(
form
);
form
.
find
(
"
#note_line_code
"
).
val
(
$
(
this
).
attr
(
"
line_code
"
));
form
.
find
(
"
#note_line_code
"
).
val
(
$
(
this
).
attr
(
"
line_code
"
));
...
...
spec/models/note_spec.rb
View file @
b4cc04d7
...
@@ -42,27 +42,13 @@ describe Note do
...
@@ -42,27 +42,13 @@ describe Note do
:project
=>
project
,
:project
=>
project
,
:noteable_id
=>
commit
.
id
,
:noteable_id
=>
commit
.
id
,
:noteable_type
=>
"Commit"
,
:noteable_type
=>
"Commit"
,
:line_code
=>
"
OLD_1_23
"
:line_code
=>
"
0_16_1
"
end
end
it
"should save a valid note"
do
it
"should save a valid note"
do
@note
.
noteable_id
.
should
==
commit
.
id
@note
.
noteable_id
.
should
==
commit
.
id
@note
.
target
.
id
.
should
==
commit
.
id
@note
.
target
.
id
.
should
==
commit
.
id
end
end
it
{
@note
.
line_type_id
.
should
==
"OLD"
}
it
{
@note
.
line_file_id
.
should
==
1
}
it
{
@note
.
line_number
.
should
==
23
}
it
{
@note
.
for_line?
(
1
,
23
,
34
).
should
be_true
}
it
{
@note
.
for_line?
(
1
,
23
,
nil
).
should
be_true
}
it
{
@note
.
for_line?
(
1
,
23
,
0
).
should
be_true
}
it
{
@note
.
for_line?
(
1
,
23
,
23
).
should
be_true
}
it
{
@note
.
for_line?
(
1
,
nil
,
34
).
should
be_false
}
it
{
@note
.
for_line?
(
1
,
24
,
nil
).
should
be_false
}
it
{
@note
.
for_line?
(
1
,
24
,
0
).
should
be_false
}
it
{
@note
.
for_line?
(
1
,
24
,
23
).
should
be_false
}
end
end
describe
:authorization
do
describe
:authorization
do
...
...
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