Skip to content

Commit

Permalink
adapt to changes in git-protocol (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Nov 2, 2022
1 parent cd867ad commit 179ccd7
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
17 changes: 11 additions & 6 deletions git-repository/src/remote/connection/fetch/negotiate.rs
Expand Up @@ -35,14 +35,19 @@ pub(crate) fn one_round(
.and_then(|r| r.target().try_id().map(ToOwned::to_owned))
});
match have_id {
Some(have_id) if mapping.remote.as_id() != have_id => {
arguments.want(mapping.remote.as_id());
arguments.have(have_id);
Some(have_id) => {
if let Some(want_id) = mapping.remote.as_id() {
if want_id != have_id {
arguments.want(want_id);
arguments.have(have_id);
}
}
}
Some(_) => {}
None => {
arguments.want(mapping.remote.as_id());
has_missing_tracking_branch = true;
if let Some(have_id) = mapping.remote.as_id() {
arguments.want(have_id);
has_missing_tracking_branch = true;
}
}
}
}
Expand Down
Expand Up @@ -56,7 +56,10 @@ pub(crate) fn update(
spec_index,
}| refspecs.get(*spec_index).map(|spec| (remote, local, spec)),
) {
let remote_id = remote.as_id();
let remote_id = match remote.as_id() {
Some(id) => id,
None => continue,
};
if dry_run == fetch::DryRun::No && !repo.objects.contains(remote_id) {
updates.push(update::Mode::RejectedSourceObjectNotFound { id: remote_id.into() }.into());
continue;
Expand Down
Expand Up @@ -487,7 +487,7 @@ mod update {
let (full_ref_name, target, object) = r.unpack();
git_refspec::match_group::Item {
full_ref_name,
target,
target: target.expect("no unborn HEAD"),
object,
}
}
Expand Down
3 changes: 2 additions & 1 deletion git-repository/src/remote/connection/ref_map.rs
Expand Up @@ -82,6 +82,7 @@ where
handshake_parameters,
}: Options,
) -> Result<fetch::RefMap, Error> {
static NULL: git_hash::ObjectId = git_hash::ObjectId::null(git_hash::Kind::Sha1); // OK to hardcode Sha1, it's not supposed to match, ever.
let remote = self
.fetch_refs(prefix_from_spec_as_filter_on_remote, handshake_parameters)
.await?;
Expand All @@ -91,7 +92,7 @@ where
let (full_ref_name, target, object) = r.unpack();
git_refspec::match_group::Item {
full_ref_name,
target,
target: target.unwrap_or(&NULL),
object,
}
}))
Expand Down
5 changes: 3 additions & 2 deletions git-repository/src/remote/fetch.rs
Expand Up @@ -41,9 +41,10 @@ pub enum Source {
impl Source {
/// Return either the direct object id we refer to or the direct target that a reference refers to.
/// The latter may be a direct or a symbolic reference, and we degenerate this to the peeled object id.
pub fn as_id(&self) -> &git_hash::oid {
/// If unborn, `None` is returned.
pub fn as_id(&self) -> Option<&git_hash::oid> {
match self {
Source::ObjectId(id) => id,
Source::ObjectId(id) => Some(id),
Source::Ref(r) => r.unpack().1,
}
}
Expand Down
4 changes: 2 additions & 2 deletions git-repository/tests/remote/fetch.rs
Expand Up @@ -182,7 +182,7 @@ mod blocking_io {
if dry_run {
assert_eq!(
edit.change.new_value().expect("no deletions").id(),
mapping.remote.as_id()
mapping.remote.as_id().expect("no unborn")
);
assert!(
repo.try_find_reference(edit.name.as_ref())?.is_none(),
Expand All @@ -192,7 +192,7 @@ mod blocking_io {
let r = repo.find_reference(edit.name.as_ref()).unwrap();
assert_eq!(
r.id(),
*mapping.remote.as_id(),
*mapping.remote.as_id().expect("no unborn"),
"local reference should point to remote id"
);
}
Expand Down

0 comments on commit 179ccd7

Please sign in to comment.