Refactor debug into debug module

This commit is contained in:
Alexander Neumann
2015-01-17 16:32:13 +01:00
parent bcb19c811b
commit 25a214809b
18 changed files with 318 additions and 238 deletions
+15 -14
View File
@@ -14,6 +14,7 @@ import (
"github.com/juju/arrar"
"github.com/restic/restic/backend"
"github.com/restic/restic/debug"
)
type Tree struct {
@@ -127,7 +128,7 @@ func LoadTreeRecursive(path string, s Server, blob Blob) (*Tree, error) {
// CopyFrom recursively copies all content from other to t.
func (t Tree) CopyFrom(other *Tree, s *Server) error {
debug("Tree.CopyFrom", "CopyFrom(%v)\n", other)
debug.Log("Tree.CopyFrom", "CopyFrom(%v)\n", other)
for _, node := range t.Nodes {
// only process files and dirs
if node.Type != "file" && node.Type != "dir" {
@@ -139,14 +140,14 @@ func (t Tree) CopyFrom(other *Tree, s *Server) error {
// if the node could not be found or the type has changed, proceed to the next
if err == ErrNodeNotFound || node.Type != oldNode.Type {
debug("Tree.CopyFrom", " node %v is new\n", node)
debug.Log("Tree.CopyFrom", " node %v is new\n", node)
continue
}
if node.Type == "file" {
// compare content
if node.SameContent(oldNode) {
debug("Tree.CopyFrom", " file node %v has same content\n", node)
debug.Log("Tree.CopyFrom", " file node %v has same content\n", node)
// check if all content is still available in the repository
for _, id := range oldNode.Content {
@@ -170,7 +171,7 @@ func (t Tree) CopyFrom(other *Tree, s *Server) error {
return err
}
debug("Tree.CopyFrom", " insert blob %v\n", blob)
debug.Log("Tree.CopyFrom", " insert blob %v\n", blob)
t.Map.Insert(blob)
}
}
@@ -183,7 +184,7 @@ func (t Tree) CopyFrom(other *Tree, s *Server) error {
// check if tree has changed
if node.tree.Equals(*oldNode.tree) {
debug("Tree.CopyFrom", " tree node %v has same content\n", node)
debug.Log("Tree.CopyFrom", " tree node %v has same content\n", node)
// if nothing has changed, copy subtree ID
node.Subtree = oldNode.Subtree
@@ -194,12 +195,12 @@ func (t Tree) CopyFrom(other *Tree, s *Server) error {
return err
}
debug("Tree.CopyFrom", " insert blob %v\n", blob)
debug.Log("Tree.CopyFrom", " insert blob %v\n", blob)
t.Map.Insert(blob)
} else {
debug("Tree.CopyFrom", " trees are not equal: %v\n", node)
debug("Tree.CopyFrom", " %#v\n", node.tree)
debug("Tree.CopyFrom", " %#v\n", oldNode.tree)
debug.Log("Tree.CopyFrom", " trees are not equal: %v\n", node)
debug.Log("Tree.CopyFrom", " %#v\n", node.tree)
debug.Log("Tree.CopyFrom", " %#v\n", oldNode.tree)
}
}
}
@@ -210,20 +211,20 @@ func (t Tree) CopyFrom(other *Tree, s *Server) error {
// Equals returns true if t and other have exactly the same nodes and map.
func (t Tree) Equals(other Tree) bool {
if len(t.Nodes) != len(other.Nodes) {
debug("Tree.Equals", "tree.Equals(): trees have different number of nodes")
debug.Log("Tree.Equals", "tree.Equals(): trees have different number of nodes")
return false
}
if !t.Map.Equals(other.Map) {
debug("Tree.Equals", "tree.Equals(): maps aren't equal")
debug.Log("Tree.Equals", "tree.Equals(): maps aren't equal")
return false
}
for i := 0; i < len(t.Nodes); i++ {
if !t.Nodes[i].Equals(*other.Nodes[i]) {
debug("Tree.Equals", "tree.Equals(): node %d is different:", i)
debug("Tree.Equals", " %#v", t.Nodes[i])
debug("Tree.Equals", " %#v", other.Nodes[i])
debug.Log("Tree.Equals", "tree.Equals(): node %d is different:", i)
debug.Log("Tree.Equals", " %#v", t.Nodes[i])
debug.Log("Tree.Equals", " %#v", other.Nodes[i])
return false
}
}