is_ancestor and is_public_ancestor have a lot of redundant code. This patch shares the code between that two. This way improvements the the function can be shared between the two functions. I don't like the name do_is_ancestor but I could not come up with anything better