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
Léo-Paul Géneau
gitlab-ce
Commits
576cec6c
Commit
576cec6c
authored
Sep 17, 2012
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add BlobController, remove Refs#blob
parent
39c65793
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
83 additions
and
65 deletions
+83
-65
app/controllers/blob_controller.rb
app/controllers/blob_controller.rb
+62
-0
app/controllers/refs_controller.rb
app/controllers/refs_controller.rb
+8
-41
app/views/blame/show.html.haml
app/views/blame/show.html.haml
+1
-1
app/views/commits/_diffs.html.haml
app/views/commits/_diffs.html.haml
+1
-1
app/views/tree/_tree_file.html.haml
app/views/tree/_tree_file.html.haml
+3
-3
config/routes.rb
config/routes.rb
+1
-7
spec/requests/security/project_access_spec.rb
spec/requests/security/project_access_spec.rb
+1
-1
spec/routing/project_routing_spec.rb
spec/routing/project_routing_spec.rb
+6
-11
No files found.
app/controllers/blob_controller.rb
0 → 100644
View file @
576cec6c
# Controller for viewing a file's blame
class
BlobController
<
ApplicationController
# Thrown when given an invalid path
class
InvalidPathError
<
StandardError
;
end
include
RefExtractor
include
Gitlab
::
Encode
layout
"project"
before_filter
:project
# Authorize
before_filter
:add_project_abilities
before_filter
:authorize_read_project!
before_filter
:authorize_code_access!
before_filter
:require_non_empty_project
before_filter
:define_tree_vars
def
show
if
@tree
.
is_blob?
if
@tree
.
text?
encoding
=
detect_encoding
(
@tree
.
data
)
mime_type
=
encoding
?
"text/plain; charset=
#{
encoding
}
"
:
"text/plain"
else
mime_type
=
@tree
.
mime_type
end
send_data
(
@tree
.
data
,
type:
mime_type
,
disposition:
'inline'
,
filename:
@tree
.
name
)
else
not_found!
end
end
private
def
define_tree_vars
@ref
,
@path
=
extract_ref
(
params
[
:id
])
@id
=
File
.
join
(
@ref
,
@path
)
@repo
=
@project
.
repo
@commit
=
CommitDecorator
.
decorate
(
@project
.
commit
(
@ref
))
@tree
=
Tree
.
new
(
@commit
.
tree
,
@project
,
@ref
,
@path
)
@tree
=
TreeDecorator
.
new
(
@tree
)
raise
InvalidPathError
if
@tree
.
invalid?
@hex_path
=
Digest
::
SHA1
.
hexdigest
(
@path
)
@history_path
=
project_tree_path
(
@project
,
@id
)
@logs_path
=
logs_file_project_ref_path
(
@project
,
@ref
,
@path
)
rescue
NoMethodError
,
InvalidPathError
not_found!
end
end
app/controllers/refs_controller.rb
View file @
576cec6c
...
...
@@ -18,9 +18,9 @@ class RefsController < ApplicationController
respond_to
do
|
format
|
format
.
html
do
new_path
=
if
params
[
:destination
]
==
"tree"
project_tree_path
(
@project
,
params
[
:ref
]
)
project_tree_path
(
@project
,
@ref
)
else
project_commits_path
(
@project
,
ref:
params
[
:ref
]
)
project_commits_path
(
@project
,
ref:
@ref
)
end
redirect_to
new_path
...
...
@@ -33,19 +33,6 @@ class RefsController < ApplicationController
end
end
#
# Repository preview
#
def
tree
respond_to
do
|
format
|
format
.
html
format
.
js
do
# disable cache to allow back button works
no_cache_headers
end
end
end
def
logs_tree
contents
=
@tree
.
contents
@logs
=
contents
.
map
do
|
content
|
...
...
@@ -59,26 +46,6 @@ class RefsController < ApplicationController
end
end
def
blob
if
@tree
.
is_blob?
if
@tree
.
text?
encoding
=
detect_encoding
(
@tree
.
data
)
mime_type
=
encoding
?
"text/plain; charset=
#{
encoding
}
"
:
"text/plain"
else
mime_type
=
@tree
.
mime_type
end
send_data
(
@tree
.
data
,
type:
mime_type
,
disposition:
'inline'
,
filename:
@tree
.
name
)
else
head
(
404
)
end
end
protected
def
define_tree_vars
...
...
app/views/blame/show.html.haml
View file @
576cec6c
...
...
@@ -18,7 +18,7 @@
=
@tree
.
name
%small
blame
%span
.options
=
link_to
"raw"
,
blob_project_ref_path
(
@project
,
@ref
,
path:
params
[
:path
]
),
class:
"btn very_small"
,
target:
"_blank"
=
link_to
"raw"
,
project_blob_path
(
@project
,
@id
),
class:
"btn very_small"
,
target:
"_blank"
=
link_to
"history"
,
project_commits_path
(
@project
,
path:
params
[
:path
],
ref:
@ref
),
class:
"btn very_small"
=
link_to
"source"
,
project_tree_path
(
@project
,
@id
),
class:
"btn very_small"
.file_content.blame
...
...
app/views/commits/_diffs.html.haml
View file @
576cec6c
...
...
@@ -24,7 +24,7 @@
%i
.icon-file
%span
{
id:
"#{diff.old_path}"
}=
diff
.
old_path
-
else
=
link_to
project_tree_path
(
@project
,
@commit
,
diff
.
new_path
)
do
=
link_to
project_tree_path
(
@project
,
tree_join
(
@commit
.
id
,
diff
.
new_path
)
)
do
%i
.icon-file
%span
{
id:
"#{diff.new_path}"
}=
diff
.
new_path
%br
/
...
...
app/views/tree/_tree_file.html.haml
View file @
576cec6c
...
...
@@ -5,8 +5,8 @@
=
name
.
force_encoding
(
'utf-8'
)
%small
#{
file
.
mode
}
%span
.options
=
link_to
"raw"
,
blob_project_ref_path
(
@project
,
@ref
,
path:
@path
),
class:
"btn very_small"
,
target:
"_blank"
=
link_to
"history"
,
project_commits_path
(
@project
,
path:
params
[
:path
]
,
ref:
@ref
),
class:
"btn very_small"
=
link_to
"raw"
,
project_blob_path
(
@project
,
@id
),
class:
"btn very_small"
,
target:
"_blank"
=
link_to
"history"
,
project_commits_path
(
@project
,
path:
@path
,
ref:
@ref
),
class:
"btn very_small"
=
link_to
"blame"
,
project_blame_path
(
@project
,
@id
),
class:
"btn very_small"
-
if
file
.
text?
-
if
gitlab_markdown?
(
name
)
...
...
@@ -32,7 +32,7 @@
-
else
.file_content.blob_file
%center
=
link_to
blob_project_ref_path
(
@project
,
@ref
,
path:
params
[
:path
]
)
do
=
link_to
project_blob_path
(
@project
,
@id
)
do
%div
.padded
%br
=
image_tag
"download.png"
,
width:
64
...
...
config/routes.rb
View file @
576cec6c
...
...
@@ -122,12 +122,6 @@ Gitlab::Application.routes.draw do
end
member
do
get
"blob"
,
constraints:
{
id:
/[a-zA-Z.0-9\/_\-]+/
,
path:
/.*/
}
# tree viewer logs
get
"logs_tree"
,
constraints:
{
id:
/[a-zA-Z.\/0-9_\-]+/
}
get
"logs_tree/:path"
=>
"refs#logs_tree"
,
...
...
@@ -197,7 +191,7 @@ Gitlab::Application.routes.draw do
# XXX: WIP
resources
:blame
,
only:
[
:show
],
constraints:
{
id:
/.+/
}
#
resources :blob, only: [:show], constraints: {id: /.+/}
resources
:blob
,
only:
[
:show
],
constraints:
{
id:
/.+/
}
# resources :raw, only: [:show], constraints: {id: /.+/}
resources
:tree
,
only:
[
:show
],
constraints:
{
id:
/.+/
}
end
...
...
spec/requests/security/project_access_spec.rb
View file @
576cec6c
...
...
@@ -95,7 +95,7 @@ describe "Application access" do
before
do
commit
=
@project
.
commit
path
=
commit
.
tree
.
contents
.
select
{
|
i
|
i
.
is_a?
(
Grit
::
Blob
)}.
first
.
name
@blob_path
=
blob_project_ref_path
(
@project
,
commit
.
id
,
path:
path
)
@blob_path
=
project_blob_path
(
@project
,
File
.
join
(
commit
.
id
,
path
)
)
end
it
{
@blob_path
.
should
be_allowed_for
@u1
}
...
...
spec/routing/project_routing_spec.rb
View file @
576cec6c
...
...
@@ -192,7 +192,6 @@ describe ProtectedBranchesController, "routing" do
end
# switch_project_refs GET /:project_id/switch(.:format) refs#switch
# blob_project_ref GET /:project_id/:id/blob(.:format) refs#blob
# logs_tree_project_ref GET /:project_id/:id/logs_tree(.:format) refs#logs_tree
# logs_file_project_ref GET /:project_id/:id/logs_tree/:path(.:format) refs#logs_tree
describe
RefsController
,
"routing"
do
...
...
@@ -204,10 +203,6 @@ describe RefsController, "routing" do
get
(
"/gitlabhq/stable/logs_tree"
).
should
route_to
(
'refs#logs_tree'
,
project_id:
'gitlabhq'
,
id:
'stable'
)
get
(
"/gitlabhq/stable/logs_tree/foo/bar/baz"
).
should
route_to
(
'refs#logs_tree'
,
project_id:
'gitlabhq'
,
id:
'stable'
,
path:
'foo/bar/baz'
)
end
it
"to #blob"
do
get
(
"/gitlabhq/stable/blob"
).
should
route_to
(
'refs#blob'
,
project_id:
'gitlabhq'
,
id:
'stable'
)
end
end
# diffs_project_merge_request GET /:project_id/merge_requests/:id/diffs(.:format) merge_requests#diffs
...
...
@@ -400,6 +395,12 @@ describe BlameController, "routing" do
end
end
describe
BlobController
,
"routing"
do
it
"to #show"
do
get
(
"/gitlabhq/blob/master/app/models/project.rb"
).
should
route_to
(
'blob#show'
,
project_id:
'gitlabhq'
,
id:
'master/app/models/project.rb'
)
end
end
describe
TreeController
,
"routing"
do
it
"to #show"
do
get
(
"/gitlabhq/tree/master/app/models/project.rb"
).
should
route_to
(
'tree#show'
,
project_id:
'gitlabhq'
,
id:
'master/app/models/project.rb'
)
...
...
@@ -435,12 +436,6 @@ end
describe
"pending routing"
do
before
{
pending
}
describe
"/:project_id/blob/:id"
do
it
"routes to a ref with a path"
do
get
(
"/gitlabhq/blob/master/app/models/project.rb"
).
should
route_to
(
'blob#show'
,
project_id:
'gitlabhq'
,
id:
'master/app/models/project.rb'
)
end
end
describe
"/:project_id/commit/:id"
do
it
"routes to a specific commit"
do
get
(
"/gitlabhq/commit/f4b1449"
).
should
route_to
(
'commit#show'
,
project_id:
'gitlabhq'
,
id:
'f4b1449'
)
...
...
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