This function is also available from dulwich.refs.