Refactor: tools: Rework print_node_history.
Reverse some conditionals so we can bail out of loops earlier and
decrease the amount of indentation of the rest of the function. This is
just to make it easier for me to understand what is going on in the
function.