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
49b024f5
Commit
49b024f5
authored
Apr 01, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Gitlab::Git:: for git features across application
parent
bb06e905
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
32 additions
and
64 deletions
+32
-64
app/controllers/blame_controller.rb
app/controllers/blame_controller.rb
+1
-2
app/controllers/compare_controller.rb
app/controllers/compare_controller.rb
+5
-5
app/models/commit.rb
app/models/commit.rb
+4
-0
app/models/gollum_wiki.rb
app/models/gollum_wiki.rb
+0
-1
app/models/repository.rb
app/models/repository.rb
+2
-8
app/models/wiki_page.rb
app/models/wiki_page.rb
+2
-2
app/views/blame/show.html.haml
app/views/blame/show.html.haml
+1
-1
app/views/compare/show.html.haml
app/views/compare/show.html.haml
+1
-1
app/views/wikis/show.html.haml
app/views/wikis/show.html.haml
+1
-2
lib/gitlab/git/commit.rb
lib/gitlab/git/commit.rb
+10
-40
spec/support/test_env.rb
spec/support/test_env.rb
+5
-2
No files found.
app/controllers/blame_controller.rb
View file @
49b024f5
...
@@ -8,7 +8,6 @@ class BlameController < ProjectResourceController
...
@@ -8,7 +8,6 @@ class BlameController < ProjectResourceController
before_filter
:require_non_empty_project
before_filter
:require_non_empty_project
def
show
def
show
@repo
=
@project
.
repo
@blame
=
Gitlab
::
Git
::
Blame
.
new
(
project
.
repository
,
@commit
.
id
,
@path
)
@blame
=
Grit
::
Blob
.
blame
(
@repo
,
@commit
.
id
,
@path
)
end
end
end
end
app/controllers/compare_controller.rb
View file @
49b024f5
...
@@ -8,12 +8,12 @@ class CompareController < ProjectResourceController
...
@@ -8,12 +8,12 @@ class CompareController < ProjectResourceController
end
end
def
show
def
show
result
=
Commit
.
compare
(
project
,
params
[
:from
],
params
[
:to
])
compare
=
Gitlab
::
Git
::
Compare
.
new
(
project
.
repository
,
params
[
:from
],
params
[
:to
])
@commits
=
result
[
:commits
]
@commits
=
compare
.
commits
@commit
=
result
[
:commit
]
@commit
=
compare
.
commit
@diffs
=
result
[
:diffs
]
@diffs
=
compare
.
diffs
@refs_are_same
=
result
[
:same
]
@refs_are_same
=
compare
.
same
@line_notes
=
[]
@line_notes
=
[]
end
end
...
...
app/models/commit.rb
View file @
49b024f5
...
@@ -8,6 +8,10 @@ class Commit
...
@@ -8,6 +8,10 @@ class Commit
#
#
DIFF_SAFE_SIZE
=
100
DIFF_SAFE_SIZE
=
100
def
self
.
decorate
(
commits
)
commits
.
map
{
|
c
|
self
.
new
(
c
)
}
end
attr_accessor
:raw
attr_accessor
:raw
def
initialize
(
raw_commit
)
def
initialize
(
raw_commit
)
...
...
app/models/gollum_wiki.rb
View file @
49b024f5
...
@@ -114,5 +114,4 @@ class GollumWiki
...
@@ -114,5 +114,4 @@ class GollumWiki
def
path_to_repo
def
path_to_repo
@path_to_repo
||=
File
.
join
(
Gitlab
.
config
.
gitlab_shell
.
repos_path
,
"
#{
path_with_namespace
}
.git"
)
@path_to_repo
||=
File
.
join
(
Gitlab
.
config
.
gitlab_shell
.
repos_path
,
"
#{
path_with_namespace
}
.git"
)
end
end
end
end
app/models/repository.rb
View file @
49b024f5
...
@@ -13,13 +13,13 @@ class Repository
...
@@ -13,13 +13,13 @@ class Repository
def
commits
(
ref
,
path
=
nil
,
limit
=
nil
,
offset
=
nil
)
def
commits
(
ref
,
path
=
nil
,
limit
=
nil
,
offset
=
nil
)
commits
=
raw_repository
.
commits
(
ref
,
path
,
limit
,
offset
)
commits
=
raw_repository
.
commits
(
ref
,
path
,
limit
,
offset
)
commits
=
decorate_commits
(
commits
)
if
commits
.
present?
commits
=
Commit
.
decorate
(
commits
)
if
commits
.
present?
commits
commits
end
end
def
commits_between
(
target
,
source
)
def
commits_between
(
target
,
source
)
commits
=
raw_repository
.
commits_between
(
target
,
source
)
commits
=
raw_repository
.
commits_between
(
target
,
source
)
commits
=
decorate_commits
(
commits
)
if
commits
.
present?
commits
=
Commit
.
decorate
(
commits
)
if
commits
.
present?
commits
commits
end
end
...
@@ -32,10 +32,4 @@ class Repository
...
@@ -32,10 +32,4 @@ class Repository
super
super
end
end
protected
def
decorate_commits
(
commits
)
commits
.
map
{
|
c
|
Commit
.
new
(
c
)
}
end
end
end
app/models/wiki_page.rb
View file @
49b024f5
...
@@ -79,14 +79,14 @@ class WikiPage
...
@@ -79,14 +79,14 @@ class WikiPage
def
version
def
version
return
nil
unless
persisted?
return
nil
unless
persisted?
@version
||=
Commit
.
new
(
@page
.
version
)
@version
||=
Commit
.
new
(
Gitlab
::
Git
::
Commit
.
new
(
@page
.
version
)
)
end
end
# Returns an array of Gitlab Commit instances.
# Returns an array of Gitlab Commit instances.
def
versions
def
versions
return
[]
unless
persisted?
return
[]
unless
persisted?
@page
.
versions
.
map
{
|
v
|
Commit
.
new
(
v
)
}
@page
.
versions
.
map
{
|
v
|
Commit
.
new
(
Gitlab
::
Git
::
Commit
.
new
(
v
)
)
}
end
end
# Returns the Date that this latest version was
# Returns the Date that this latest version was
...
...
app/views/blame/show.html.haml
View file @
49b024f5
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
%i
.icon-angle-right
%i
.icon-angle-right
=
link_to
project_tree_path
(
@project
,
@ref
)
do
=
link_to
project_tree_path
(
@project
,
@ref
)
do
=
@project
.
name
=
@project
.
name
-
@tree
.
breadcrumbs
(
6
)
do
|
link
|
-
tree_breadcrumbs
(
@tree
,
6
)
do
|
link
|
\/
\/
%li
=
link
%li
=
link
.clear
.clear
...
...
app/views/compare/show.html.haml
View file @
49b024f5
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
%div
.ui-box
%div
.ui-box
%h5
.title
%h5
.title
Commits (
#{
@commits
.
count
}
)
Commits (
#{
@commits
.
count
}
)
%ul
.well-list
=
render
@commits
%ul
.well-list
=
render
Commit
.
decorate
(
@commits
)
-
unless
@diffs
.
empty?
-
unless
@diffs
.
empty?
%h4
Diff
%h4
Diff
...
...
app/views/wikis/show.html.haml
View file @
49b024f5
...
@@ -13,5 +13,4 @@
...
@@ -13,5 +13,4 @@
=
preserve
do
=
preserve
do
=
render_wiki_content
(
@wiki
)
=
render_wiki_content
(
@wiki
)
-
commit
=
Commit
.
new
(
@wiki
.
version
)
%p
.time
Last edited by
#{
commit_author_link
(
@wiki
.
version
,
avatar:
true
,
size:
16
)
}
#{
time_ago_in_words
@wiki
.
created_at
}
ago
%p
.time
Last edited by
#{
commit_author_link
(
commit
,
avatar:
true
,
size:
16
)
}
#{
time_ago_in_words
@wiki
.
created_at
}
ago
lib/gitlab/git/commit.rb
View file @
49b024f5
# Gitlab::Git::
Gitlab::Git::
Commit is a wrapper around native Grit::Commit object
# Gitlab::Git::Commit is a wrapper around native Grit::Commit object
# We dont want to use grit objects inside app/
# We dont want to use grit objects inside app/
# It helps us easily migrate to rugged in future
# It helps us easily migrate to rugged in future
module
Gitlab
module
Gitlab
module
Git
module
Git
class
Gitlab::Git::
Commit
class
Commit
attr_accessor
:raw_commit
,
:head
,
:refs
attr_accessor
:raw_commit
,
:head
,
:refs
delegate
:message
,
:authored_date
,
:committed_date
,
:parents
,
:sha
,
delegate
:message
,
:authored_date
,
:committed_date
,
:parents
,
:sha
,
...
@@ -18,12 +18,12 @@ module Gitlab
...
@@ -18,12 +18,12 @@ module Gitlab
repo
.
commits
(
root_ref
).
first
repo
.
commits
(
root_ref
).
first
end
end
Gitlab
::
Git
::
Commit
.
new
(
commit
)
if
commit
Commit
.
new
(
commit
)
if
commit
end
end
def
fresh_commits
(
repo
,
n
=
10
)
def
fresh_commits
(
repo
,
n
=
10
)
commits
=
repo
.
heads
.
map
do
|
h
|
commits
=
repo
.
heads
.
map
do
|
h
|
repo
.
commits
(
h
.
name
,
n
).
map
{
|
c
|
Gitlab
::
Git
::
Commit
.
new
(
c
,
h
)
}
repo
.
commits
(
h
.
name
,
n
).
map
{
|
c
|
Commit
.
new
(
c
,
h
)
}
end
.
flatten
.
uniq
{
|
c
|
c
.
id
}
end
.
flatten
.
uniq
{
|
c
|
c
.
id
}
commits
.
sort!
do
|
x
,
y
|
commits
.
sort!
do
|
x
,
y
|
...
@@ -34,7 +34,7 @@ module Gitlab
...
@@ -34,7 +34,7 @@ module Gitlab
end
end
def
commits_with_refs
(
repo
,
n
=
20
)
def
commits_with_refs
(
repo
,
n
=
20
)
commits
=
repo
.
branches
.
map
{
|
ref
|
Gitlab
::
Git
::
Commit
.
new
(
ref
.
commit
,
ref
)
}
commits
=
repo
.
branches
.
map
{
|
ref
|
Commit
.
new
(
ref
.
commit
,
ref
)
}
commits
.
sort!
do
|
x
,
y
|
commits
.
sort!
do
|
x
,
y
|
y
.
committed_date
<=>
x
.
committed_date
y
.
committed_date
<=>
x
.
committed_date
...
@@ -45,7 +45,7 @@ module Gitlab
...
@@ -45,7 +45,7 @@ module Gitlab
def
commits_since
(
repo
,
date
)
def
commits_since
(
repo
,
date
)
commits
=
repo
.
heads
.
map
do
|
h
|
commits
=
repo
.
heads
.
map
do
|
h
|
repo
.
log
(
h
.
name
,
nil
,
since:
date
).
each
{
|
c
|
Gitlab
::
Git
::
Commit
.
new
(
c
,
h
)
}
repo
.
log
(
h
.
name
,
nil
,
since:
date
).
each
{
|
c
|
Commit
.
new
(
c
,
h
)
}
end
.
flatten
.
uniq
{
|
c
|
c
.
id
}
end
.
flatten
.
uniq
{
|
c
|
c
.
id
}
commits
.
sort!
do
|
x
,
y
|
commits
.
sort!
do
|
x
,
y
|
...
@@ -62,41 +62,11 @@ module Gitlab
...
@@ -62,41 +62,11 @@ module Gitlab
repo
.
commits
(
ref
,
limit
,
offset
)
repo
.
commits
(
ref
,
limit
,
offset
)
else
else
repo
.
commits
(
ref
)
repo
.
commits
(
ref
)
end
.
map
{
|
c
|
Gitlab
::
Git
::
Commit
.
new
(
c
)
}
end
.
map
{
|
c
|
Commit
.
new
(
c
)
}
end
end
def
commits_between
(
repo
,
from
,
to
)
def
commits_between
(
repo
,
from
,
to
)
repo
.
commits_between
(
from
,
to
).
map
{
|
c
|
Gitlab
::
Git
::
Commit
.
new
(
c
)
}
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
|
Gitlab
::
Git
::
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
]
=
Gitlab
::
Git
::
Commit
.
new
(
first
)
end
result
end
end
end
end
...
@@ -142,7 +112,7 @@ module Gitlab
...
@@ -142,7 +112,7 @@ module Gitlab
def
prev_commit
def
prev_commit
@prev_commit
||=
if
parents
.
present?
@prev_commit
||=
if
parents
.
present?
Gitlab
::
Git
::
Commit
.
new
(
parents
.
first
)
Commit
.
new
(
parents
.
first
)
else
else
nil
nil
end
end
...
@@ -156,7 +126,7 @@ module Gitlab
...
@@ -156,7 +126,7 @@ module Gitlab
#
#
# Cuts out the header and stats from #to_patch and returns only the diff.
# Cuts out the header and stats from #to_patch and returns only the diff.
def
to_diff
def
to_diff
# see Grit::
Gitlab::Git::
Commit#show
# see Grit::Commit#show
patch
=
to_patch
patch
=
to_patch
# discard lines before the diff
# discard lines before the diff
...
...
spec/support/test_env.rb
View file @
49b024f5
...
@@ -17,15 +17,18 @@ module TestEnv
...
@@ -17,15 +17,18 @@ module TestEnv
repos_path
=
Rails
.
root
.
join
(
'tmp'
,
'test-git-base-path'
)
repos_path
=
Rails
.
root
.
join
(
'tmp'
,
'test-git-base-path'
)
Gitlab
.
config
.
gitlab_shell
.
stub
(
repos_path:
repos_path
)
Gitlab
.
config
.
gitlab_shell
.
stub
(
repos_path:
repos_path
)
Gitlab
::
Shell
.
any_instance
.
stub
(
:add_repository
)
do
|
path
|
create_temp_repo
(
File
.
join
(
repos_path
,
"
#{
path
}
.git"
))
end
Gitlab
::
Shell
.
any_instance
.
stub
(
Gitlab
::
Shell
.
any_instance
.
stub
(
add_repository:
->
(
path
)
{
create_temp_repo
(
File
.
join
(
repos_path
,
"
#{
path
}
.git"
))
},
mv_repository:
true
,
mv_repository:
true
,
remove_repository:
true
,
remove_repository:
true
,
add_key:
true
,
add_key:
true
,
remove_key:
true
remove_key:
true
)
)
fake_satellite
=
double
(
fake_satellite
=
stub
(
exists?:
true
,
exists?:
true
,
destroy:
true
,
destroy:
true
,
create:
true
create:
true
...
...
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