Skip to content

Commit

Permalink
change!: fetch::Ref::unpack() returns Option<oid>. (#450)
Browse files Browse the repository at this point in the history
That way the caller has to be aware of the possibility of an unborn
branch (probably the only unborn branch) on the remote.
  • Loading branch information
Byron committed Nov 2, 2022
1 parent 7086101 commit cd867ad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 4 additions & 7 deletions git-protocol/src/fetch/refs/mod.rs
Expand Up @@ -89,21 +89,18 @@ impl Ref {
/// In case of peeled refs, the tag object itself is returned as it is what the ref directly refers to, and target of the tag is returned
/// as `peeled`.
/// If `unborn`, the first object id will be the null oid.
pub fn unpack(&self) -> (&BStr, &git_hash::oid, Option<&git_hash::oid>) {
pub fn unpack(&self) -> (&BStr, Option<&git_hash::oid>, Option<&git_hash::oid>) {
match self {
Ref::Direct { full_ref_name, object }
| Ref::Symbolic {
full_ref_name, object, ..
} => (full_ref_name.as_ref(), object, None),
} => (full_ref_name.as_ref(), Some(object), None),
Ref::Peeled {
full_ref_name,
tag: object,
object: peeled,
} => (full_ref_name.as_ref(), object, Some(peeled)),
Ref::Unborn { target: _ } => {
static NULL: git_hash::ObjectId = git_hash::ObjectId::null(git_hash::Kind::Sha1);
("HEAD".into(), &NULL, None)
}
} => (full_ref_name.as_ref(), Some(object), Some(peeled)),
Ref::Unborn { target: _ } => ("HEAD".into(), None, None),
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion git-protocol/tests/fetch/mod.rs
Expand Up @@ -41,7 +41,9 @@ impl fetch::DelegateBlocking for CloneDelegate {
_previous_response: Option<&Response>,
) -> io::Result<Action> {
for r in refs {
arguments.want(r.unpack().1);
if let Some(id) = r.unpack().1 {
arguments.want(id);
}
}
Ok(Action::Cancel)
}
Expand Down

0 comments on commit cd867ad

Please sign in to comment.