Make use of `git2::Repository::refname_to_id`

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
Alexis Sellier 2022-10-19 14:47:12 +02:00
parent 94f7675c72
commit 111480cd6e
No known key found for this signature in database
2 changed files with 5 additions and 13 deletions

View File

@ -125,10 +125,8 @@ pub fn fork_remote<G: Signer, S: storage::WriteStorage>(
let repository = storage.repository(proj)?;
let raw = repository.raw();
let remote_head = raw
.find_reference(&git::refs::storage::branch(remote, &project.default_branch))?
.target()
.ok_or(ForkError::InvalidReference)?;
let remote_head =
raw.refname_to_id(&git::refs::storage::branch(remote, &project.default_branch))?;
raw.reference(
&git::refs::storage::branch(me, &project.default_branch),
remote_head,
@ -136,10 +134,7 @@ pub fn fork_remote<G: Signer, S: storage::WriteStorage>(
&format!("creating default branch for {me}"),
)?;
let remote_id = raw
.find_reference(&git::refs::storage::id(remote))?
.target()
.ok_or(ForkError::InvalidReference)?;
let remote_id = raw.refname_to_id(&git::refs::storage::id(remote))?;
raw.reference(
&git::refs::storage::id(me),
remote_id,

View File

@ -437,11 +437,8 @@ impl ReadRepository for Repository {
remote: &RemoteId,
reference: &git::Qualified,
) -> Result<Oid, git::Error> {
// TODO: Use native git2 function for this.
let oid = self
.reference(remote, reference)?
.target()
.ok_or(git::Error::NotFound(git::NotFound::NoRefTarget))?;
let name = reference.with_namespace(remote.into());
let oid = self.backend.refname_to_id(&name)?;
Ok(oid.into())
}