getDeltaScript start end =
    let quick s e =
            if s `unsafePtrEq` e
            then Just []
            else case quick s (hs_parent e) of
                   Just b -> Just $ (hs_entry end):b
                   Nothing -> Nothing
    in case quick start end of
         Just r -> Just $ reverse r
         Nothing ->
             {- start isn't on the path from the root to end.  Do it
                the hard way. -}
             Debug.Trace.trace "getDeltaScript on slow path..." $
             let start' = historyGetHeList start
                 end' = historyGetHeList end
                 worker [] xs = Just xs
                 worker _ [] = Nothing
                 worker aas@(a:as) bbs@(b:bs)
                     | a == b = worker as bs
                     | otherwise =
                         case (a, b) of
                           (HistoryRun atid acntr,
                            HistoryRun btid bcntr)
                               | atid == btid ->
                                   if acntr < bcntr
                                   then worker as bbs
                                   else worker aas bs
                           _ -> Nothing
             in worker start' end'
getDeltaScript start end =
    let quick s e =
            if s `unsafePtrEq` e
            then Just []
            else case quick s (hs_parent e) of
                   Just b -> Just $ (hs_entry end):b
                   Nothing -> Nothing
    in case quick start end of
         Just r -> Just $ reverse r
         Nothing ->
             {- start isn't on the path from the root to end.  Do it
                the hard way. -}
             Debug.Trace.trace "getDeltaScript on slow path..." $
             let start' = historyGetHeList start
                 end' = historyGetHeList end
                 worker [] xs = Just xs
                 worker _ [] = Nothing
                 worker aas@(a:as) bbs@(b:bs)
                     | a == b = worker as bs
                     | otherwise =
                         case (a, b) of
                           (HistoryRun atid acntr,
                            HistoryRun btid bcntr)
                               | atid == btid ->
                                   if acntr < bcntr
                                   then worker as bbs
                                   else worker aas bs
                           _ -> Nothing
             in worker start' end'
getDeltaScript start end =
    let quick s e =
            if s `unsafePtrEq` e
            then Just []
            else case quick s (hs_parent e) of
                   Just b -> Just $ (hs_entry end):b
                   Nothing -> Nothing
    in case quick start end of
         Just r -> Just $ reverse r
         Nothing ->
             {- start isn't on the path from the root to end.  Do it
                the hard way. -}
             Debug.Trace.trace "getDeltaScript on slow path..." $
             let start' = historyGetHeList start
                 end' = historyGetHeList end
                 worker [] xs = Just xs
                 worker _ [] = Nothing
                 worker aas@(a:as) bbs@(b:bs)
                     | a == b = worker as bs
                     | otherwise =
                         case (a, b) of
                           (HistoryRun atid acntr,
                            HistoryRun btid bcntr)
                               | atid == btid ->
                                   if acntr < bcntr
                                   then worker as bbs
                                   else worker aas bs
                           _ -> Nothing
             in worker start' end'