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
97a9c229
Commit
97a9c229
authored
Apr 14, 2013
by
Sato Hiroyuki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor: remove dup code
parent
edcdbd67
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
38 deletions
+22
-38
app/controllers/refs_controller.rb
app/controllers/refs_controller.rb
+5
-30
app/controllers/tree_controller.rb
app/controllers/tree_controller.rb
+0
-3
app/views/graph/_head.html.haml
app/views/graph/_head.html.haml
+2
-2
lib/extracts_path.rb
lib/extracts_path.rb
+15
-3
No files found.
app/controllers/refs_controller.rb
View file @
97a9c229
class
RefsController
<
ProjectResourceController
include
ExtractsPath
# Authorize
before_filter
:authorize_read_project!
before_filter
:authorize_code_access!
before_filter
:require_non_empty_project
before_filter
:ref
before_filter
:define_tree_vars
,
only:
[
:blob
,
:logs_tree
]
def
switch
respond_to
do
|
format
|
format
.
html
do
new_path
=
if
params
[
:destination
]
==
"tree"
project_tree_path
(
@project
,
(
@
ref
+
"/"
+
params
[
:path
]
))
project_tree_path
(
@project
,
(
@
id
))
elsif
params
[
:destination
]
==
"blob"
project_blob_path
(
@project
,
(
@
ref
+
"/"
+
params
[
:path
]
))
project_blob_path
(
@project
,
(
@
id
))
elsif
params
[
:destination
]
==
"graph"
project_graph_path
(
@project
,
@
ref
)
project_graph_path
(
@project
,
@
id
)
else
project_commits_path
(
@project
,
@
ref
)
project_commits_path
(
@project
,
@
id
)
end
redirect_to
new_path
...
...
@@ -42,27 +40,4 @@ class RefsController < ProjectResourceController
}
end
end
protected
def
define_tree_vars
params
[
:path
]
=
nil
if
params
[
:path
].
blank?
@repo
=
project
.
repository
@commit
=
@repo
.
commit
(
@ref
)
@tree
=
Tree
.
new
(
@repo
,
@commit
.
id
,
@ref
,
params
[
:path
])
@hex_path
=
Digest
::
SHA1
.
hexdigest
(
params
[
:path
]
||
""
)
if
params
[
:path
]
@logs_path
=
logs_file_project_ref_path
(
@project
,
@ref
,
params
[
:path
])
else
@logs_path
=
logs_tree_project_ref_path
(
@project
,
@ref
)
end
rescue
return
render_404
end
def
ref
@ref
=
params
[
:id
]
||
params
[
:ref
]
end
end
app/controllers/tree_controller.rb
View file @
97a9c229
...
...
@@ -8,9 +8,6 @@ class TreeController < ProjectResourceController
before_filter
:require_non_empty_project
def
show
@hex_path
=
Digest
::
SHA1
.
hexdigest
(
@path
)
@logs_path
=
logs_file_project_ref_path
(
@project
,
@ref
,
@path
)
respond_to
do
|
format
|
format
.
html
# Disable cache so browser history works
...
...
app/views/graph/_head.html.haml
View file @
97a9c229
...
...
@@ -3,10 +3,10 @@
.clearfix
.pull-left
=
render
partial:
'shared/ref_switcher'
,
locals:
{
destination:
'graph'
,
path:
@path
}
=
render
partial:
'shared/ref_switcher'
,
locals:
{
destination:
'graph'
}
.search.pull-right
=
form_tag
project_graph_path
(
@project
,
params
[
:id
]
),
method: :get
do
|
f
|
=
form_tag
project_graph_path
(
@project
,
@id
),
method: :get
do
|
f
|
.control-group
=
label_tag
:search
,
"Looking for commit:"
,
class:
'control-label light'
.controls
...
...
lib/extracts_path.rb
View file @
97a9c229
...
...
@@ -94,16 +94,28 @@ module ExtractsPath
# Automatically renders `not_found!` if a valid tree path could not be
# resolved (e.g., when a user inserts an invalid path or ref).
def
assign_ref_vars
@id
=
params
[
:id
]
@id
=
get_id
@ref
,
@path
=
extract_ref
(
@id
)
@
commit
=
@project
.
repository
.
commit
(
@ref
)
@
repo
=
@project
.
repository
@tree
=
Tree
.
new
(
@project
.
repository
,
@commit
.
id
,
@ref
,
@path
)
@commit
=
@repo
.
commit
(
@ref
)
@tree
=
Tree
.
new
(
@repo
,
@commit
.
id
,
@ref
,
@path
)
@hex_path
=
Digest
::
SHA1
.
hexdigest
(
@path
)
@logs_path
=
logs_file_project_ref_path
(
@project
,
@ref
,
@path
)
raise
InvalidPathError
unless
@tree
.
exists?
rescue
RuntimeError
,
NoMethodError
,
InvalidPathError
not_found!
end
private
def
get_id
id
=
params
[
:id
]
||
params
[
:ref
]
id
+=
"/"
+
params
[
:path
]
unless
params
[
:path
].
blank?
id
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