Index: trunk/cgi-bin/IPDB.pm
===================================================================
--- trunk/cgi-bin/IPDB.pm	(revision 729)
+++ trunk/cgi-bin/IPDB.pm	(revision 730)
@@ -2127,4 +2127,18 @@
 
       if ($args{scope} eq 'keepall') {
+        # Create a new parent with the same info as the passed "primary".
+        $newparent->execute($newblock, $args{newtype}, $prime);
+        # and now retrieve the new parent ID
+        ($prime) = $dbh->selectrow_array("SELECT currval('allocations_id_seq')");
+        # Reparent the free blocks in the new block
+        $fbreparentsth->execute($prime, $binfo->{master_id}, $binfo->{city}, $newcontainerclass, $binfo->{vrf},
+            $binfo->{parent_id}, $newblock);
+        # keep existing allocations (including the original primary), just push them down a level
+        while (my ($pcidr,$peer_id,$ptype,$m_id) = $peersth->fetchrow_array) {
+          $reparentsth->execute($prime, $binfo->{master_id}, $peer_id);
+          # Fix up master_id on free blocks if we're merging a master block
+          $mfbsth->execute($binfo->{master_id}, $m_id) if $ptype eq 'mm';
+        }
+
       } elsif ($args{scope} =~ /^clear/) {
       } elsif ($args{scope} eq 'mergepeer') { # should this just be an else?
