VOL-1687 : Fix wrong in-memory node assignments

- Fixed nil pointer with createProxy
- Changed watch loop to avoid re-starting when rev changes

Change-Id: Ie821788f2422d7a2083398c65b9632c65fae001d
diff --git a/db/model/non_persisted_revision.go b/db/model/non_persisted_revision.go
index 6075b3f..297a740 100644
--- a/db/model/non_persisted_revision.go
+++ b/db/model/non_persisted_revision.go
@@ -55,7 +55,6 @@
 	Branch       *Branch
 	WeakRef      string
 	Name         string
-	discarded    bool
 	lastUpdate   time.Time
 }
 
@@ -66,14 +65,9 @@
 	r.Config = NewDataRevision(root, data)
 	r.Children = children
 	r.Hash = r.hashContent()
-	r.discarded = false
 	return r
 }
 
-func (npr *NonPersistedRevision) IsDiscarded() bool {
-	return npr.discarded
-}
-
 func (npr *NonPersistedRevision) SetConfig(config *DataRevision) {
 	npr.mutex.Lock()
 	defer npr.mutex.Unlock()
@@ -356,14 +350,33 @@
 			if nameExists {
 				// Check if the data has changed or not
 				if existingChildren[nameIndex].GetData().(proto.Message).String() != newChild.GetData().(proto.Message).String() {
+					log.Debugw("replacing-existing-child", log.Fields{
+						"old-hash": existingChildren[nameIndex].GetHash(),
+						"old-data": existingChildren[nameIndex].GetData(),
+						"new-hash": newChild.GetHash(),
+						"new-data": newChild.GetData(),
+					})
+
 					// replace entry
 					newChild.GetNode().Root = existingChildren[nameIndex].GetNode().Root
 					updatedChildren = append(updatedChildren, newChild)
 				} else {
+					log.Debugw("keeping-existing-child", log.Fields{
+						"old-hash": existingChildren[nameIndex].GetHash(),
+						"old-data": existingChildren[nameIndex].GetData(),
+						"new-hash": newChild.GetHash(),
+						"new-data": newChild.GetData(),
+					})
+
 					// keep existing entry
 					updatedChildren = append(updatedChildren, existingChildren[nameIndex])
 				}
 			} else {
+				log.Debugw("adding-unknown-child", log.Fields{
+					"hash": newChild.GetHash(),
+					"data": newChild.GetData(),
+				})
+
 				// new entry ... just add it
 				updatedChildren = append(updatedChildren, newChild)
 			}
@@ -413,7 +426,6 @@
 // Drop is used to indicate when a revision is no longer required
 func (npr *NonPersistedRevision) Drop(txid string, includeConfig bool) {
 	log.Debugw("dropping-revision", log.Fields{"hash": npr.GetHash(), "name": npr.GetName()})
-	npr.discarded = true
 }
 
 // ChildDrop will remove a child entry matching the provided parameters from the current revision
@@ -458,6 +470,6 @@
 	// stub ... required by interface
 }
 
-func (pr *NonPersistedRevision) StorageDrop(txid string, includeConfig bool) {
+func (npr *NonPersistedRevision) StorageDrop(txid string, includeConfig bool) {
 	// stub ... required by interface
 }