Skip to content

Commit cd867ad

Browse files
committed
change!: fetch::Ref::unpack() returns Option<oid>. (#450)
That way the caller has to be aware of the possibility of an unborn branch (probably the only unborn branch) on the remote.
1 parent 7086101 commit cd867ad

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

git-protocol/src/fetch/refs/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,18 @@ impl Ref {
8989
/// 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
9090
/// as `peeled`.
9191
/// If `unborn`, the first object id will be the null oid.
92-
pub fn unpack(&self) -> (&BStr, &git_hash::oid, Option<&git_hash::oid>) {
92+
pub fn unpack(&self) -> (&BStr, Option<&git_hash::oid>, Option<&git_hash::oid>) {
9393
match self {
9494
Ref::Direct { full_ref_name, object }
9595
| Ref::Symbolic {
9696
full_ref_name, object, ..
97-
} => (full_ref_name.as_ref(), object, None),
97+
} => (full_ref_name.as_ref(), Some(object), None),
9898
Ref::Peeled {
9999
full_ref_name,
100100
tag: object,
101101
object: peeled,
102-
} => (full_ref_name.as_ref(), object, Some(peeled)),
103-
Ref::Unborn { target: _ } => {
104-
static NULL: git_hash::ObjectId = git_hash::ObjectId::null(git_hash::Kind::Sha1);
105-
("HEAD".into(), &NULL, None)
106-
}
102+
} => (full_ref_name.as_ref(), Some(object), Some(peeled)),
103+
Ref::Unborn { target: _ } => ("HEAD".into(), None, None),
107104
}
108105
}
109106
}

git-protocol/tests/fetch/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ impl fetch::DelegateBlocking for CloneDelegate {
4141
_previous_response: Option<&Response>,
4242
) -> io::Result<Action> {
4343
for r in refs {
44-
arguments.want(r.unpack().1);
44+
if let Some(id) = r.unpack().1 {
45+
arguments.want(id);
46+
}
4547
}
4648
Ok(Action::Cancel)
4749
}

0 commit comments

Comments
 (0)