Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
38cbec86a9d9
Commit
38cbec86
authored
Nov 11, 2011
by
Dmitriy Zaporozhets
Browse files
refactoring project, commits controllers
parent
ffb3b3f64634
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/controllers/commits_controller.rb
View file @
38cbec86
...
...
@@ -8,5 +8,7 @@
before_filter
:add_project_abilities
before_filter
:authorize_read_project!
before_filter
:require_non_empty_project
before_filter
:load_refs
,
:only
=>
:index
# load @branch, @tag & @ref
def
index
...
...
@@ -11,7 +13,5 @@
def
index
load_refs
# load @branch, @tag & @ref
@repo
=
project
.
repo
limit
,
offset
=
(
params
[
:limit
]
||
20
),
(
params
[
:offset
]
||
0
)
...
...
@@ -15,11 +15,11 @@
@repo
=
project
.
repo
limit
,
offset
=
(
params
[
:limit
]
||
20
),
(
params
[
:offset
]
||
0
)
if
params
[
:path
]
@commits
=
@repo
.
log
(
@ref
,
params
[
:path
],
:max_count
=>
limit
,
:skip
=>
offset
)
else
@commits
=
@repo
.
commits
(
@ref
,
limit
,
offset
)
end
@commits
=
if
params
[
:path
]
@repo
.
log
(
@ref
,
params
[
:path
],
:max_count
=>
limit
,
:skip
=>
offset
)
else
@repo
.
commits
(
@ref
,
limit
,
offset
)
end
respond_to
do
|
format
|
format
.
html
# index.html.erb
...
...
@@ -29,8 +29,8 @@
def
show
@commit
=
project
.
repo
.
commits
(
params
[
:id
]).
first
@notes
=
project
.
notes
.
where
(
:noteable_id
=>
@commit
.
id
,
:noteable_type
=>
"C
ommit
"
).
order
(
"created_at DESC"
)
.
limit
(
20
)
@note
=
@project
.
notes
.
new
(
:noteable_id
=>
@commit
.
id
,
:noteable_type
=>
"C
ommit
"
)
@notes
=
project
.
commit_notes
(
@c
ommit
).
fresh
.
limit
(
20
)
@note
=
@project
.
build_commit_note
(
@c
ommit
)
respond_to
do
|
format
|
format
.
html
...
...
app/controllers/projects_controller.rb
View file @
38cbec86
...
...
@@ -6,5 +6,4 @@
before_filter
:add_project_abilities
before_filter
:authorize_read_project!
,
:except
=>
[
:index
,
:new
,
:create
]
before_filter
:authorize_admin_project!
,
:only
=>
[
:edit
,
:update
,
:destroy
]
before_filter
:require_non_empty_project
,
:only
=>
[
:blob
,
:tree
]
...
...
@@ -10,4 +9,5 @@
before_filter
:require_non_empty_project
,
:only
=>
[
:blob
,
:tree
]
before_filter
:load_refs
,
:only
=>
:tree
# load @branch, @tag & @ref
def
index
source
=
current_user
.
projects
...
...
@@ -101,7 +101,5 @@
#
def
tree
load_refs
# load @branch, @tag & @ref
@repo
=
project
.
repo
...
...
@@ -106,10 +104,10 @@
@repo
=
project
.
repo
if
params
[
:commit_id
]
@commit
=
@repo
.
commits
(
params
[
:commit_id
]).
first
else
@commit
=
@repo
.
commits
(
@ref
).
first
end
@commit
=
if
params
[
:commit_id
]
@repo
.
commits
(
params
[
:commit_id
]).
first
else
@repo
.
commits
(
@ref
).
first
end
@tree
=
@commit
.
tree
@tree
=
@tree
/
params
[
:path
]
if
params
[
:path
]
...
...
app/models/project.rb
View file @
38cbec86
...
...
@@ -51,6 +51,10 @@
end
delegate
:repo
,
:url_to_repo
,
:path_to_repo
,
:update_gitosis_project
,
:destroy_gitosis_project
,
:tags
,
:repo_exists?
,
:commit
,
...
...
@@ -74,9 +78,7 @@
notes
.
where
(
:noteable_type
=>
[
""
,
nil
])
end
def
update_gitosis_project
Gitosis
.
new
.
configure
do
|
c
|
c
.
update_project
(
path
,
gitosis_writers
)
end
def
build_commit_note
(
commit
)
notes
.
new
(
:noteable_id
=>
commit
.
id
,
:noteable_type
=>
"Commit"
)
end
...
...
@@ -81,9 +83,7 @@
end
def
destroy_gitosis_project
Gitosis
.
new
.
configure
do
|
c
|
c
.
destroy_project
(
self
)
end
def
commit_notes
(
commit
)
notes
.
where
(
:noteable_id
=>
commit
.
id
,
:noteable_type
=>
"Commit"
)
end
def
add_access
(
user
,
*
access
)
...
...
@@ -121,14 +121,6 @@
private_flag
end
def
url_to_repo
"
#{
GITOSIS
[
"git_user"
]
}
@
#{
GITOSIS
[
"host"
]
}
:
#{
path
}
.git"
end
def
path_to_repo
GITOSIS
[
"base_path"
]
+
path
+
".git"
end
def
last_activity
updates
(
1
).
first
rescue
...
...
app/models/repository.rb
View file @
38cbec86
...
...
@@ -9,7 +9,15 @@
@project
=
project
end
def
path
@path
||=
project
.
path
end
def
project_id
project
.
id
end
def
repo
@repo
||=
Grit
::
Repo
.
new
(
project
.
path_to_repo
)
end
...
...
@@ -12,8 +20,32 @@
def
repo
@repo
||=
Grit
::
Repo
.
new
(
project
.
path_to_repo
)
end
def
url_to_repo
"
#{
GITOSIS
[
"git_user"
]
}
@
#{
GITOSIS
[
"host"
]
}
:
#{
path
}
.git"
end
def
path_to_repo
GITOSIS
[
"base_path"
]
+
path
+
".git"
end
def
update_gitosis_project
Gitosis
.
new
.
configure
do
|
c
|
c
.
update_project
(
path
,
project
.
gitosis_writers
)
end
end
def
destroy_gitosis_project
Gitosis
.
new
.
configure
do
|
c
|
c
.
destroy_project
(
@project
)
end
end
def
repo_exists?
repo
rescue
false
end
def
tags
repo
.
tags
.
map
(
&
:name
).
sort
.
reverse
end
...
...
@@ -16,9 +48,15 @@
def
tags
repo
.
tags
.
map
(
&
:name
).
sort
.
reverse
end
def
repo_exists?
repo
rescue
false
def
heads
@heads
||=
repo
.
heads
end
def
tree
(
fcommit
,
path
=
nil
)
fcommit
=
commit
if
fcommit
==
:head
tree
=
fcommit
.
tree
path
?
(
tree
/
path
)
:
tree
end
def
commit
(
commit_id
=
nil
)
...
...
@@ -29,12 +67,6 @@
end
end
def
tree
(
fcommit
,
path
=
nil
)
fcommit
=
commit
if
fcommit
==
:head
tree
=
fcommit
.
tree
path
?
(
tree
/
path
)
:
tree
end
def
fresh_commits
(
n
=
10
)
commits
=
heads
.
map
do
|
h
|
repo
.
commits
(
h
.
name
,
n
)
...
...
@@ -47,10 +79,6 @@
commits
[
0
...
n
]
end
def
heads
@heads
||=
repo
.
heads
end
def
commits_since
(
date
)
commits
=
heads
.
map
do
|
h
|
repo
.
log
(
h
.
name
,
nil
,
:since
=>
date
)
...
...
Write
Preview
Supports
Markdown
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