Implementing the forgotten diff() function for DiffState
diff --git a/model/sync-diff-state.cc b/model/sync-diff-state.cc
index a804a8e..1c6a41c 100644
--- a/model/sync-diff-state.cc
+++ b/model/sync-diff-state.cc
@@ -43,7 +43,7 @@
 DiffState::diff () const
 {
   DiffStatePtr ret = make_shared<DiffState> ();
-
+  
   DiffStatePtr state = m_next;
   while (state != 0)
     {
@@ -57,6 +57,21 @@
 DiffState &
 DiffState::operator += (const DiffState &state)
 {
+  BOOST_FOREACH (LeafConstPtr _leaf, state.getLeaves ())
+    {
+      DiffLeafConstPtr leaf = dynamic_pointer_cast<const DiffLeaf> (_leaf);
+      BOOST_ASSERT (leaf != 0);
+
+      if (leaf->getOperation () == UPDATE)
+        update (leaf->getInfo (), leaf->getSeq ());
+      else if (leaf->getOperation () == REMOVE)
+        remove (leaf->getInfo ());
+      else
+        {
+          BOOST_ASSERT (false);
+        }
+    }
+  
   return *this;
 }
   
diff --git a/model/sync-logic.cc b/model/sync-logic.cc
index c4a8487..e39b86b 100644
--- a/model/sync-logic.cc
+++ b/model/sync-logic.cc
@@ -246,6 +246,10 @@
         }
 
       diffLog->setDigest(m_state.getDigest());
+      if (m_log.size () > 0)
+        {
+          m_log.get<sequenced> ().front ()->setNext (diffLog);
+        }
       m_log.insert (diffLog);
     }
   catch (Error::SyncXmlDecodingFailure &e)
@@ -256,15 +260,6 @@
 
   if (diffLog->getLeaves ().size () > 0)
     {
-      // notify upper layer
-      BOOST_FOREACH (LeafConstPtr leaf, diffLog->getLeaves ())
-        {
-          DiffLeafConstPtr diffLeaf = dynamic_pointer_cast<const DiffLeaf> (leaf);
-          BOOST_ASSERT (diffLeaf != 0);
-          
-          // m_fetchCallback (prefix, 1, seq.getSeq());
-        }
-  
       sendSyncInterest();
     }
 }
diff --git a/test/test_state.cc b/test/test_state.cc
index 00ff467..56810ac 100644
--- a/test/test_state.cc
+++ b/test/test_state.cc
@@ -263,4 +263,32 @@
 
 }
 
+BOOST_AUTO_TEST_CASE (DiffStateDiffTest)
+{
+  DiffStatePtr root = make_shared<DiffState> ();
+
+  DiffStatePtr head = make_shared<DiffState> ();
+  root->setNext (head);
+  
+  head->update (StdNameInfo::FindOrCreate ("3"), SeqNo (1));
+  head->remove (StdNameInfo::FindOrCreate ("1"));
+  
+  DiffStatePtr tail = make_shared<DiffState> ();
+  head->setNext (tail);
+
+  tail->update (StdNameInfo::FindOrCreate ("3"), SeqNo (2));  
+
+  {
+  ostringstream os;
+  os << *root->diff ();
+  string diffState = os.str ();
+  erase_all (diffState, "\n");
+  BOOST_CHECK_EQUAL (diffState,
+                     "<state>"
+                     "<item action=\"remove\"><name>1</name></item>"
+                     "<item action=\"update\"><name>3</name><seq><session>0</session><seqno>2</seqno></seq></item>"
+                     "</state>");
+  }
+}
+
 BOOST_AUTO_TEST_SUITE_END()