Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
180b9b32
提交
180b9b32
authored
1月 07, 2015
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refs: added --format option
上级
f46120b1
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
23 行增加
和
6 行删除
+23
-6
refs.go
core/commands/refs.go
+23
-6
没有找到文件。
core/commands/refs.go
浏览文件 @
180b9b32
...
@@ -3,6 +3,7 @@ package commands
...
@@ -3,6 +3,7 @@ package commands
import
(
import
(
"bytes"
"bytes"
"io"
"io"
"strings"
"sync"
"sync"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
...
@@ -45,7 +46,8 @@ Note: list all refs recursively with -r.
...
@@ -45,7 +46,8 @@ Note: list all refs recursively with -r.
cmds
.
StringArg
(
"ipfs-path"
,
true
,
true
,
"Path to the object(s) to list refs from"
),
cmds
.
StringArg
(
"ipfs-path"
,
true
,
true
,
"Path to the object(s) to list refs from"
),
},
},
Options
:
[]
cmds
.
Option
{
Options
:
[]
cmds
.
Option
{
cmds
.
BoolOption
(
"edges"
,
"e"
,
"Emit edge format: <from> -> <to>"
),
cmds
.
StringOption
(
"format"
,
"Emit edges with given format. tokens: <src> <dst> <linkname>"
),
cmds
.
BoolOption
(
"edges"
,
"e"
,
"Emit edge format: `<from> -> <to>`"
),
cmds
.
BoolOption
(
"unique"
,
"u"
,
"Omit duplicate refs from output"
),
cmds
.
BoolOption
(
"unique"
,
"u"
,
"Omit duplicate refs from output"
),
cmds
.
BoolOption
(
"recursive"
,
"r"
,
"Recursively list links of child nodes"
),
cmds
.
BoolOption
(
"recursive"
,
"r"
,
"Recursively list links of child nodes"
),
},
},
...
@@ -70,6 +72,11 @@ Note: list all refs recursively with -r.
...
@@ -70,6 +72,11 @@ Note: list all refs recursively with -r.
return
nil
,
err
return
nil
,
err
}
}
format
,
_
,
err
:=
req
.
Option
(
"format"
)
.
String
()
if
err
!=
nil
{
return
nil
,
err
}
objs
,
err
:=
objectsForPaths
(
n
,
req
.
Arguments
())
objs
,
err
:=
objectsForPaths
(
n
,
req
.
Arguments
())
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -87,6 +94,7 @@ Note: list all refs recursively with -r.
...
@@ -87,6 +94,7 @@ Note: list all refs recursively with -r.
Ctx
:
n
.
Context
(),
Ctx
:
n
.
Context
(),
Unique
:
unique
,
Unique
:
unique
,
PrintEdge
:
edges
,
PrintEdge
:
edges
,
PrintFmt
:
format
,
Recursive
:
recursive
,
Recursive
:
recursive
,
}
}
...
@@ -159,6 +167,7 @@ type RefWriter struct {
...
@@ -159,6 +167,7 @@ type RefWriter struct {
Unique
bool
Unique
bool
Recursive
bool
Recursive
bool
PrintEdge
bool
PrintEdge
bool
PrintFmt
string
seen
map
[
u
.
Key
]
struct
{}
seen
map
[
u
.
Key
]
struct
{}
}
}
...
@@ -182,7 +191,7 @@ func (rw *RefWriter) WriteRefs(n *dag.Node) (int, error) {
...
@@ -182,7 +191,7 @@ func (rw *RefWriter) WriteRefs(n *dag.Node) (int, error) {
continue
continue
}
}
if
err
:=
rw
.
WriteEdge
(
nkey
,
lk
);
err
!=
nil
{
if
err
:=
rw
.
WriteEdge
(
nkey
,
lk
,
l
.
Name
);
err
!=
nil
{
return
count
,
err
return
count
,
err
}
}
count
++
count
++
...
@@ -223,7 +232,7 @@ func (rw *RefWriter) skip(k u.Key) bool {
...
@@ -223,7 +232,7 @@ func (rw *RefWriter) skip(k u.Key) bool {
}
}
// Write one edge
// Write one edge
func
(
rw
*
RefWriter
)
WriteEdge
(
from
,
to
u
.
Key
)
error
{
func
(
rw
*
RefWriter
)
WriteEdge
(
from
,
to
u
.
Key
,
linkname
string
)
error
{
if
rw
.
Ctx
!=
nil
{
if
rw
.
Ctx
!=
nil
{
select
{
select
{
case
<-
rw
.
Ctx
.
Done
()
:
// just in case.
case
<-
rw
.
Ctx
.
Done
()
:
// just in case.
...
@@ -233,10 +242,18 @@ func (rw *RefWriter) WriteEdge(from, to u.Key) error {
...
@@ -233,10 +242,18 @@ func (rw *RefWriter) WriteEdge(from, to u.Key) error {
}
}
var
s
string
var
s
string
if
rw
.
PrintEdge
{
switch
{
s
=
from
.
Pretty
()
+
" -> "
case
rw
.
PrintFmt
!=
""
:
s
=
rw
.
PrintFmt
s
=
strings
.
Replace
(
s
,
"<src>"
,
from
.
Pretty
(),
-
1
)
s
=
strings
.
Replace
(
s
,
"<dst>"
,
to
.
Pretty
(),
-
1
)
s
=
strings
.
Replace
(
s
,
"<linkname>"
,
linkname
,
-
1
)
case
rw
.
PrintEdge
:
s
=
from
.
Pretty
()
+
" -> "
+
to
.
Pretty
()
default
:
s
+=
to
.
Pretty
()
}
}
s
+=
to
.
Pretty
()
+
"
\n
"
s
+=
"
\n
"
if
_
,
err
:=
rw
.
W
.
Write
([]
byte
(
s
));
err
!=
nil
{
if
_
,
err
:=
rw
.
W
.
Write
([]
byte
(
s
));
err
!=
nil
{
return
err
return
err
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论