Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
b2ecf0aa
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 搜索 >>
提交
b2ecf0aa
编写于
7月 13, 2017
作者:
J
Jacob Vosmaer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change Git::Repository#log to return Commits
上级
e691f5b8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
90 addition
and
86 deletion
+90
-86
lib/gitlab/git/commit.rb
lib/gitlab/git/commit.rb
+1
-1
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+81
-77
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+8
-8
未找到文件。
lib/gitlab/git/commit.rb
浏览文件 @
b2ecf0aa
...
...
@@ -38,7 +38,7 @@ module Gitlab
repo
=
options
.
delete
(
:repo
)
raise
'Gitlab::Git::Repository is required'
unless
repo
.
respond_to?
(
:log
)
repo
.
log
(
options
)
.
map
{
|
c
|
decorate
(
c
)
}
repo
.
log
(
options
)
end
# Get single commit
...
...
lib/gitlab/git/repository.rb
浏览文件 @
b2ecf0aa
...
...
@@ -331,83 +331,7 @@ module Gitlab
# )
#
def
log
(
options
)
default_options
=
{
limit:
10
,
offset:
0
,
path:
nil
,
follow:
false
,
skip_merges:
false
,
disable_walk:
false
,
after:
nil
,
before:
nil
}
options
=
default_options
.
merge
(
options
)
options
[
:limit
]
||=
0
options
[
:offset
]
||=
0
actual_ref
=
options
[
:ref
]
||
root_ref
begin
sha
=
sha_from_ref
(
actual_ref
)
rescue
Rugged
::
OdbError
,
Rugged
::
InvalidError
,
Rugged
::
ReferenceError
# Return an empty array if the ref wasn't found
return
[]
end
if
log_using_shell?
(
options
)
log_by_shell
(
sha
,
options
)
else
log_by_walk
(
sha
,
options
)
end
end
def
log_using_shell?
(
options
)
options
[
:path
].
present?
||
options
[
:disable_walk
]
||
options
[
:skip_merges
]
||
options
[
:after
]
||
options
[
:before
]
end
def
log_by_walk
(
sha
,
options
)
walk_options
=
{
show:
sha
,
sort:
Rugged
::
SORT_NONE
,
limit:
options
[
:limit
],
offset:
options
[
:offset
]
}
Rugged
::
Walker
.
walk
(
rugged
,
walk_options
).
to_a
end
def
log_by_shell
(
sha
,
options
)
limit
=
options
[
:limit
].
to_i
offset
=
options
[
:offset
].
to_i
use_follow_flag
=
options
[
:follow
]
&&
options
[
:path
].
present?
# We will perform the offset in Ruby because --follow doesn't play well with --skip.
# See: https://gitlab.com/gitlab-org/gitlab-ce/issues/3574#note_3040520
offset_in_ruby
=
use_follow_flag
&&
options
[
:offset
].
present?
limit
+=
offset
if
offset_in_ruby
cmd
=
%W[
#{
Gitlab
.
config
.
git
.
bin_path
}
--git-dir=
#{
path
}
log]
cmd
<<
"--max-count=
#{
limit
}
"
cmd
<<
'--format=%H'
cmd
<<
"--skip=
#{
offset
}
"
unless
offset_in_ruby
cmd
<<
'--follow'
if
use_follow_flag
cmd
<<
'--no-merges'
if
options
[
:skip_merges
]
cmd
<<
"--after=
#{
options
[
:after
].
iso8601
}
"
if
options
[
:after
]
cmd
<<
"--before=
#{
options
[
:before
].
iso8601
}
"
if
options
[
:before
]
cmd
<<
sha
# :path can be a string or an array of strings
if
options
[
:path
].
present?
cmd
<<
'--'
cmd
+=
Array
(
options
[
:path
])
end
raw_output
=
IO
.
popen
(
cmd
)
{
|
io
|
io
.
read
}
lines
=
offset_in_ruby
?
raw_output
.
lines
.
drop
(
offset
)
:
raw_output
.
lines
lines
.
map!
{
|
c
|
Rugged
::
Commit
.
new
(
rugged
,
c
.
strip
)
}
raw_log
(
options
).
map
{
|
c
|
Commit
.
decorate
(
c
)
}
end
def
count_commits
(
options
)
...
...
@@ -912,6 +836,86 @@ module Gitlab
private
def
raw_log
(
options
)
default_options
=
{
limit:
10
,
offset:
0
,
path:
nil
,
follow:
false
,
skip_merges:
false
,
disable_walk:
false
,
after:
nil
,
before:
nil
}
options
=
default_options
.
merge
(
options
)
options
[
:limit
]
||=
0
options
[
:offset
]
||=
0
actual_ref
=
options
[
:ref
]
||
root_ref
begin
sha
=
sha_from_ref
(
actual_ref
)
rescue
Rugged
::
OdbError
,
Rugged
::
InvalidError
,
Rugged
::
ReferenceError
# Return an empty array if the ref wasn't found
return
[]
end
if
log_using_shell?
(
options
)
log_by_shell
(
sha
,
options
)
else
log_by_walk
(
sha
,
options
)
end
end
def
log_using_shell?
(
options
)
options
[
:path
].
present?
||
options
[
:disable_walk
]
||
options
[
:skip_merges
]
||
options
[
:after
]
||
options
[
:before
]
end
def
log_by_walk
(
sha
,
options
)
walk_options
=
{
show:
sha
,
sort:
Rugged
::
SORT_NONE
,
limit:
options
[
:limit
],
offset:
options
[
:offset
]
}
Rugged
::
Walker
.
walk
(
rugged
,
walk_options
).
to_a
end
def
log_by_shell
(
sha
,
options
)
limit
=
options
[
:limit
].
to_i
offset
=
options
[
:offset
].
to_i
use_follow_flag
=
options
[
:follow
]
&&
options
[
:path
].
present?
# We will perform the offset in Ruby because --follow doesn't play well with --skip.
# See: https://gitlab.com/gitlab-org/gitlab-ce/issues/3574#note_3040520
offset_in_ruby
=
use_follow_flag
&&
options
[
:offset
].
present?
limit
+=
offset
if
offset_in_ruby
cmd
=
%W[
#{
Gitlab
.
config
.
git
.
bin_path
}
--git-dir=
#{
path
}
log]
cmd
<<
"--max-count=
#{
limit
}
"
cmd
<<
'--format=%H'
cmd
<<
"--skip=
#{
offset
}
"
unless
offset_in_ruby
cmd
<<
'--follow'
if
use_follow_flag
cmd
<<
'--no-merges'
if
options
[
:skip_merges
]
cmd
<<
"--after=
#{
options
[
:after
].
iso8601
}
"
if
options
[
:after
]
cmd
<<
"--before=
#{
options
[
:before
].
iso8601
}
"
if
options
[
:before
]
cmd
<<
sha
# :path can be a string or an array of strings
if
options
[
:path
].
present?
cmd
<<
'--'
cmd
+=
Array
(
options
[
:path
])
end
raw_output
=
IO
.
popen
(
cmd
)
{
|
io
|
io
.
read
}
lines
=
offset_in_ruby
?
raw_output
.
lines
.
drop
(
offset
)
:
raw_output
.
lines
lines
.
map!
{
|
c
|
Rugged
::
Commit
.
new
(
rugged
,
c
.
strip
)
}
end
# We are trying to deprecate this method because it does a lot of work
# but it seems to be used only to look up submodule URL's.
# https://gitlab.com/gitlab-org/gitaly/issues/329
...
...
spec/lib/gitlab/git/repository_spec.rb
浏览文件 @
b2ecf0aa
...
...
@@ -705,9 +705,9 @@ describe Gitlab::Git::Repository, seed_helper: true do
# Add new commits so that there's a renamed file in the commit history
repo
=
Gitlab
::
Git
::
Repository
.
new
(
'default'
,
TEST_REPO_PATH
).
rugged
commit_with_old_name
=
new_commit_edit_old_file
(
repo
)
rename_commit
=
new_commit_move_file
(
repo
)
commit_with_new_name
=
new_commit_edit_new_file
(
repo
)
commit_with_old_name
=
Gitlab
::
Git
::
Commit
.
decorate
(
new_commit_edit_old_file
(
repo
)
)
rename_commit
=
Gitlab
::
Git
::
Commit
.
decorate
(
new_commit_move_file
(
repo
)
)
commit_with_new_name
=
Gitlab
::
Git
::
Commit
.
decorate
(
new_commit_edit_new_file
(
repo
)
)
end
after
(
:context
)
do
...
...
@@ -880,8 +880,8 @@ describe Gitlab::Git::Repository, seed_helper: true do
context
"compare results between log_by_walk and log_by_shell"
do
let
(
:options
)
{
{
ref:
"master"
}
}
let
(
:commits_by_walk
)
{
repository
.
log
(
options
).
map
(
&
:
o
id
)
}
let
(
:commits_by_shell
)
{
repository
.
log
(
options
.
merge
({
disable_walk:
true
})).
map
(
&
:
o
id
)
}
let
(
:commits_by_walk
)
{
repository
.
log
(
options
).
map
(
&
:id
)
}
let
(
:commits_by_shell
)
{
repository
.
log
(
options
.
merge
({
disable_walk:
true
})).
map
(
&
:id
)
}
it
{
expect
(
commits_by_walk
).
to
eq
(
commits_by_shell
)
}
...
...
@@ -924,7 +924,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
expect
(
commits
.
size
).
to
be
>
0
expect
(
commits
).
to
satisfy
do
|
commits
|
commits
.
all?
{
|
commit
|
commit
.
tim
e
>=
options
[
:after
]
}
commits
.
all?
{
|
commit
|
commit
.
committed_dat
e
>=
options
[
:after
]
}
end
end
end
...
...
@@ -937,7 +937,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
expect
(
commits
.
size
).
to
be
>
0
expect
(
commits
).
to
satisfy
do
|
commits
|
commits
.
all?
{
|
commit
|
commit
.
tim
e
<=
options
[
:before
]
}
commits
.
all?
{
|
commit
|
commit
.
committed_dat
e
<=
options
[
:before
]
}
end
end
end
...
...
@@ -946,7 +946,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
let
(
:options
)
{
{
ref:
'master'
,
path:
[
'PROCESS.md'
,
'README.md'
]
}
}
def
commit_files
(
commit
)
commit
.
diff
(
commit
.
parent_ids
.
first
)
.
deltas
.
flat_map
do
|
delta
|
commit
.
diff
_from_parent
.
deltas
.
flat_map
do
|
delta
|
[
delta
.
old_file
[
:path
],
delta
.
new_file
[
:path
]].
uniq
.
compact
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录