Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
398ba6f1
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
398ba6f1
编写于
9月 17, 2012
作者:
R
Robert Speicher
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
DRY up Blame, Blob and Tree controllers
上级
576cec6c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
38 addition
and
73 deletion
+38
-73
app/controllers/blame_controller.rb
app/controllers/blame_controller.rb
+2
-25
app/controllers/blob_controller.rb
app/controllers/blob_controller.rb
+1
-23
app/controllers/tree_controller.rb
app/controllers/tree_controller.rb
+6
-23
app/views/tree/show.html.haml
app/views/tree/show.html.haml
+1
-1
app/views/tree/show.js.haml
app/views/tree/show.js.haml
+1
-1
lib/ref_extractor.rb
lib/ref_extractor.rb
+27
-0
未找到文件。
app/controllers/blame_controller.rb
浏览文件 @
398ba6f1
# Controller for viewing a file's blame
class
BlameController
<
ApplicationController
# Thrown when given an invalid path
class
InvalidPathError
<
StandardError
;
end
include
RefExtractor
...
...
@@ -15,31 +13,10 @@ class BlameController < ApplicationController
before_filter
:authorize_code_access!
before_filter
:require_non_empty_project
before_filter
:
define_tree
_vars
before_filter
:
assign_ref
_vars
def
show
@repo
=
@project
.
repo
@blame
=
Grit
::
Blob
.
blame
(
@repo
,
@commit
.
id
,
@path
)
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/blob_controller.rb
浏览文件 @
398ba6f1
...
...
@@ -16,7 +16,7 @@ class BlobController < ApplicationController
before_filter
:authorize_code_access!
before_filter
:require_non_empty_project
before_filter
:
define_tree
_vars
before_filter
:
assign_ref
_vars
def
show
if
@tree
.
is_blob?
...
...
@@ -37,26 +37,4 @@ class BlobController < ApplicationController
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/tree_controller.rb
浏览文件 @
398ba6f1
...
...
@@ -15,35 +15,18 @@ class TreeController < ApplicationController
before_filter
:authorize_code_access!
before_filter
:require_non_empty_project
before_filter
:
define_tree
_vars
before_filter
:
assign_ref
_vars
def
show
@hex_path
=
Digest
::
SHA1
.
hexdigest
(
@path
)
@history_path
=
project_tree_path
(
@project
,
@id
)
@logs_path
=
logs_file_project_ref_path
(
@project
,
@ref
,
@path
)
respond_to
do
|
format
|
format
.
html
# Disable cache so browser history works
format
.
js
{
no_cache_headers
}
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
.
gsub
(
/^\//
,
''
))
@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/views/tree/show.html.haml
浏览文件 @
398ba6f1
=
render
"head"
#tree-holder
=
render
partial:
"tree"
,
locals:
{
repo:
@repo
,
commit:
@commit
,
tree:
@tree
}
#tree-holder
=
render
partial:
"tree"
,
locals:
{
commit:
@commit
,
tree:
@tree
}
:javascript
$
(
function
()
{
...
...
app/views/tree/show.js.haml
浏览文件 @
398ba6f1
:plain
// Load Files list
$("#tree-holder").html("
#{
escape_javascript
(
render
(
partial:
"tree"
,
locals:
{
repo:
@repo
,
commit:
@commit
,
tree:
@tree
}))
}
");
$("#tree-holder").html("
#{
escape_javascript
(
render
(
partial:
"tree"
,
locals:
{
commit:
@commit
,
tree:
@tree
}))
}
");
$("#tree-content-holder").show("slide", { direction: "right" }, 150);
$('.project-refs-form #path').val("
#{
@path
}
");
...
...
lib/ref_extractor.rb
浏览文件 @
398ba6f1
...
...
@@ -67,4 +67,31 @@ module RefExtractor
pair
end
# Assigns common instance variables for views working with Git tree-ish objects
#
# Assignments are:
#
# - @id - A string representing the joined ref and path
# - @ref - A string representing the ref (e.g., the branch, tag, or commit SHA)
# - @path - A string representing the filesystem path
# - @commit - A CommitDecorator representing the commit from the given ref
# - @tree - A TreeDecorator representing the tree at the given ref/path
#
# Automatically renders `not_found!` if a valid tree could not be resolved
# (e.g., when a user inserts an invalid path or ref).
def
assign_ref_vars
@ref
,
@path
=
extract_ref
(
params
[
:id
])
@id
=
File
.
join
(
@ref
,
@path
)
@commit
=
CommitDecorator
.
decorate
(
@project
.
commit
(
@ref
))
@tree
=
Tree
.
new
(
@commit
.
tree
,
@project
,
@ref
,
@path
)
@tree
=
TreeDecorator
.
new
(
@tree
)
raise
InvalidPathError
if
@tree
.
invalid?
rescue
NoMethodError
,
InvalidPathError
not_found!
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录