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
Boxiang Sun
gitlab-ce
Commits
d730e3ef
Commit
d730e3ef
authored
Nov 11, 2011
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring project, commits controllers
parent
dab072c1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
45 deletions
+63
-45
app/controllers/commits_controller.rb
app/controllers/commits_controller.rb
+9
-9
app/controllers/projects_controller.rb
app/controllers/projects_controller.rb
+6
-8
app/models/project.rb
app/models/project.rb
+8
-16
app/models/repository.rb
app/models/repository.rb
+40
-12
No files found.
app/controllers/commits_controller.rb
View file @
d730e3ef
...
@@ -8,18 +8,18 @@ class CommitsController < ApplicationController
...
@@ -8,18 +8,18 @@ class CommitsController < ApplicationController
before_filter
:add_project_abilities
before_filter
:add_project_abilities
before_filter
:authorize_read_project!
before_filter
:authorize_read_project!
before_filter
:require_non_empty_project
before_filter
:require_non_empty_project
before_filter
:load_refs
,
:only
=>
:index
# load @branch, @tag & @ref
def
index
load_refs
# load @branch, @tag & @ref
def
index
@repo
=
project
.
repo
@repo
=
project
.
repo
limit
,
offset
=
(
params
[
:limit
]
||
20
),
(
params
[
:offset
]
||
0
)
limit
,
offset
=
(
params
[
:limit
]
||
20
),
(
params
[
:offset
]
||
0
)
if
params
[
:path
]
@commits
=
if
params
[
:path
]
@commits
=
@repo
.
log
(
@ref
,
params
[
:path
],
:max_count
=>
limit
,
:skip
=>
offset
)
@repo
.
log
(
@ref
,
params
[
:path
],
:max_count
=>
limit
,
:skip
=>
offset
)
else
else
@commits
=
@repo
.
commits
(
@ref
,
limit
,
offset
)
@repo
.
commits
(
@ref
,
limit
,
offset
)
end
end
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
# index.html.erb
format
.
html
# index.html.erb
...
@@ -29,8 +29,8 @@ class CommitsController < ApplicationController
...
@@ -29,8 +29,8 @@ class CommitsController < ApplicationController
def
show
def
show
@commit
=
project
.
repo
.
commits
(
params
[
:id
]).
first
@commit
=
project
.
repo
.
commits
(
params
[
:id
]).
first
@notes
=
project
.
notes
.
where
(
:noteable_id
=>
@commit
.
id
,
:noteable_type
=>
"Commit"
).
order
(
"created_at DESC"
)
.
limit
(
20
)
@notes
=
project
.
commit_notes
(
@commit
).
fresh
.
limit
(
20
)
@note
=
@project
.
notes
.
new
(
:noteable_id
=>
@commit
.
id
,
:noteable_type
=>
"Commit"
)
@note
=
@project
.
build_commit_note
(
@commit
)
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
format
.
html
...
...
app/controllers/projects_controller.rb
View file @
d730e3ef
...
@@ -6,8 +6,8 @@ class ProjectsController < ApplicationController
...
@@ -6,8 +6,8 @@ class ProjectsController < ApplicationController
before_filter
:add_project_abilities
before_filter
:add_project_abilities
before_filter
:authorize_read_project!
,
:except
=>
[
:index
,
:new
,
:create
]
before_filter
:authorize_read_project!
,
:except
=>
[
:index
,
:new
,
:create
]
before_filter
:authorize_admin_project!
,
:only
=>
[
:edit
,
:update
,
:destroy
]
before_filter
:authorize_admin_project!
,
:only
=>
[
:edit
,
:update
,
:destroy
]
before_filter
:require_non_empty_project
,
:only
=>
[
:blob
,
:tree
]
before_filter
:require_non_empty_project
,
:only
=>
[
:blob
,
:tree
]
before_filter
:load_refs
,
:only
=>
:tree
# load @branch, @tag & @ref
def
index
def
index
source
=
current_user
.
projects
source
=
current_user
.
projects
...
@@ -101,15 +101,13 @@ class ProjectsController < ApplicationController
...
@@ -101,15 +101,13 @@ class ProjectsController < ApplicationController
#
#
def
tree
def
tree
load_refs
# load @branch, @tag & @ref
@repo
=
project
.
repo
@repo
=
project
.
repo
if
params
[
:commit_id
]
@commit
=
if
params
[
:commit_id
]
@commit
=
@repo
.
commits
(
params
[
:commit_id
]).
first
@repo
.
commits
(
params
[
:commit_id
]).
first
else
else
@commit
=
@repo
.
commits
(
@ref
).
first
@repo
.
commits
(
@ref
).
first
end
end
@tree
=
@commit
.
tree
@tree
=
@commit
.
tree
@tree
=
@tree
/
params
[
:path
]
if
params
[
:path
]
@tree
=
@tree
/
params
[
:path
]
if
params
[
:path
]
...
...
app/models/project.rb
View file @
d730e3ef
...
@@ -51,6 +51,10 @@ class Project < ActiveRecord::Base
...
@@ -51,6 +51,10 @@ class Project < ActiveRecord::Base
end
end
delegate
:repo
,
delegate
:repo
,
:url_to_repo
,
:path_to_repo
,
:update_gitosis_project
,
:destroy_gitosis_project
,
:tags
,
:tags
,
:repo_exists?
,
:repo_exists?
,
:commit
,
:commit
,
...
@@ -74,16 +78,12 @@ class Project < ActiveRecord::Base
...
@@ -74,16 +78,12 @@ class Project < ActiveRecord::Base
notes
.
where
(
:noteable_type
=>
[
""
,
nil
])
notes
.
where
(
:noteable_type
=>
[
""
,
nil
])
end
end
def
update_gitosis_project
def
build_commit_note
(
commit
)
Gitosis
.
new
.
configure
do
|
c
|
notes
.
new
(
:noteable_id
=>
commit
.
id
,
:noteable_type
=>
"Commit"
)
c
.
update_project
(
path
,
gitosis_writers
)
end
end
end
def
destroy_gitosis_project
def
commit_notes
(
commit
)
Gitosis
.
new
.
configure
do
|
c
|
notes
.
where
(
:noteable_id
=>
commit
.
id
,
:noteable_type
=>
"Commit"
)
c
.
destroy_project
(
self
)
end
end
end
def
add_access
(
user
,
*
access
)
def
add_access
(
user
,
*
access
)
...
@@ -121,14 +121,6 @@ class Project < ActiveRecord::Base
...
@@ -121,14 +121,6 @@ class Project < ActiveRecord::Base
private_flag
private_flag
end
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
def
last_activity
updates
(
1
).
first
updates
(
1
).
first
rescue
rescue
...
...
app/models/repository.rb
View file @
d730e3ef
...
@@ -9,24 +9,48 @@ class Repository
...
@@ -9,24 +9,48 @@ class Repository
@project
=
project
@project
=
project
end
end
def
path
@path
||=
project
.
path
end
def
project_id
project
.
id
end
def
repo
def
repo
@repo
||=
Grit
::
Repo
.
new
(
project
.
path_to_repo
)
@repo
||=
Grit
::
Repo
.
new
(
project
.
path_to_repo
)
end
end
def
tags
def
url_to_repo
repo
.
tags
.
map
(
&
:name
).
sort
.
reverse
"
#{
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
end
def
repo_exists?
def
repo_exists?
repo
rescue
false
repo
rescue
false
end
end
def
commit
(
commit_id
=
nil
)
def
tags
if
commit_id
repo
.
tags
.
map
(
&
:name
).
sort
.
reverse
repo
.
commits
(
commit_id
).
first
end
else
repo
.
commits
.
first
def
heads
end
@heads
||=
repo
.
heads
end
end
def
tree
(
fcommit
,
path
=
nil
)
def
tree
(
fcommit
,
path
=
nil
)
...
@@ -35,6 +59,14 @@ class Repository
...
@@ -35,6 +59,14 @@ class Repository
path
?
(
tree
/
path
)
:
tree
path
?
(
tree
/
path
)
:
tree
end
end
def
commit
(
commit_id
=
nil
)
if
commit_id
repo
.
commits
(
commit_id
).
first
else
repo
.
commits
.
first
end
end
def
fresh_commits
(
n
=
10
)
def
fresh_commits
(
n
=
10
)
commits
=
heads
.
map
do
|
h
|
commits
=
heads
.
map
do
|
h
|
repo
.
commits
(
h
.
name
,
n
)
repo
.
commits
(
h
.
name
,
n
)
...
@@ -47,10 +79,6 @@ class Repository
...
@@ -47,10 +79,6 @@ class Repository
commits
[
0
...
n
]
commits
[
0
...
n
]
end
end
def
heads
@heads
||=
repo
.
heads
end
def
commits_since
(
date
)
def
commits_since
(
date
)
commits
=
heads
.
map
do
|
h
|
commits
=
heads
.
map
do
|
h
|
repo
.
log
(
h
.
name
,
nil
,
:since
=>
date
)
repo
.
log
(
h
.
name
,
nil
,
:since
=>
date
)
...
...
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