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
Tatuya Kamada
gitlab-ce
Commits
84a15902
Commit
84a15902
authored
Apr 21, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Let commit model know about its project.
parent
b0ed2ff1
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
34 additions
and
27 deletions
+34
-27
app/mailers/emails/projects.rb
app/mailers/emails/projects.rb
+3
-3
app/models/commit.rb
app/models/commit.rb
+7
-4
app/models/merge_request_diff.rb
app/models/merge_request_diff.rb
+2
-2
app/models/project.rb
app/models/project.rb
+5
-1
app/models/project_wiki.rb
app/models/project_wiki.rb
+1
-1
app/models/repository.rb
app/models/repository.rb
+6
-5
app/services/merge_requests/build_service.rb
app/services/merge_requests/build_service.rb
+1
-1
app/views/projects/blame/show.html.haml
app/views/projects/blame/show.html.haml
+1
-1
app/views/projects/commits/_commit_list.html.haml
app/views/projects/commits/_commit_list.html.haml
+2
-2
app/workers/irker_worker.rb
app/workers/irker_worker.rb
+1
-2
lib/api/entities.rb
lib/api/entities.rb
+2
-2
spec/mailers/notify_spec.rb
spec/mailers/notify_spec.rb
+3
-3
No files found.
app/mailers/emails/projects.rb
View file @
84a15902
...
@@ -79,7 +79,7 @@ module Emails
...
@@ -79,7 +79,7 @@ module Emails
@disable_diffs
=
disable_diffs
@disable_diffs
=
disable_diffs
if
@compare
if
@compare
@commits
=
Commit
.
decorate
(
compare
.
commits
)
@commits
=
Commit
.
decorate
(
compare
.
commits
,
@project
)
@diffs
=
compare
.
diffs
@diffs
=
compare
.
diffs
end
end
...
@@ -101,8 +101,8 @@ module Emails
...
@@ -101,8 +101,8 @@ module Emails
if
@commits
.
length
>
1
if
@commits
.
length
>
1
@target_url
=
namespace_project_compare_url
(
@project
.
namespace
,
@target_url
=
namespace_project_compare_url
(
@project
.
namespace
,
@project
,
@project
,
from:
Commit
.
new
(
@compare
.
base
),
from:
Commit
.
new
(
@compare
.
base
,
@project
),
to:
Commit
.
new
(
@compare
.
head
))
to:
Commit
.
new
(
@compare
.
head
,
@project
))
@subject
<<
"Deleted "
if
@reverse_compare
@subject
<<
"Deleted "
if
@reverse_compare
@subject
<<
"
#{
@commits
.
length
}
commits:
#{
@commits
.
first
.
title
}
"
@subject
<<
"
#{
@commits
.
length
}
commits:
#{
@commits
.
first
.
title
}
"
else
else
...
...
app/models/commit.rb
View file @
84a15902
...
@@ -6,6 +6,8 @@ class Commit
...
@@ -6,6 +6,8 @@ class Commit
attr_mentionable
:safe_message
attr_mentionable
:safe_message
attr_accessor
:project
# Safe amount of changes (files and lines) in one commit to render
# Safe amount of changes (files and lines) in one commit to render
# Used to prevent 500 error on huge commits by suppressing diff
# Used to prevent 500 error on huge commits by suppressing diff
#
#
...
@@ -18,12 +20,12 @@ class Commit
...
@@ -18,12 +20,12 @@ class Commit
DIFF_HARD_LIMIT_LINES
=
50000
unless
defined?
(
DIFF_HARD_LIMIT_LINES
)
DIFF_HARD_LIMIT_LINES
=
50000
unless
defined?
(
DIFF_HARD_LIMIT_LINES
)
class
<<
self
class
<<
self
def
decorate
(
commits
)
def
decorate
(
commits
,
project
)
commits
.
map
do
|
commit
|
commits
.
map
do
|
commit
|
if
commit
.
kind_of?
(
Commit
)
if
commit
.
kind_of?
(
Commit
)
commit
commit
else
else
self
.
new
(
commit
)
self
.
new
(
commit
,
project
)
end
end
end
end
end
end
...
@@ -41,10 +43,11 @@ class Commit
...
@@ -41,10 +43,11 @@ class Commit
attr_accessor
:raw
attr_accessor
:raw
def
initialize
(
raw_commit
)
def
initialize
(
raw_commit
,
project
)
raise
"Nil as raw commit passed"
unless
raw_commit
raise
"Nil as raw commit passed"
unless
raw_commit
@raw
=
raw_commit
@raw
=
raw_commit
@project
=
project
end
end
def
id
def
id
...
@@ -169,6 +172,6 @@ class Commit
...
@@ -169,6 +172,6 @@ class Commit
end
end
def
parents
def
parents
@parents
||=
Commit
.
decorate
(
super
)
@parents
||=
Commit
.
decorate
(
super
,
project
)
end
end
end
end
app/models/merge_request_diff.rb
View file @
84a15902
...
@@ -67,7 +67,7 @@ class MergeRequestDiff < ActiveRecord::Base
...
@@ -67,7 +67,7 @@ class MergeRequestDiff < ActiveRecord::Base
end
end
def
load_commits
(
array
)
def
load_commits
(
array
)
array
.
map
{
|
hash
|
Commit
.
new
(
Gitlab
::
Git
::
Commit
.
new
(
hash
))
}
array
.
map
{
|
hash
|
Commit
.
new
(
Gitlab
::
Git
::
Commit
.
new
(
hash
)
,
merge_request
.
source_project
)
}
end
end
def
dump_diffs
(
diffs
)
def
dump_diffs
(
diffs
)
...
@@ -88,7 +88,7 @@ class MergeRequestDiff < ActiveRecord::Base
...
@@ -88,7 +88,7 @@ class MergeRequestDiff < ActiveRecord::Base
commits
=
compare_result
.
commits
commits
=
compare_result
.
commits
if
commits
.
present?
if
commits
.
present?
commits
=
Commit
.
decorate
(
commits
).
commits
=
Commit
.
decorate
(
commits
,
merge_request
.
source_project
).
sort_by
(
&
:created_at
).
sort_by
(
&
:created_at
).
reverse
reverse
end
end
...
...
app/models/project.rb
View file @
84a15902
...
@@ -254,7 +254,11 @@ class Project < ActiveRecord::Base
...
@@ -254,7 +254,11 @@ class Project < ActiveRecord::Base
end
end
def
repository
def
repository
@repository
||=
Repository
.
new
(
path_with_namespace
)
@repository
||=
Repository
.
new
(
path_with_namespace
,
nil
,
self
)
end
def
commit
(
id
)
repository
.
commit
(
id
)
end
end
def
saved?
def
saved?
...
...
app/models/project_wiki.rb
View file @
84a15902
...
@@ -112,7 +112,7 @@ class ProjectWiki
...
@@ -112,7 +112,7 @@ class ProjectWiki
end
end
def
repository
def
repository
Repository
.
new
(
path_with_namespace
,
default_branch
)
Repository
.
new
(
path_with_namespace
,
default_branch
,
@project
)
end
end
def
default_branch
def
default_branch
...
...
app/models/repository.rb
View file @
84a15902
class
Repository
class
Repository
include
Gitlab
::
ShellAdapter
include
Gitlab
::
ShellAdapter
attr_accessor
:raw_repository
,
:path_with_namespace
attr_accessor
:raw_repository
,
:path_with_namespace
,
:project
def
initialize
(
path_with_namespace
,
default_branch
=
nil
)
def
initialize
(
path_with_namespace
,
default_branch
=
nil
,
project
=
nil
)
@path_with_namespace
=
path_with_namespace
@path_with_namespace
=
path_with_namespace
@raw_repository
=
Gitlab
::
Git
::
Repository
.
new
(
path_to_repo
)
if
path_with_namespace
@raw_repository
=
Gitlab
::
Git
::
Repository
.
new
(
path_to_repo
)
if
path_with_namespace
@project
=
project
rescue
Gitlab
::
Git
::
Repository
::
NoRepository
rescue
Gitlab
::
Git
::
Repository
::
NoRepository
nil
nil
end
end
...
@@ -28,7 +29,7 @@ class Repository
...
@@ -28,7 +29,7 @@ class Repository
def
commit
(
id
=
'HEAD'
)
def
commit
(
id
=
'HEAD'
)
return
nil
unless
raw_repository
return
nil
unless
raw_repository
commit
=
Gitlab
::
Git
::
Commit
.
find
(
raw_repository
,
id
)
commit
=
Gitlab
::
Git
::
Commit
.
find
(
raw_repository
,
id
)
commit
=
Commit
.
new
(
commit
)
if
commit
commit
=
Commit
.
new
(
commit
,
@project
)
if
commit
commit
commit
rescue
Rugged
::
OdbError
rescue
Rugged
::
OdbError
nil
nil
...
@@ -42,13 +43,13 @@ class Repository
...
@@ -42,13 +43,13 @@ class Repository
limit:
limit
,
limit:
limit
,
offset:
offset
,
offset:
offset
,
)
)
commits
=
Commit
.
decorate
(
commits
)
if
commits
.
present?
commits
=
Commit
.
decorate
(
commits
,
@project
)
if
commits
.
present?
commits
commits
end
end
def
commits_between
(
from
,
to
)
def
commits_between
(
from
,
to
)
commits
=
Gitlab
::
Git
::
Commit
.
between
(
raw_repository
,
from
,
to
)
commits
=
Gitlab
::
Git
::
Commit
.
between
(
raw_repository
,
from
,
to
)
commits
=
Commit
.
decorate
(
commits
)
if
commits
.
present?
commits
=
Commit
.
decorate
(
commits
,
@project
)
if
commits
.
present?
commits
commits
end
end
...
...
app/services/merge_requests/build_service.rb
View file @
84a15902
...
@@ -29,7 +29,7 @@ module MergeRequests
...
@@ -29,7 +29,7 @@ module MergeRequests
# At this point we decide if merge request can be created
# At this point we decide if merge request can be created
# If we have at least one commit to merge -> creation allowed
# If we have at least one commit to merge -> creation allowed
if
commits
.
present?
if
commits
.
present?
merge_request
.
compare_commits
=
Commit
.
decorate
(
commits
)
merge_request
.
compare_commits
=
Commit
.
decorate
(
commits
,
merge_request
.
source_project
)
merge_request
.
can_be_created
=
true
merge_request
.
can_be_created
=
true
merge_request
.
compare_failed
=
false
merge_request
.
compare_failed
=
false
...
...
app/views/projects/blame/show.html.haml
View file @
84a15902
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
.file-content.blame.highlight
.file-content.blame.highlight
%table
%table
-
@blame
.
each
do
|
commit
,
lines
,
since
|
-
@blame
.
each
do
|
commit
,
lines
,
since
|
-
commit
=
Commit
.
new
(
commit
)
-
commit
=
Commit
.
new
(
commit
,
@project
)
%tr
%tr
%td
.blame-commit
%td
.blame-commit
%span
.commit
%span
.commit
...
...
app/views/projects/commits/_commit_list.html.haml
View file @
84a15902
...
@@ -3,9 +3,9 @@
...
@@ -3,9 +3,9 @@
Commits (
#{
@commits
.
count
}
)
Commits (
#{
@commits
.
count
}
)
-
if
@commits
.
size
>
MergeRequestDiff
::
COMMITS_SAFE_SIZE
-
if
@commits
.
size
>
MergeRequestDiff
::
COMMITS_SAFE_SIZE
%ul
.well-list
%ul
.well-list
-
Commit
.
decorate
(
@commits
.
first
(
MergeRequestDiff
::
COMMITS_SAFE_SIZE
)).
each
do
|
commit
|
-
Commit
.
decorate
(
@commits
.
first
(
MergeRequestDiff
::
COMMITS_SAFE_SIZE
)
,
@project
).
each
do
|
commit
|
=
render
"projects/commits/inline_commit"
,
commit:
commit
,
project:
@project
=
render
"projects/commits/inline_commit"
,
commit:
commit
,
project:
@project
%li
.warning-row.unstyled
%li
.warning-row.unstyled
other
#{
@commits
.
size
-
MergeRequestDiff
::
COMMITS_SAFE_SIZE
}
commits hidden to prevent performance issues.
other
#{
@commits
.
size
-
MergeRequestDiff
::
COMMITS_SAFE_SIZE
}
commits hidden to prevent performance issues.
-
else
-
else
%ul
.well-list
=
render
Commit
.
decorate
(
@commits
),
project:
@project
%ul
.well-list
=
render
Commit
.
decorate
(
@commits
,
@project
),
project:
@project
app/workers/irker_worker.rb
View file @
84a15902
...
@@ -137,8 +137,7 @@ class IrkerWorker
...
@@ -137,8 +137,7 @@ class IrkerWorker
end
end
def
commit_from_id
(
project
,
id
)
def
commit_from_id
(
project
,
id
)
commit
=
Gitlab
::
Git
::
Commit
.
find
(
project
.
repository
,
id
)
project
.
commit
(
id
)
Commit
.
new
(
commit
)
end
end
def
files_count
(
commit
)
def
files_count
(
commit
)
...
...
lib/api/entities.rb
View file @
84a15902
...
@@ -251,11 +251,11 @@ module API
...
@@ -251,11 +251,11 @@ module API
class
Compare
<
Grape
::
Entity
class
Compare
<
Grape
::
Entity
expose
:commit
,
using:
Entities
::
RepoCommit
do
|
compare
,
options
|
expose
:commit
,
using:
Entities
::
RepoCommit
do
|
compare
,
options
|
Commit
.
decorate
(
compare
.
commits
).
last
Commit
.
decorate
(
compare
.
commits
,
nil
).
last
end
end
expose
:commits
,
using:
Entities
::
RepoCommit
do
|
compare
,
options
|
expose
:commits
,
using:
Entities
::
RepoCommit
do
|
compare
,
options
|
Commit
.
decorate
(
compare
.
commits
)
Commit
.
decorate
(
compare
.
commits
,
nil
)
end
end
expose
:diffs
,
using:
Entities
::
RepoDiff
do
|
compare
,
options
|
expose
:diffs
,
using:
Entities
::
RepoDiff
do
|
compare
,
options
|
...
...
spec/mailers/notify_spec.rb
View file @
84a15902
...
@@ -670,8 +670,8 @@ describe Notify do
...
@@ -670,8 +670,8 @@ describe Notify do
let
(
:example_site_path
)
{
root_path
}
let
(
:example_site_path
)
{
root_path
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:compare
)
{
Gitlab
::
Git
::
Compare
.
new
(
project
.
repository
.
raw_repository
,
sample_image_commit
.
id
,
sample_commit
.
id
)
}
let
(
:compare
)
{
Gitlab
::
Git
::
Compare
.
new
(
project
.
repository
.
raw_repository
,
sample_image_commit
.
id
,
sample_commit
.
id
)
}
let
(
:commits
)
{
Commit
.
decorate
(
compare
.
commits
)
}
let
(
:commits
)
{
Commit
.
decorate
(
compare
.
commits
,
nil
)
}
let
(
:diff_path
)
{
namespace_project_compare_path
(
project
.
namespace
,
project
,
from:
Commit
.
new
(
compare
.
base
),
to:
Commit
.
new
(
compare
.
head
))
}
let
(
:diff_path
)
{
namespace_project_compare_path
(
project
.
namespace
,
project
,
from:
Commit
.
new
(
compare
.
base
,
project
),
to:
Commit
.
new
(
compare
.
head
,
project
))
}
let
(
:send_from_committer_email
)
{
false
}
let
(
:send_from_committer_email
)
{
false
}
subject
{
Notify
.
repository_push_email
(
project
.
id
,
'devs@company.name'
,
author_id:
user
.
id
,
ref:
'refs/heads/master'
,
action: :push
,
compare:
compare
,
reverse_compare:
false
,
send_from_committer_email:
send_from_committer_email
)
}
subject
{
Notify
.
repository_push_email
(
project
.
id
,
'devs@company.name'
,
author_id:
user
.
id
,
ref:
'refs/heads/master'
,
action: :push
,
compare:
compare
,
reverse_compare:
false
,
send_from_committer_email:
send_from_committer_email
)
}
...
@@ -774,7 +774,7 @@ describe Notify do
...
@@ -774,7 +774,7 @@ describe Notify do
let
(
:example_site_path
)
{
root_path
}
let
(
:example_site_path
)
{
root_path
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:compare
)
{
Gitlab
::
Git
::
Compare
.
new
(
project
.
repository
.
raw_repository
,
sample_commit
.
parent_id
,
sample_commit
.
id
)
}
let
(
:compare
)
{
Gitlab
::
Git
::
Compare
.
new
(
project
.
repository
.
raw_repository
,
sample_commit
.
parent_id
,
sample_commit
.
id
)
}
let
(
:commits
)
{
Commit
.
decorate
(
compare
.
commits
)
}
let
(
:commits
)
{
Commit
.
decorate
(
compare
.
commits
,
nil
)
}
let
(
:diff_path
)
{
namespace_project_commit_path
(
project
.
namespace
,
project
,
commits
.
first
)
}
let
(
:diff_path
)
{
namespace_project_commit_path
(
project
.
namespace
,
project
,
commits
.
first
)
}
subject
{
Notify
.
repository_push_email
(
project
.
id
,
'devs@company.name'
,
author_id:
user
.
id
,
ref:
'refs/heads/master'
,
action: :push
,
compare:
compare
)
}
subject
{
Notify
.
repository_push_email
(
project
.
id
,
'devs@company.name'
,
author_id:
user
.
id
,
ref:
'refs/heads/master'
,
action: :push
,
compare:
compare
)
}
...
...
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