Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
5f4445c3
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 搜索 >>
提交
5f4445c3
编写于
4月 02, 2013
作者:
D
Dmitriy Zaporozhets
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
store commits for MR as array of hashes
上级
7af16bbb
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
113 addition
and
66 deletion
+113
-66
app/controllers/refs_controller.rb
app/controllers/refs_controller.rb
+1
-1
app/models/merge_request.rb
app/models/merge_request.rb
+12
-18
app/models/tree.rb
app/models/tree.rb
+8
-24
app/services/git_push_service.rb
app/services/git_push_service.rb
+1
-1
app/views/commits/_diffs.html.haml
app/views/commits/_diffs.html.haml
+1
-1
lib/extracts_path.rb
lib/extracts_path.rb
+1
-1
lib/gitlab/git/commit.rb
lib/gitlab/git/commit.rb
+51
-20
lib/gitlab/git/tree.rb
lib/gitlab/git/tree.rb
+38
-0
未找到文件。
app/controllers/refs_controller.rb
浏览文件 @
5f4445c3
...
...
@@ -48,7 +48,7 @@ class RefsController < ProjectResourceController
@repo
=
project
.
repository
@commit
=
@repo
.
commit
(
@ref
)
@tree
=
Tree
.
new
(
@
commit
.
tree
,
@ref
,
params
[
:path
])
@tree
=
Tree
.
new
(
@
repo
,
@commit
.
id
,
@ref
,
params
[
:path
])
@hex_path
=
Digest
::
SHA1
.
hexdigest
(
params
[
:path
]
||
""
)
if
params
[
:path
]
...
...
app/models/merge_request.rb
浏览文件 @
5f4445c3
...
...
@@ -152,17 +152,7 @@ class MergeRequest < ActiveRecord::Base
end
def
commits
if
st_commits
.
present?
# check if merge request commits are valid
if
st_commits
.
first
.
respond_to?
(
:short_id
)
st_commits
else
# if commits are invalid - simply reload it from repo
reloaded_commits
end
else
[]
end
load_commits
(
st_commits
)
||
[]
end
def
probably_merged?
...
...
@@ -172,13 +162,7 @@ class MergeRequest < ActiveRecord::Base
def
reloaded_commits
if
opened?
&&
unmerged_commits
.
any?
# we need to reset st_commits field first
# in order to prevent internal rails comparison
self
.
st_commits
=
[]
save
# Then we can safely write unmerged commits
self
.
st_commits
=
unmerged_commits
self
.
st_commits
=
dump_commits
(
unmerged_commits
)
save
end
commits
...
...
@@ -228,4 +212,14 @@ class MergeRequest < ActiveRecord::Base
def
last_commit_short_sha
@last_commit_short_sha
||=
last_commit
.
sha
[
0
..
10
]
end
private
def
dump_commits
(
commits
)
commits
.
map
(
&
:to_hash
)
end
def
load_commits
(
array
)
array
.
map
{
|
hash
|
Commit
.
new
(
Gitlab
::
Git
::
Commit
.
new
(
hash
))
}
end
end
app/models/tree.rb
浏览文件 @
5f4445c3
class
Tree
include
Linguist
::
BlobHelper
attr_accessor
:path
,
:tree
,
:ref
delegate
:contents
,
:basename
,
:name
,
:data
,
:mime_type
,
:mode
,
:size
,
:text?
,
:colorize
,
to: :tree
def
initialize
(
raw_tree
,
ref
=
nil
,
path
=
nil
)
@ref
,
@path
=
ref
,
path
@tree
=
if
path
.
present?
raw_tree
/
path
else
raw_tree
end
end
def
is_blob?
tree
.
is_a?
(
Grit
::
Blob
)
def
initialize
(
repository
,
sha
,
ref
=
nil
,
path
=
nil
)
@raw
=
Gitlab
::
Git
::
Tree
.
new
(
repository
,
sha
,
ref
,
path
)
end
def
invalid?
tree
.
nil?
@raw
.
nil?
end
def
empty?
data
.
blank?
def
method_missing
(
m
,
*
args
,
&
block
)
@raw
.
send
(
m
,
*
args
,
&
block
)
end
def
up_dir?
path
.
present?
end
def
respond_to?
(
method
)
return
true
if
@raw
.
respond_to?
(
method
)
def
readme
@readme
||=
contents
.
find
{
|
c
|
c
.
is_a?
(
Grit
::
Blob
)
and
c
.
name
=~
/^readme/i
}
super
end
end
app/services/git_push_service.rb
浏览文件 @
5f4445c3
...
...
@@ -104,7 +104,7 @@ class GitPushService
data
[
:commits
]
<<
{
id:
commit
.
id
,
message:
commit
.
safe_message
,
timestamp:
commit
.
date
.
xmlschema
,
timestamp:
commit
.
committed_
date
.
xmlschema
,
url:
"
#{
Gitlab
.
config
.
gitlab
.
url
}
/
#{
project
.
path_with_namespace
}
/commit/
#{
commit
.
id
}
"
,
author:
{
name:
commit
.
author_name
,
...
...
app/views/commits/_diffs.html.haml
浏览文件 @
5f4445c3
...
...
@@ -16,7 +16,7 @@
-
unless
@suppress_diff
-
diffs
.
each_with_index
do
|
diff
,
i
|
-
next
if
diff
.
diff
.
empty?
-
file
=
(
@commit
.
tree
/
diff
.
new_path
)
-
file
=
Tree
.
new
(
@repository
,
@commit
.
id
,
@ref
,
diff
.
new_path
)
-
file
=
(
@commit
.
prev_commit
.
tree
/
diff
.
old_path
)
unless
file
-
next
unless
file
.file
{
id:
"diff-#{i}"
}
...
...
lib/extracts_path.rb
浏览文件 @
5f4445c3
...
...
@@ -102,7 +102,7 @@ module ExtractsPath
# because "@project.repository.commit(@ref)" returns wrong commit when @ref is tag name.
@commit
=
@project
.
repository
.
commits
(
@ref
,
@path
,
1
,
0
).
first
@tree
=
Tree
.
new
(
@
commit
.
tree
,
@ref
,
@path
)
@tree
=
Tree
.
new
(
@
project
.
repository
,
@commit
.
id
,
@ref
,
@path
)
raise
InvalidPathError
if
@tree
.
invalid?
rescue
RuntimeError
,
NoMethodError
,
InvalidPathError
...
...
lib/gitlab/git/commit.rb
浏览文件 @
5f4445c3
...
...
@@ -4,13 +4,19 @@
module
Gitlab
module
Git
class
Commit
attr_accessor
:raw_commit
,
:head
,
:refs
attr_accessor
:raw_commit
,
:head
,
:refs
,
:sha
,
:authored_date
,
:committed_date
,
:message
,
:author_name
,
:author_email
,
:committer_name
,
:committer_email
delegate
:message
,
:authored_date
,
:committed_date
,
:parents
,
:sha
,
:date
,
:committer
,
:author
,
:diffs
,
:tree
,
:id
,
:stats
,
:to_patch
,
delegate
:parents
,
:diffs
,
:tree
,
:stats
,
:to_patch
,
to: :raw_commit
class
<<
self
def
serialize_keys
%w(sha authored_date committed_date author_name author_email committer_name committer_email message)
end
def
find_or_first
(
repo
,
commit_id
=
nil
,
root_ref
)
commit
=
if
commit_id
repo
.
commit
(
commit_id
)
...
...
@@ -73,10 +79,19 @@ module Gitlab
def
initialize
(
raw_commit
,
head
=
nil
)
raise
"Nil as raw commit passed"
unless
raw_commit
@raw_commit
=
raw_commit
if
raw_commit
.
is_a?
(
Hash
)
init_from_hash
(
raw_commit
)
else
init_from_grit
(
raw_commit
)
end
@head
=
head
end
def
id
sha
end
def
short_id
(
length
=
10
)
id
.
to_s
[
0
..
length
]
end
...
...
@@ -89,27 +104,11 @@ module Gitlab
committed_date
end
def
author_email
author
.
email
end
def
author_name
author
.
name
end
# Was this commit committed by a different person than the original author?
def
different_committer?
author_name
!=
committer_name
||
author_email
!=
committer_email
end
def
committer_name
committer
.
name
end
def
committer_email
committer
.
email
end
def
prev_commit
@prev_commit
||=
if
parents
.
present?
Commit
.
new
(
parents
.
first
)
...
...
@@ -148,6 +147,38 @@ module Gitlab
def
no_commit_message
"--no commit message"
end
def
to_hash
hash
=
{}
keys
=
Commit
.
serialize_keys
keys
.
each
do
|
key
|
hash
[
key
]
=
send
(
key
)
end
hash
end
private
def
init_from_grit
(
grit
)
@raw_commit
=
grit
@sha
=
grit
.
sha
@message
=
grit
.
message
@authored_date
=
grit
.
authored_date
@committed_date
=
grit
.
committed_date
@author_name
=
grit
.
author
.
name
@author_email
=
grit
.
author
.
email
@committer_name
=
grit
.
committer
.
name
@committer_email
=
grit
.
committer
.
email
end
def
init_from_hash
(
hash
)
Commit
.
serialize_keys
.
each
do
|
key
|
send
(
:"
#{
key
}
="
,
hash
[
key
])
end
end
end
end
end
lib/gitlab/git/tree.rb
0 → 100644
浏览文件 @
5f4445c3
module
Gitlab
module
Git
class
Tree
include
Linguist
::
BlobHelper
attr_accessor
:repository
,
:sha
,
:path
,
:ref
,
:raw_tree
def
initialize
(
repository
,
sha
,
ref
=
nil
,
path
=
nil
)
@repository
,
@sha
,
@ref
=
repository
,
sha
,
ref
# Load tree from repository
@commit
=
@repository
.
commit
(
sha
)
@raw_tree
=
@repository
.
tree
(
@commit
,
path
)
end
def
empty?
data
.
blank?
end
def
data
raw_tree
.
data
end
def
is_blob?
tree
.
is_a?
(
Grit
::
Blob
)
end
def
up_dir?
path
.
present?
end
def
readme
@readme
||=
contents
.
find
{
|
c
|
c
.
is_a?
(
Grit
::
Blob
)
and
c
.
name
=~
/^readme/i
}
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录