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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
a7a5a656
Commit
a7a5a656
authored
Mar 28, 2022
by
Jacques
Committed by
Jacques Erasmus
Mar 30, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add commit diff stats
Added diff stats to the commit view Changelog: added
parent
3e5c16ac
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
0 deletions
+44
-0
app/assets/javascripts/pages/projects/commit/show/index.js
app/assets/javascripts/pages/projects/commit/show/index.js
+27
-0
app/helpers/diff_helper.rb
app/helpers/diff_helper.rb
+12
-0
app/views/projects/diffs/_file.html.haml
app/views/projects/diffs/_file.html.haml
+1
-0
spec/features/commit_spec.rb
spec/features/commit_spec.rb
+4
-0
No files found.
app/assets/javascripts/pages/projects/commit/show/index.js
View file @
a7a5a656
/* eslint-disable no-new */
import
$
from
'
jquery
'
;
import
Vue
from
'
vue
'
;
import
loadAwardsHandler
from
'
~/awards_handler
'
;
import
ShortcutsNavigation
from
'
~/behaviors/shortcuts/shortcuts_navigation
'
;
import
Diff
from
'
~/diff
'
;
...
...
@@ -14,6 +15,7 @@ import { initCommitBoxInfo } from '~/projects/commit_box/info';
import
syntaxHighlight
from
'
~/syntax_highlight
'
;
import
ZenMode
from
'
~/zen_mode
'
;
import
'
~/sourcegraph/load
'
;
import
DiffStats
from
'
~/diffs/components/diff_stats.vue
'
;
const
hasPerfBar
=
document
.
querySelector
(
'
.with-performance-bar
'
);
const
performanceHeight
=
hasPerfBar
?
35
:
0
;
...
...
@@ -26,6 +28,7 @@ initCommitBoxInfo();
initDeprecatedNotes
();
const
filesContainer
=
$
(
'
.js-diffs-batch
'
);
const
diffStatsElements
=
document
.
querySelectorAll
(
'
#js-diff-stats
'
);
if
(
filesContainer
.
length
)
{
const
batchPath
=
filesContainer
.
data
(
'
diffFilesPath
'
);
...
...
@@ -44,5 +47,29 @@ if (filesContainer.length) {
}
else
{
new
Diff
();
}
if
(
diffStatsElements
.
length
)
{
diffStatsElements
.
forEach
((
diffStatsEl
)
=>
{
const
{
addedLines
,
removedLines
,
oldSize
,
newSize
,
viewerName
}
=
diffStatsEl
.
dataset
;
new
Vue
({
el
:
diffStatsEl
,
render
(
createElement
)
{
return
createElement
(
DiffStats
,
{
props
:
{
diffFile
:
{
old_size
:
oldSize
,
new_size
:
newSize
,
viewer
:
{
name
:
viewerName
},
},
addedLines
:
Number
(
addedLines
),
removedLines
:
Number
(
removedLines
),
},
});
},
});
});
}
loadAwardsHandler
();
initCommitActions
();
app/helpers/diff_helper.rb
View file @
a7a5a656
...
...
@@ -179,6 +179,18 @@ module DiffHelper
}
end
def
diff_file_stats_data
(
diff_file
)
old_blob
=
diff_file
.
old_blob
new_blob
=
diff_file
.
new_blob
{
old_size:
old_blob
&
.
size
,
new_size:
new_blob
&
.
size
,
added_lines:
diff_file
.
added_lines
,
removed_lines:
diff_file
.
removed_lines
,
viewer_name:
diff_file
.
viewer
.
partial_name
}
end
def
editable_diff?
(
diff_file
)
!
diff_file
.
deleted_file?
&&
@merge_request
&&
@merge_request
.
source_project
end
...
...
app/views/projects/diffs/_file.html.haml
View file @
a7a5a656
...
...
@@ -15,6 +15,7 @@
-
unless
diff_file
.
submodule?
.file-actions.gl-display-none.gl-sm-display-flex
#js-diff-stats
{
data:
diff_file_stats_data
(
diff_file
)
}
-
if
diff_file
.
blob
&
.
readable_text?
%span
.has-tooltip
{
title:
_
(
"Toggle comments for this file"
)
}
=
link_to
'#'
,
class:
'js-toggle-diff-comments btn gl-button btn-default btn-icon selected'
,
disabled:
@diff_notes_disabled
do
...
...
spec/features/commit_spec.rb
View file @
a7a5a656
...
...
@@ -33,6 +33,10 @@ RSpec.describe 'Commit' do
it
"reports the correct number of total changes"
do
expect
(
page
).
to
have_content
(
"Changes
#{
commit
.
diffs
.
size
}
"
)
end
it
'renders diff stats'
,
:js
do
expect
(
page
).
to
have_selector
(
".diff-stats"
)
end
end
describe
"pagination"
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