The unified diff between revisions [8846a6b8..] and [ebdccab0..] is displayed below. It can also be downloaded as a raw diff.

This diff has been restricted to the following files: 'database.cc'

#
#
# patch "database.cc"
#  from [4c830b7b46f89cdc384cae08e54bfeac62335eb7]
#    to [fd5eff861239cd1408cca007c0df653f8a0f7d3f]
#
============================================================
--- database.cc	4c830b7b46f89cdc384cae08e54bfeac62335eb7
+++ database.cc	fd5eff861239cd1408cca007c0df653f8a0f7d3f
@@ -1224,6 +1224,10 @@ database::remove_version(hexenc<id> cons
       }
   }

+  // no deltas are allowed to point to the target.
+  execute(query("DELETE from " + delta_table + " WHERE base = ?")
+          % text(target_id()));
+
   if (delta_exists(target_id, delta_table))
     {
       if (!older.empty())
@@ -1243,6 +1247,8 @@ database::remove_version(hexenc<id> cons
           for (map<hexenc<id>, data>::const_iterator i = older.begin();
                i != older.end(); ++i)
             {
+              if (delta_exists(i->first, delta_table))
+                continue;
               delta bypass_delta;
               diff(newer_data, i->second, bypass_delta);
               put_delta(i->first, newer_id, bypass_delta, delta_table);
@@ -1257,7 +1263,10 @@ database::remove_version(hexenc<id> cons
       I(exists(target_id, data_table));
       for (map<hexenc<id>, data>::const_iterator i = older.begin();
            i != older.end(); ++i)
-        put(i->first, i->second, data_table);
+        {
+          if (!exists(i->first, data_table))
+            put(i->first, i->second, data_table);
+        }
       execute(query("DELETE from " + data_table + " WHERE id = ?")
               % text(target_id()));
     }