Repository.xs: merge_base() should fail if sv_isobject is false
Use a different counter for counting and iterating

Some values may be undefined, resulting in an infinite loop.
Repository.xs: Added is_head_detached()
Changes: update
Repository.xs: tree parameter to diff() may be undefined
Changes: update