Move new_repository to Repository::open
Move a little code outside unsafe