- BlockRef &last = (rsv_blocks.empty() ? cur_blocks.back() : rsv_blocks.back());
- BlockRef next = last.next();
- const Block::Endpoint &ep = next.block->get_endpoints()[next.entry];
- if(!r->get_tracks().count(ep.track))
- routes.push_front(Route::find(*ep.track, ep.track_ep, *r));
-
- /* XXX This is sort of a hack, but it keeps divert() happy. Need to come
- up with a better solution when there is time. */
- routes.push_front(create_lead_route());
+ TrackIter first = cur_blocks.front().track_iter();
+ TrackIter next = (rsv_blocks.empty() ? cur_blocks : rsv_blocks).back().next().track_iter();
+ if(!r->has_track(*next))
+ {
+ Route *lead = Route::find(*next, next.entry(), *r);
+ create_lead_route(lead, lead);
+ routes.push_front(lead);
+ }
+ else if(!r->has_track(*first))
+ routes.push_front(create_lead_route(0, r));