Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
8c972f9d
C
Coca
项目概览
Phodal
/
Coca
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Coca
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
8c972f9d
编写于
12月 21, 2019
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: use reverse for git history change
上级
947cb814
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
36 addition
and
21 deletion
+36
-21
core/domain/gitt/README.md
core/domain/gitt/README.md
+1
-1
core/domain/gitt/gitt.go
core/domain/gitt/gitt.go
+13
-11
test/gitt_test.go
test/gitt_test.go
+22
-9
未找到文件。
core/domain/gitt/README.md
浏览文件 @
8c972f9d
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
GitLogs
GitLogs
```
```
git log --all --numstat --date=short --pretty="format:[%h] %aN %ad %s" --numstat
git log --all --numstat --date=short --pretty="format:[%h] %aN %ad %s" --numstat
--reverse
```
```
Related Projects:
[
https://github.com/bast/gitink
](
https://github.com/bast/gitink
)
Related Projects:
[
https://github.com/bast/gitink
](
https://github.com/bast/gitink
)
...
...
core/domain/gitt/gitt.go
浏览文件 @
8c972f9d
...
@@ -18,7 +18,6 @@ var currentCommitMessage CommitMessage
...
@@ -18,7 +18,6 @@ var currentCommitMessage CommitMessage
var
currentFileChanges
[]
FileChange
var
currentFileChanges
[]
FileChange
var
commitMessages
[]
CommitMessage
var
commitMessages
[]
CommitMessage
var
(
var
(
rev
=
`\[([\d|a-f]{5,12})\]`
rev
=
`\[([\d|a-f]{5,12})\]`
author
=
`(.*?)\s\d{4}-\d{2}-\d{2}`
author
=
`(.*?)\s\d{4}-\d{2}-\d{2}`
...
@@ -34,7 +33,7 @@ var (
...
@@ -34,7 +33,7 @@ var (
)
)
func
BuildCommitMessage
()
[]
CommitMessage
{
func
BuildCommitMessage
()
[]
CommitMessage
{
historyArgs
:=
[]
string
{
"log"
,
"--pretty=format:[%h] %aN %ad %s"
,
"--date=short"
,
"--numstat"
}
historyArgs
:=
[]
string
{
"log"
,
"--pretty=format:[%h] %aN %ad %s"
,
"--date=short"
,
"--numstat"
,
"--reverse"
}
cmd
:=
exec
.
Command
(
"git"
,
historyArgs
...
)
cmd
:=
exec
.
Command
(
"git"
,
historyArgs
...
)
out
,
err
:=
cmd
.
CombinedOutput
()
out
,
err
:=
cmd
.
CombinedOutput
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -91,20 +90,21 @@ func GetTeamSummary(messages []CommitMessage) []TeamSummary {
...
@@ -91,20 +90,21 @@ func GetTeamSummary(messages []CommitMessage) []TeamSummary {
infos
:=
make
(
map
[
string
]
TeamInformation
)
infos
:=
make
(
map
[
string
]
TeamInformation
)
for
_
,
commitMessage
:=
range
messages
{
for
_
,
commitMessage
:=
range
messages
{
for
_
,
change
:=
range
commitMessage
.
Changes
{
for
_
,
change
:=
range
commitMessage
.
Changes
{
if
moveReg
.
MatchString
(
change
.
File
)
{
fileName
:=
change
.
File
infos
=
switchFile
(
infos
,
change
.
File
)
if
moveReg
.
MatchString
(
fileName
)
{
infos
,
fileName
=
switchFile
(
infos
,
fileName
)
}
}
if
infos
[
change
.
Fil
e
]
.
EntityName
==
""
{
if
infos
[
fileNam
e
]
.
EntityName
==
""
{
authors
:=
make
(
map
[
string
]
string
)
authors
:=
make
(
map
[
string
]
string
)
authors
[
commitMessage
.
Author
]
=
commitMessage
.
Author
authors
[
commitMessage
.
Author
]
=
commitMessage
.
Author
revs
:=
make
(
map
[
string
]
string
)
revs
:=
make
(
map
[
string
]
string
)
revs
[
commitMessage
.
Rev
]
=
commitMessage
.
Rev
revs
[
commitMessage
.
Rev
]
=
commitMessage
.
Rev
infos
[
change
.
File
]
=
*&
TeamInformation
{
change
.
Fil
e
,
authors
,
revs
}
infos
[
fileName
]
=
*&
TeamInformation
{
fileNam
e
,
authors
,
revs
}
}
else
{
}
else
{
infos
[
change
.
Fil
e
]
.
Authors
[
commitMessage
.
Author
]
=
commitMessage
.
Author
infos
[
fileNam
e
]
.
Authors
[
commitMessage
.
Author
]
=
commitMessage
.
Author
infos
[
change
.
Fil
e
]
.
Revs
[
commitMessage
.
Rev
]
=
commitMessage
.
Rev
infos
[
fileNam
e
]
.
Revs
[
commitMessage
.
Rev
]
=
commitMessage
.
Rev
}
}
}
}
}
}
...
@@ -122,22 +122,24 @@ func GetTeamSummary(messages []CommitMessage) []TeamSummary {
...
@@ -122,22 +122,24 @@ func GetTeamSummary(messages []CommitMessage) []TeamSummary {
}
}
// 反向查询
// 反向查询
func
switchFile
(
infos
map
[
string
]
TeamInformation
,
changedFile
string
)
map
[
string
]
TeamInformation
{
func
switchFile
(
infos
map
[
string
]
TeamInformation
,
changedFile
string
)
(
map
[
string
]
TeamInformation
,
string
)
{
changed
:=
moveReg
.
FindStringSubmatch
(
changedFile
)
changed
:=
moveReg
.
FindStringSubmatch
(
changedFile
)
// examples: cmd/{call_graph.go => call.go}
// examples: cmd/{call_graph.go => call.go}
if
len
(
changed
)
>=
5
{
if
len
(
changed
)
>=
5
{
oldFileName
:=
changed
[
1
]
+
changed
[
2
]
+
changed
[
4
]
oldFileName
:=
changed
[
1
]
+
changed
[
2
]
+
changed
[
4
]
newFileName
:=
changed
[
1
]
+
changed
[
3
]
+
changed
[
4
]
newFileName
:=
changed
[
1
]
+
changed
[
3
]
+
changed
[
4
]
fmt
.
Println
(
infos
,
oldFileName
,
newFileName
)
if
_
,
ok
:=
infos
[
oldFileName
];
ok
{
if
_
,
ok
:=
infos
[
oldFileName
];
ok
{
oldInfo
:=
infos
[
oldFileName
]
oldInfo
:=
infos
[
oldFileName
]
delete
(
infos
,
oldFileName
)
delete
(
infos
,
oldFileName
)
oldInfo
.
EntityName
=
newFileName
infos
[
newFileName
]
=
oldInfo
infos
[
newFileName
]
=
oldInfo
changedFile
=
newFileName
}
}
}
}
return
infos
return
infos
,
changedFile
}
}
type
TopAuthor
struct
{
type
TopAuthor
struct
{
...
...
test/gitt_test.go
浏览文件 @
8c972f9d
...
@@ -2,7 +2,6 @@ package test_test
...
@@ -2,7 +2,6 @@ package test_test
import
(
import
(
"coca/core/domain/gitt"
"coca/core/domain/gitt"
"fmt"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
.
"github.com/onsi/gomega"
)
)
...
@@ -30,25 +29,39 @@ var _ = Describe("Git Parser", func() {
...
@@ -30,25 +29,39 @@ var _ = Describe("Git Parser", func() {
Context
(
"Test for Move file"
,
func
()
{
Context
(
"Test for Move file"
,
func
()
{
It
(
"should have a current file move update"
,
func
()
{
It
(
"should have a current file move update"
,
func
()
{
messages
:=
gitt
.
BuildMessageByInput
(
`
messages
:=
gitt
.
BuildMessageByInput
(
`
[d00f01214b] Phodal Huang 2019-12-19 update files
[d00f0124d] Phodal Huang 2019-12-19 update files
0 0 core/domain/bs/BadSmellApp.go
[1d00f0124b] Phodal Huang 2019-12-19 update files
1 1 cmd/bs.go
1 1 cmd/bs.go
0 0 core/
adapter
/bs/BadSmellApp.go
0 0 core/
domain
/bs/BadSmellApp.go
[d00f04111b] Phodal Huang 2019-12-18 refactor: move bs to adapter
[d00f04111b] Phodal Huang 2019-12-18 refactor: move bs to adapter
1 1 cmd/bs.go
1 1 cmd/bs.go
5 5 core/{domain => adapter}/bs/BadSmellApp.go
5 5 core/{domain => adapter}/bs/BadSmellApp.go
[
1d00f012
4b] Phodal Huang 2019-12-19 update files
[
d00f0121
4b] Phodal Huang 2019-12-19 update files
1 1 cmd/bs.go
1 1 cmd/bs.go
0 0 core/domain/bs/BadSmellApp.go
0 0 core/adapter/bs/BadSmellApp.go
`
)
summary
:=
gitt
.
GetTeamSummary
(
messages
)
Expect
(
summary
[
0
]
.
EntityName
)
.
To
(
Equal
(
"core/adapter/bs/BadSmellApp.go"
))
Expect
(
summary
[
1
]
.
EntityName
)
.
To
(
Equal
(
"cmd/bs.go"
))
Expect
(
len
(
summary
))
.
To
(
Equal
(
2
))
})
It
(
"support for first path change"
,
func
()
{
messages
:=
gitt
.
BuildMessageByInput
(
`
[333] Phodal Huang 2019-12-19 update files
0 0 src/domain/gitt/README.md
[d00f0124d] Phodal Huang 2019-12-19 update files
[d00f0124d] Phodal Huang 2019-12-19 update files
0 0 core/domain/bs/BadSmellApp.go
0 0 {src => core}/domain/gitt/README.md
`
)
`
)
summary
:=
gitt
.
GetTeamSummary
(
messages
)
summary
:=
gitt
.
GetTeamSummary
(
messages
)
fmt
.
Println
(
summary
)
Expect
(
summary
[
0
]
.
EntityName
)
.
To
(
Equal
(
"core/domain/gitt/README.md"
))
Expect
(
summary
[
0
]
.
EntityName
)
.
To
(
Equal
(
"cmd/bs.go"
))
Expect
(
len
(
summary
))
.
To
(
Equal
(
1
))
Expect
(
summary
[
1
]
.
EntityName
)
.
To
(
Equal
(
"core/domain/bs/BadSmellApp.go"
))
})
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录