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
iv
gitlab-ce
Commits
97a4d8ae
Commit
97a4d8ae
authored
Feb 04, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve code according to new gitlab_git
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
bacfad1c
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
43 additions
and
15 deletions
+43
-15
app/helpers/gitlab_markdown_helper.rb
app/helpers/gitlab_markdown_helper.rb
+2
-2
app/models/repository.rb
app/models/repository.rb
+13
-1
app/models/tree.rb
app/models/tree.rb
+4
-0
lib/api/entities.rb
lib/api/entities.rb
+20
-1
lib/api/repositories.rb
lib/api/repositories.rb
+3
-10
lib/extracts_path.rb
lib/extracts_path.rb
+1
-1
No files found.
app/helpers/gitlab_markdown_helper.rb
View file @
97a4d8ae
...
@@ -166,13 +166,13 @@ module GitlabMarkdownHelper
...
@@ -166,13 +166,13 @@ module GitlabMarkdownHelper
def
file_exists?
(
path
)
def
file_exists?
(
path
)
return
false
if
path
.
nil?
||
path
.
empty?
return
false
if
path
.
nil?
||
path
.
empty?
return
@repository
.
blob_at
(
current_ref
,
path
).
present?
||
Tree
.
new
(
@repository
,
current_ref
,
path
).
entries
.
any?
return
@repository
.
blob_at
(
current_ref
,
path
).
present?
||
@repository
.
tree
(
:head
,
path
).
entries
.
any?
end
end
# Check if the path is pointing to a directory(tree) or a file(blob)
# Check if the path is pointing to a directory(tree) or a file(blob)
# eg. doc/api is directory and doc/README.md is file
# eg. doc/api is directory and doc/README.md is file
def
local_path
(
path
)
def
local_path
(
path
)
return
"tree"
if
Tree
.
new
(
@repository
,
current_ref
,
path
).
entries
.
any?
return
"tree"
if
@repository
.
tree
(
:head
,
path
).
entries
.
any?
return
"raw"
if
@repository
.
blob_at
(
current_ref
,
path
).
image?
return
"raw"
if
@repository
.
blob_at
(
current_ref
,
path
).
image?
return
"blob"
return
"blob"
end
end
...
...
app/models/repository.rb
View file @
97a4d8ae
...
@@ -163,7 +163,19 @@ class Repository
...
@@ -163,7 +163,19 @@ class Repository
def
readme
def
readme
Rails
.
cache
.
fetch
(
cache_key
(
:readme
))
do
Rails
.
cache
.
fetch
(
cache_key
(
:readme
))
do
Tree
.
new
(
self
,
self
.
root_ref
).
readme
tree
(
:head
).
readme
end
end
end
end
def
head_commit
commit
(
self
.
root_ref
)
end
def
tree
(
sha
=
:head
,
path
=
nil
)
if
sha
==
:head
sha
=
head_commit
.
sha
end
Tree
.
new
(
self
,
sha
,
path
)
end
end
end
app/models/tree.rb
View file @
97a4d8ae
...
@@ -23,4 +23,8 @@ class Tree
...
@@ -23,4 +23,8 @@ class Tree
def
submodules
def
submodules
@entries
.
select
(
&
:submodule?
)
@entries
.
select
(
&
:submodule?
)
end
end
def
sorted_entries
trees
+
blobs
+
submodules
end
end
end
lib/api/entities.rb
View file @
97a4d8ae
...
@@ -79,7 +79,16 @@ module API
...
@@ -79,7 +79,16 @@ module API
end
end
class
RepoObject
<
Grape
::
Entity
class
RepoObject
<
Grape
::
Entity
expose
:name
,
:commit
expose
:name
expose
:commit
do
|
repo_obj
,
options
|
if
repo_obj
.
respond_to?
(
:commit
)
repo_obj
.
commit
elsif
options
[
:project
]
options
[
:project
].
repository
.
commit
(
repo_obj
.
target
)
end
end
expose
:protected
do
|
repo
,
options
|
expose
:protected
do
|
repo
,
options
|
if
options
[
:project
]
if
options
[
:project
]
options
[
:project
].
protected_branch?
repo
.
name
options
[
:project
].
protected_branch?
repo
.
name
...
@@ -87,6 +96,16 @@ module API
...
@@ -87,6 +96,16 @@ module API
end
end
end
end
class
RepoTreeObject
<
Grape
::
Entity
expose
:id
,
:name
,
:type
expose
:mode
do
|
obj
,
options
|
filemode
=
obj
.
mode
.
to_s
(
8
)
filemode
=
"0"
+
filemode
if
filemode
.
length
<
6
filemode
end
end
class
RepoCommit
<
Grape
::
Entity
class
RepoCommit
<
Grape
::
Entity
expose
:id
,
:short_id
,
:title
,
:author_name
,
:author_email
,
:created_at
expose
:id
,
:short_id
,
:title
,
:author_name
,
:author_email
,
:created_at
end
end
...
...
lib/api/repositories.rb
View file @
97a4d8ae
...
@@ -82,7 +82,7 @@ module API
...
@@ -82,7 +82,7 @@ module API
# Example Request:
# Example Request:
# GET /projects/:id/repository/tags
# GET /projects/:id/repository/tags
get
":id/repository/tags"
do
get
":id/repository/tags"
do
present
user_project
.
repo
.
tags
.
sort_by
(
&
:name
).
reverse
,
with:
Entities
::
RepoObject
present
user_project
.
repo
.
tags
.
sort_by
(
&
:name
).
reverse
,
with:
Entities
::
RepoObject
,
project:
user_project
end
end
# Get a project repository commits
# Get a project repository commits
...
@@ -141,15 +141,9 @@ module API
...
@@ -141,15 +141,9 @@ module API
path
=
params
[
:path
]
||
nil
path
=
params
[
:path
]
||
nil
commit
=
user_project
.
repository
.
commit
(
ref
)
commit
=
user_project
.
repository
.
commit
(
ref
)
tree
=
Tree
.
new
(
user_project
.
repository
,
commit
.
id
,
path
)
tree
=
user_project
.
repository
.
tree
(
commit
.
id
,
path
)
trees
=
[]
present
tree
.
sorted_entries
,
with:
Entities
::
RepoTreeObject
%w(trees blobs submodules)
.
each
do
|
type
|
trees
+=
tree
.
send
(
type
).
map
{
|
t
|
{
name:
t
.
name
,
type:
type
.
singularize
,
mode:
t
.
mode
,
id:
t
.
id
}
}
end
trees
end
end
# Get a raw file contents
# Get a raw file contents
...
@@ -233,4 +227,3 @@ module API
...
@@ -233,4 +227,3 @@ module API
end
end
end
end
end
end
lib/extracts_path.rb
View file @
97a4d8ae
...
@@ -117,7 +117,7 @@ module ExtractsPath
...
@@ -117,7 +117,7 @@ module ExtractsPath
end
end
def
tree
def
tree
@tree
||=
Tree
.
new
(
@repo
,
@commit
.
id
,
@path
)
@tree
||=
@repo
.
tree
(
@commit
.
id
,
@path
)
end
end
private
private
...
...
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