Define a "leaf" as a check-in with no children in the same branch.  The
is_a_leaf() function does some complicated SQL to figure this out.