-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
an attempt at making the editor more efficient #1567
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ import ( | |
|
||
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context" | ||
|
||
key "github.com/ipfs/go-ipfs/blocks/key" | ||
dag "github.com/ipfs/go-ipfs/merkledag" | ||
) | ||
|
||
|
@@ -26,21 +25,17 @@ func (e *Editor) GetNode() *dag.Node { | |
return e.root.Copy() | ||
} | ||
|
||
func (e *Editor) AddLink(ctx context.Context, childname string, childk key.Key) error { | ||
nd, err := addLink(ctx, e.ds, e.root, childname, childk) | ||
if err != nil { | ||
return err | ||
} | ||
e.root = nd | ||
return nil | ||
func (e *Editor) GetDagService() dag.DAGService { | ||
return e.ds | ||
} | ||
|
||
func addLink(ctx context.Context, ds dag.DAGService, root *dag.Node, childname string, childk key.Key) (*dag.Node, error) { | ||
func addLink(ctx context.Context, ds dag.DAGService, root *dag.Node, childname string, childnd *dag.Node) (*dag.Node, error) { | ||
if childname == "" { | ||
return nil, errors.New("cannot create link with no name!") | ||
} | ||
|
||
childnd, err := ds.Get(ctx, childk) | ||
// ensure that the node we are adding is in the dagservice | ||
_, err := ds.Add(childnd) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -58,7 +53,7 @@ func addLink(ctx context.Context, ds dag.DAGService, root *dag.Node, childname s | |
return root, nil | ||
} | ||
|
||
func (e *Editor) InsertNodeAtPath(ctx context.Context, path string, toinsert key.Key, create func() *dag.Node) error { | ||
func (e *Editor) InsertNodeAtPath(ctx context.Context, path string, toinsert *dag.Node, create func() *dag.Node) error { | ||
splpath := strings.Split(path, "/") | ||
nd, err := insertNodeAtPath(ctx, e.ds, e.root, splpath, toinsert, create) | ||
if err != nil { | ||
|
@@ -68,7 +63,7 @@ func (e *Editor) InsertNodeAtPath(ctx context.Context, path string, toinsert key | |
return nil | ||
} | ||
|
||
func insertNodeAtPath(ctx context.Context, ds dag.DAGService, root *dag.Node, path []string, toinsert key.Key, create func() *dag.Node) (*dag.Node, error) { | ||
func insertNodeAtPath(ctx context.Context, ds dag.DAGService, root *dag.Node, path []string, toinsert *dag.Node, create func() *dag.Node) (*dag.Node, error) { | ||
if len(path) == 1 { | ||
return addLink(ctx, ds, root, path[0], toinsert) | ||
} | ||
|
@@ -151,3 +146,32 @@ func rmLink(ctx context.Context, ds dag.DAGService, root *dag.Node, path []strin | |
|
||
return root, nil | ||
} | ||
|
||
func (e *Editor) WriteOutputTo(ds dag.DAGService) error { | ||
return copyDag(e.GetNode(), e.ds, ds) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this doesn't seem to get called? shouldn't it be called by the add command at the end? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's called now. |
||
|
||
func copyDag(nd *dag.Node, from, to dag.DAGService) error { | ||
_, err := to.Add(nd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, lnk := range nd.Links { | ||
child, err := lnk.GetNode(context.Background(), from) | ||
if err != nil { | ||
if err == dag.ErrNotFound { | ||
// not found means we didnt modify it, and it should | ||
// already be in the target datastore | ||
continue | ||
} | ||
return err | ||
} | ||
|
||
err = copyDag(child, from, to) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this needs what i wrote in 978c9fa#diff-bd0ca9f1e2d5c7ba128af01ec4c1131cR314