Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
fa3a9e2e
Commit
fa3a9e2e
authored
Feb 18, 2015
by
Jeromy Johnson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #794 from jbenet/feat/refs-faster
teach ipfs refs -r how to use GetBlocks
parents
5253b6ab
3cda8ca6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
12 deletions
+40
-12
core/commands/refs.go
core/commands/refs.go
+40
-12
No files found.
core/commands/refs.go
View file @
fa3a9e2e
...
...
@@ -227,6 +227,14 @@ type RefWriter struct {
// WriteRefs writes refs of the given object to the underlying writer.
func
(
rw
*
RefWriter
)
WriteRefs
(
n
*
dag
.
Node
)
(
int
,
error
)
{
if
rw
.
Recursive
{
return
rw
.
writeRefsRecursive
(
n
)
}
else
{
return
rw
.
writeRefsSingle
(
n
)
}
}
func
(
rw
*
RefWriter
)
writeRefsRecursive
(
n
*
dag
.
Node
)
(
int
,
error
)
{
nkey
,
err
:=
n
.
Key
()
if
err
!=
nil
{
return
0
,
err
...
...
@@ -236,29 +244,23 @@ func (rw *RefWriter) WriteRefs(n *dag.Node) (int, error) {
return
0
,
nil
}
count
:=
0
for
_
,
l
:=
range
n
.
Links
{
lk
:=
u
.
Key
(
l
.
Hash
)
var
count
int
for
i
,
ng
:=
range
rw
.
DAG
.
GetDAG
(
rw
.
Ctx
,
n
)
{
lk
:=
u
.
Key
(
n
.
Links
[
i
]
.
Hash
)
if
rw
.
skip
(
lk
)
{
continue
}
if
err
:=
rw
.
WriteEdge
(
nkey
,
lk
,
l
.
Name
);
err
!=
nil
{
if
err
:=
rw
.
WriteEdge
(
nkey
,
lk
,
n
.
Links
[
i
]
.
Name
);
err
!=
nil
{
return
count
,
err
}
count
++
if
!
rw
.
Recursive
{
continue
}
child
,
err
:=
l
.
GetNode
(
rw
.
DAG
)
nd
,
err
:=
ng
.
Get
()
if
err
!=
nil
{
return
count
,
err
}
c
,
err
:=
rw
.
W
riteRefs
(
chil
d
)
c
,
err
:=
rw
.
w
riteRefs
Recursive
(
n
d
)
count
+=
c
if
err
!=
nil
{
return
count
,
err
...
...
@@ -267,6 +269,32 @@ func (rw *RefWriter) WriteRefs(n *dag.Node) (int, error) {
return
count
,
nil
}
func
(
rw
*
RefWriter
)
writeRefsSingle
(
n
*
dag
.
Node
)
(
int
,
error
)
{
nkey
,
err
:=
n
.
Key
()
if
err
!=
nil
{
return
0
,
err
}
if
rw
.
skip
(
nkey
)
{
return
0
,
nil
}
count
:=
0
for
_
,
l
:=
range
n
.
Links
{
lk
:=
u
.
Key
(
l
.
Hash
)
if
rw
.
skip
(
lk
)
{
continue
}
if
err
:=
rw
.
WriteEdge
(
nkey
,
lk
,
l
.
Name
);
err
!=
nil
{
return
count
,
err
}
count
++
}
return
count
,
nil
}
// skip returns whether to skip a key
func
(
rw
*
RefWriter
)
skip
(
k
u
.
Key
)
bool
{
if
!
rw
.
Unique
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment