@@ -79,16 +79,29 @@ func (c *committer) commitNeeded(n node) bool {
7979 return hash == nil || dirty
8080}
8181
82+ // commit collapses a node down into a hash node and inserts it into the database
83+ func (c * committer ) Commit (n node , db * Database ) (hashNode , error ) {
84+ if db == nil {
85+ return nil , errors .New ("no db provided" )
86+ }
87+ h , err := c .commit (n , db , true )
88+ if err != nil {
89+ return nil , err
90+ }
91+ hn , ok := h .(hashNode )
92+ if ! ok {
93+ panic ("commit did not hash down to a hashnode!" )
94+ }
95+ return hn , nil
96+ }
97+
8298// commit collapses a node down into a hash node and inserts it into the database
8399func (c * committer ) commit (n node , db * Database , force bool ) (node , error ) {
84100 // if this path is clean, use available cached data
85101 hash , dirty := n .cache ()
86102 if hash != nil && ! dirty {
87103 return hash , nil
88104 }
89- if db == nil {
90- return nil , errors .New ("no db provided" )
91- }
92105 // Commit children, then parent, and remove remove the dirty flag.
93106 switch cn := n .(type ) {
94107 case * shortNode :
@@ -105,7 +118,6 @@ func (c *committer) commit(n node, db *Database, force bool) (node, error) {
105118 collapsed .Key = hexToCompact (cn .Key )
106119 hashedNode := c .store (collapsed , db , force , true )
107120 if hn , ok := hashedNode .(hashNode ); ok {
108- cn .flags .dirty = false
109121 return hn , nil
110122 } else {
111123 return collapsed , nil
@@ -120,7 +132,6 @@ func (c *committer) commit(n node, db *Database, force bool) (node, error) {
120132
121133 hashedNode := c .store (collapsed , db , force , hasVnodes )
122134 if hn , ok := hashedNode .(hashNode ); ok {
123- cn .flags .dirty = false
124135 return hn , nil
125136 } else {
126137 return collapsed , nil
0 commit comments