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
dab072c1
Commit
dab072c1
authored
Nov 11, 2011
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor code: repository.rb
parent
99bd0015
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
82 additions
and
56 deletions
+82
-56
app/controllers/application_controller.rb
app/controllers/application_controller.rb
+1
-1
app/controllers/projects_controller.rb
app/controllers/projects_controller.rb
+1
-1
app/models/project.rb
app/models/project.rb
+15
-54
app/models/repository.rb
app/models/repository.rb
+65
-0
No files found.
app/controllers/application_controller.rb
View file @
dab072c1
...
@@ -64,7 +64,7 @@ class ApplicationController < ActionController::Base
...
@@ -64,7 +64,7 @@ class ApplicationController < ActionController::Base
else
else
@branch
=
params
[
:branch
].
blank?
?
nil
:
params
[
:branch
]
@branch
=
params
[
:branch
].
blank?
?
nil
:
params
[
:branch
]
@tag
=
params
[
:tag
].
blank?
?
nil
:
params
[
:tag
]
@tag
=
params
[
:tag
].
blank?
?
nil
:
params
[
:tag
]
@ref
=
@branch
||
@tag
||
"master"
@ref
=
@branch
||
@tag
||
Repository
.
default_ref
end
end
end
end
...
...
app/controllers/projects_controller.rb
View file @
dab072c1
...
@@ -108,7 +108,7 @@ class ProjectsController < ApplicationController
...
@@ -108,7 +108,7 @@ class ProjectsController < ApplicationController
if
params
[
:commit_id
]
if
params
[
:commit_id
]
@commit
=
@repo
.
commits
(
params
[
:commit_id
]).
first
@commit
=
@repo
.
commits
(
params
[
:commit_id
]).
first
else
else
@commit
=
@repo
.
commits
(
@ref
||
"master"
).
first
@commit
=
@repo
.
commits
(
@ref
).
first
end
end
@tree
=
@commit
.
tree
@tree
=
@commit
.
tree
...
...
app/models/project.rb
View file @
dab072c1
...
@@ -46,6 +46,21 @@ class Project < ActiveRecord::Base
...
@@ -46,6 +46,21 @@ class Project < ActiveRecord::Base
scope
:public_only
,
where
(
:private_flag
=>
false
)
scope
:public_only
,
where
(
:private_flag
=>
false
)
def
repository
@repository
||=
Repository
.
new
(
self
)
end
delegate
:repo
,
:tags
,
:repo_exists?
,
:commit
,
:commits
,
:tree
,
:heads
,
:commits_since
,
:fresh_commits
,
:to
=>
:repository
,
:prefix
=>
nil
def
to_param
def
to_param
code
code
end
end
...
@@ -114,18 +129,6 @@ class Project < ActiveRecord::Base
...
@@ -114,18 +129,6 @@ class Project < ActiveRecord::Base
GITOSIS
[
"base_path"
]
+
path
+
".git"
GITOSIS
[
"base_path"
]
+
path
+
".git"
end
end
def
repo
@repo
||=
Grit
::
Repo
.
new
(
path_to_repo
)
end
def
tags
repo
.
tags
.
map
(
&
:name
).
sort
.
reverse
end
def
repo_exists?
repo
rescue
false
end
def
last_activity
def
last_activity
updates
(
1
).
first
updates
(
1
).
first
rescue
rescue
...
@@ -146,48 +149,6 @@ class Project < ActiveRecord::Base
...
@@ -146,48 +149,6 @@ class Project < ActiveRecord::Base
end
[
0
...
n
]
end
[
0
...
n
]
end
end
def
commit
(
commit_id
=
nil
)
if
commit_id
repo
.
commits
(
commit_id
).
first
else
repo
.
commits
.
first
end
end
def
heads
@heads
||=
repo
.
heads
end
def
fresh_commits
(
n
=
10
)
commits
=
heads
.
map
do
|
h
|
repo
.
commits
(
h
.
name
,
n
)
end
.
flatten
.
uniq
{
|
c
|
c
.
id
}
commits
.
sort!
do
|
x
,
y
|
y
.
committed_date
<=>
x
.
committed_date
end
commits
[
0
...
n
]
end
def
commits_since
(
date
)
commits
=
heads
.
map
do
|
h
|
repo
.
log
(
h
.
name
,
nil
,
:since
=>
date
)
end
.
flatten
.
uniq
{
|
c
|
c
.
id
}
commits
.
sort!
do
|
x
,
y
|
y
.
committed_date
<=>
x
.
committed_date
end
commits
end
def
tree
(
fcommit
,
path
=
nil
)
fcommit
=
commit
if
fcommit
==
:head
tree
=
fcommit
.
tree
path
?
(
tree
/
path
)
:
tree
end
def
check_limit
def
check_limit
unless
owner
.
can_create_project?
unless
owner
.
can_create_project?
errors
[
:base
]
<<
(
"Your own projects limit is
#{
owner
.
projects_limit
}
! Please contact administrator to increase it"
)
errors
[
:base
]
<<
(
"Your own projects limit is
#{
owner
.
projects_limit
}
! Please contact administrator to increase it"
)
...
...
app/models/repository.rb
0 → 100644
View file @
dab072c1
class
Repository
attr_accessor
:project
def
self
.
default_ref
"master"
end
def
initialize
(
project
)
@project
=
project
end
def
repo
@repo
||=
Grit
::
Repo
.
new
(
project
.
path_to_repo
)
end
def
tags
repo
.
tags
.
map
(
&
:name
).
sort
.
reverse
end
def
repo_exists?
repo
rescue
false
end
def
commit
(
commit_id
=
nil
)
if
commit_id
repo
.
commits
(
commit_id
).
first
else
repo
.
commits
.
first
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
)
end
.
flatten
.
uniq
{
|
c
|
c
.
id
}
commits
.
sort!
do
|
x
,
y
|
y
.
committed_date
<=>
x
.
committed_date
end
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
)
end
.
flatten
.
uniq
{
|
c
|
c
.
id
}
commits
.
sort!
do
|
x
,
y
|
y
.
committed_date
<=>
x
.
committed_date
end
commits
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