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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
154e54b4
Commit
154e54b4
authored
Mar 31, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove grit logic from app/
parent
d444a23a
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
11 additions
and
170 deletions
+11
-170
app/models/commit.rb
app/models/commit.rb
+5
-164
app/models/gollum_wiki.rb
app/models/gollum_wiki.rb
+1
-1
app/models/merge_request.rb
app/models/merge_request.rb
+1
-1
app/models/network/commit.rb
app/models/network/commit.rb
+1
-1
app/models/note.rb
app/models/note.rb
+1
-1
app/models/project.rb
app/models/project.rb
+2
-2
No files found.
app/models/commit.rb
View file @
154e54b4
...
@@ -8,174 +8,15 @@ class Commit
...
@@ -8,174 +8,15 @@ class Commit
#
#
DIFF_SAFE_SIZE
=
100
DIFF_SAFE_SIZE
=
100
attr_accessor
:
commit
,
:head
,
:refs
attr_accessor
:
raw
delegate
:message
,
:authored_date
,
:committed_date
,
:parents
,
:sha
,
def
initialize
(
raw_commit
)
:date
,
:committer
,
:author
,
:diffs
,
:tree
,
:id
,
:stats
,
:to_patch
,
to: :commit
class
<<
self
def
find_or_first
(
repo
,
commit_id
=
nil
,
root_ref
)
commit
=
if
commit_id
repo
.
commit
(
commit_id
)
else
repo
.
commits
(
root_ref
).
first
end
Commit
.
new
(
commit
)
if
commit
end
def
fresh_commits
(
repo
,
n
=
10
)
commits
=
repo
.
heads
.
map
do
|
h
|
repo
.
commits
(
h
.
name
,
n
).
map
{
|
c
|
Commit
.
new
(
c
,
h
)
}
end
.
flatten
.
uniq
{
|
c
|
c
.
id
}
commits
.
sort!
do
|
x
,
y
|
y
.
committed_date
<=>
x
.
committed_date
end
commits
[
0
...
n
]
end
def
commits_with_refs
(
repo
,
n
=
20
)
commits
=
repo
.
branches
.
map
{
|
ref
|
Commit
.
new
(
ref
.
commit
,
ref
)
}
commits
.
sort!
do
|
x
,
y
|
y
.
committed_date
<=>
x
.
committed_date
end
commits
[
0
..
n
]
end
def
commits_since
(
repo
,
date
)
commits
=
repo
.
heads
.
map
do
|
h
|
repo
.
log
(
h
.
name
,
nil
,
since:
date
).
each
{
|
c
|
Commit
.
new
(
c
,
h
)
}
end
.
flatten
.
uniq
{
|
c
|
c
.
id
}
commits
.
sort!
do
|
x
,
y
|
y
.
committed_date
<=>
x
.
committed_date
end
commits
end
def
commits
(
repo
,
ref
,
path
=
nil
,
limit
=
nil
,
offset
=
nil
)
if
path
repo
.
log
(
ref
,
path
,
max_count:
limit
,
skip:
offset
)
elsif
limit
&&
offset
repo
.
commits
(
ref
,
limit
,
offset
)
else
repo
.
commits
(
ref
)
end
.
map
{
|
c
|
Commit
.
new
(
c
)
}
end
def
commits_between
(
repo
,
from
,
to
)
repo
.
commits_between
(
from
,
to
).
map
{
|
c
|
Commit
.
new
(
c
)
}
end
def
compare
(
project
,
from
,
to
)
result
=
{
commits:
[],
diffs:
[],
commit:
nil
,
same:
false
}
return
result
unless
from
&&
to
first
=
project
.
repository
.
commit
(
to
.
try
(
:strip
))
last
=
project
.
repository
.
commit
(
from
.
try
(
:strip
))
if
first
&&
last
result
[
:same
]
=
(
first
.
id
==
last
.
id
)
result
[
:commits
]
=
project
.
repo
.
commits_between
(
last
.
id
,
first
.
id
).
map
{
|
c
|
Commit
.
new
(
c
)}
# Dont load diff for 100+ commits
result
[
:diffs
]
=
if
result
[
:commits
].
size
>
100
[]
else
project
.
repo
.
diff
(
last
.
id
,
first
.
id
)
rescue
[]
end
result
[
:commit
]
=
Commit
.
new
(
first
)
end
result
end
end
def
initialize
(
raw_commit
,
head
=
nil
)
raise
"Nil as raw commit passed"
unless
raw_commit
raise
"Nil as raw commit passed"
unless
raw_commit
@commit
=
raw_commit
@raw
=
raw_commit
@head
=
head
end
def
short_id
(
length
=
10
)
id
.
to_s
[
0
..
length
]
end
def
safe_message
@safe_message
||=
message
end
def
created_at
committed_date
end
def
author_email
author
.
email
end
def
author_name
author
.
name
end
# Was this commit committed by a different person than the original author?
def
different_committer?
author_name
!=
committer_name
||
author_email
!=
committer_email
end
def
committer_name
committer
.
name
end
def
committer_email
committer
.
email
end
def
prev_commit
@prev_commit
||=
if
parents
.
present?
Commit
.
new
(
parents
.
first
)
else
nil
end
end
def
prev_commit_id
prev_commit
.
try
:id
end
# Shows the diff between the commit's parent and the commit.
#
# Cuts out the header and stats from #to_patch and returns only the diff.
def
to_diff
# see Grit::Commit#show
patch
=
to_patch
# discard lines before the diff
lines
=
patch
.
split
(
"
\n
"
)
while
!
lines
.
first
.
start_with?
(
"diff --git"
)
do
lines
.
shift
end
lines
.
pop
if
lines
.
last
=~
/^[\d.]+$/
# Git version
lines
.
pop
if
lines
.
last
==
"-- "
# end of diff
lines
.
join
(
"
\n
"
)
end
end
def
has_zero_stats?
def
method_missing
(
m
,
*
args
,
&
block
)
stats
.
total
.
zero?
@raw
.
send
(
m
,
*
args
,
&
block
)
rescue
true
end
end
end
end
app/models/gollum_wiki.rb
View file @
154e54b4
...
@@ -50,7 +50,7 @@ class GollumWiki
...
@@ -50,7 +50,7 @@ class GollumWiki
# Returns the last 30 Commit objects across the entire
# Returns the last 30 Commit objects across the entire
# repository.
# repository.
def
recent_history
def
recent_history
Commit
.
fresh_commits
(
wiki
.
repo
,
30
)
Gitlab
::
Git
::
Commit
.
fresh_commits
(
wiki
.
repo
,
30
)
end
end
# Finds a page within the repository based on a tile
# Finds a page within the repository based on a tile
...
...
app/models/merge_request.rb
View file @
154e54b4
...
@@ -169,7 +169,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -169,7 +169,7 @@ class MergeRequest < ActiveRecord::Base
end
end
def
unmerged_commits
def
unmerged_commits
self
.
project
.
repo
.
self
.
project
.
repo
sitory
.
commits_between
(
self
.
target_branch
,
self
.
source_branch
).
commits_between
(
self
.
target_branch
,
self
.
source_branch
).
map
{
|
c
|
Commit
.
new
(
c
)}.
map
{
|
c
|
Commit
.
new
(
c
)}.
sort_by
(
&
:created_at
).
sort_by
(
&
:created_at
).
...
...
app/models/network/commit.rb
View file @
154e54b4
...
@@ -8,7 +8,7 @@ module Network
...
@@ -8,7 +8,7 @@ module Network
attr_accessor
:time
,
:spaces
,
:parent_spaces
attr_accessor
:time
,
:spaces
,
:parent_spaces
def
initialize
(
raw_commit
,
refs
)
def
initialize
(
raw_commit
,
refs
)
@commit
=
::
Commit
.
new
(
raw_commit
)
@commit
=
Gitlab
::
Git
::
Commit
.
new
(
raw_commit
)
@time
=
-
1
@time
=
-
1
@spaces
=
[]
@spaces
=
[]
@parent_spaces
=
[]
@parent_spaces
=
[]
...
...
app/models/note.rb
View file @
154e54b4
...
@@ -130,7 +130,7 @@ class Note < ActiveRecord::Base
...
@@ -130,7 +130,7 @@ class Note < ActiveRecord::Base
# override to return commits, which are not active record
# override to return commits, which are not active record
def
noteable
def
noteable
if
for_commit?
if
for_commit?
project
.
repository
.
commit
(
commit_id
)
Commit
.
new
(
project
.
repository
.
commit
(
commit_id
)
)
else
else
super
super
end
end
...
...
app/models/project.rb
View file @
154e54b4
...
@@ -142,11 +142,11 @@ class Project < ActiveRecord::Base
...
@@ -142,11 +142,11 @@ class Project < ActiveRecord::Base
def
repository
def
repository
if
path
if
path
@repository
||=
Repository
.
new
(
path_with_namespace
,
default_branch
)
@repository
||=
Gitlab
::
Git
::
Repository
.
new
(
path_with_namespace
,
default_branch
)
else
else
nil
nil
end
end
rescue
G
rit
::
NoSuchPathError
rescue
G
itlab
::
Git
::
NoRepository
nil
nil
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