Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
c6daf934
提交
c6daf934
authored
9月 22, 2018
作者:
Overbool
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(diff): modify diff logic and comment
License: MIT Signed-off-by:
Overbool
<
overbool.xu@gmail.com
>
上级
7cda005a
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
28 行增加
和
25 行删除
+28
-25
diff.go
dagutils/diff.go
+25
-22
t0052-object-diff.sh
test/sharness/t0052-object-diff.sh
+3
-3
没有找到文件。
dagutils/diff.go
浏览文件 @
c6daf934
...
...
@@ -95,29 +95,23 @@ func ApplyChange(ctx context.Context, ds ipld.DAGService, nd *dag.ProtoNode, cs
}
// Diff returns a set of changes that transform node 'a' into node 'b'.
// It
supports two nodes forms: ProtoNode and RawNode. Because we treat
//
the nodes as IPLD nodes as long as possible and only convert them
//
to ProtoNode when necessary: when we need to remove links, and at that point
//
(if they have links to remove) we know they are not raw nodes
.
// It
only traverses links in the following cases:
//
1. two node's links number are greater than 0.
//
2. both of two nodes are ProtoNode.
//
Otherwise, it compares the cid and emits a Mod change object
.
func
Diff
(
ctx
context
.
Context
,
ds
ipld
.
DAGService
,
a
,
b
ipld
.
Node
)
([]
*
Change
,
error
)
{
// Base case where both nodes are leaves, just compare
// their CIDs.
if
len
(
a
.
Links
())
==
0
&&
len
(
b
.
Links
())
==
0
{
if
a
.
Cid
()
.
Equals
(
b
.
Cid
())
{
return
[]
*
Change
{},
nil
}
return
[]
*
Change
{
{
Type
:
Mod
,
Before
:
a
.
Cid
(),
After
:
b
.
Cid
(),
},
},
nil
return
getChange
(
a
,
b
)
}
var
out
[]
*
Change
cleanA
:=
a
.
Copy
()
cleanB
:=
b
.
Copy
()
cleanA
,
okA
:=
a
.
Copy
()
.
(
*
dag
.
ProtoNode
)
cleanB
,
okB
:=
b
.
Copy
()
.
(
*
dag
.
ProtoNode
)
if
!
okA
||
!
okB
{
return
getChange
(
a
,
b
)
}
// strip out unchanged stuff
for
_
,
lnk
:=
range
a
.
Links
()
{
...
...
@@ -146,12 +140,8 @@ func Diff(ctx context.Context, ds ipld.DAGService, a, b ipld.Node) ([]*Change, e
out
=
append
(
out
,
subc
)
}
}
if
cleanA
,
ok
:=
cleanA
.
(
*
dag
.
ProtoNode
);
ok
{
cleanA
.
RemoveNodeLink
(
l
.
Name
)
}
if
cleanB
,
ok
:=
cleanB
.
(
*
dag
.
ProtoNode
);
ok
{
cleanB
.
RemoveNodeLink
(
l
.
Name
)
}
cleanA
.
RemoveNodeLink
(
l
.
Name
)
cleanB
.
RemoveNodeLink
(
l
.
Name
)
}
}
...
...
@@ -207,3 +197,16 @@ func MergeDiffs(a, b []*Change) ([]*Change, []Conflict) {
}
return
out
,
conflicts
}
func
getChange
(
a
,
b
ipld
.
Node
)
([]
*
Change
,
error
)
{
if
a
.
Cid
()
.
Equals
(
b
.
Cid
())
{
return
[]
*
Change
{},
nil
}
return
[]
*
Change
{
{
Type
:
Mod
,
Before
:
a
.
Cid
(),
After
:
b
.
Cid
(),
},
},
nil
}
test/sharness/t0052-object-diff.sh
浏览文件 @
c6daf934
...
...
@@ -58,19 +58,19 @@ test_expect_success "diff against self (single file) is empty" '
'
test_expect_success
"diff (raw-leaves) against self (single file) is empty"
'
ipfs object diff $SINGLE_FILE_RAW $SINGLE_FILE_RAW > diff_raw_out
ipfs object diff $SINGLE_FILE_RAW $SINGLE_FILE_RAW > diff_raw_out
&&
printf "" > diff_raw_exp &&
test_cmp diff_raw_exp diff_raw_out
'
test_expect_success
"diff against self (empty dir) is empty"
'
ipfs object diff $EMPTY_DIR $EMPTY_DIR > diff_out
ipfs object diff $EMPTY_DIR $EMPTY_DIR > diff_out
&&
printf "" > diff_exp &&
test_cmp diff_exp diff_out
'
test_expect_success
"diff (raw-leaves) against self (empty dir) is empty"
'
ipfs object diff $EMPTY_DIR_RAW $EMPTY_DIR_RAW > diff_raw_out
ipfs object diff $EMPTY_DIR_RAW $EMPTY_DIR_RAW > diff_raw_out
&&
printf "" > diff_raw_exp &&
test_cmp diff_raw_exp diff_raw_out
'
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论