diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
commit | c23a457e72abe608715ac76f076f47dc42af07a5 (patch) | |
tree | 2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/gix-protocol/src/handshake/refs | |
parent | Releasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip |
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-protocol/src/handshake/refs')
-rw-r--r-- | vendor/gix-protocol/src/handshake/refs/mod.rs | 15 | ||||
-rw-r--r-- | vendor/gix-protocol/src/handshake/refs/shared.rs | 99 | ||||
-rw-r--r-- | vendor/gix-protocol/src/handshake/refs/tests.rs | 11 |
3 files changed, 89 insertions, 36 deletions
diff --git a/vendor/gix-protocol/src/handshake/refs/mod.rs b/vendor/gix-protocol/src/handshake/refs/mod.rs index 889842e4c..39c6c85a9 100644 --- a/vendor/gix-protocol/src/handshake/refs/mod.rs +++ b/vendor/gix-protocol/src/handshake/refs/mod.rs @@ -38,10 +38,17 @@ impl Ref { /// If `unborn`, the first object id will be the null oid. pub fn unpack(&self) -> (&BStr, Option<&gix_hash::oid>, Option<&gix_hash::oid>) { match self { - Ref::Direct { full_ref_name, object } - | Ref::Symbolic { - full_ref_name, object, .. - } => (full_ref_name.as_ref(), Some(object), None), + Ref::Direct { full_ref_name, object } => (full_ref_name.as_ref(), Some(object), None), + Ref::Symbolic { + full_ref_name, + tag, + object, + .. + } => ( + full_ref_name.as_ref(), + Some(tag.as_deref().unwrap_or(object)), + tag.as_deref().map(|_| object.as_ref()), + ), Ref::Peeled { full_ref_name, tag: object, diff --git a/vendor/gix-protocol/src/handshake/refs/shared.rs b/vendor/gix-protocol/src/handshake/refs/shared.rs index 046a2a1b1..45aefe68b 100644 --- a/vendor/gix-protocol/src/handshake/refs/shared.rs +++ b/vendor/gix-protocol/src/handshake/refs/shared.rs @@ -8,20 +8,33 @@ impl From<InternalRef> for Ref { InternalRef::Symbolic { path, target: Some(target), + tag, object, } => Ref::Symbolic { full_ref_name: path, target, + tag, object, }, InternalRef::Symbolic { path, target: None, + tag: None, object, } => Ref::Direct { full_ref_name: path, object, }, + InternalRef::Symbolic { + path, + target: None, + tag: Some(tag), + object, + } => Ref::Peeled { + full_ref_name: path, + tag, + object, + }, InternalRef::Peeled { path, tag, object } => Ref::Peeled { full_ref_name: path, tag, @@ -56,6 +69,7 @@ pub(crate) enum InternalRef { /// /// The latter is more of an edge case, please [this issue][#205] for details. target: Option<BString>, + tag: Option<gix_hash::ObjectId>, object: gix_hash::ObjectId, }, /// extracted from V1 capabilities, which contain some important symbolic refs along with their targets @@ -155,6 +169,7 @@ pub(in crate::handshake::refs) fn parse_v1( Some(position) => match out_refs.swap_remove(position) { InternalRef::SymbolicForLookup { path: _, target } => out_refs.push(InternalRef::Symbolic { path: path.into(), + tag: None, // TODO: figure out how annotated tags work here. object, target, }), @@ -172,7 +187,7 @@ pub(in crate::handshake::refs) fn parse_v1( pub(in crate::handshake::refs) fn parse_v2(line: &BStr) -> Result<Ref, Error> { let trimmed = line.trim_end(); - let mut tokens = trimmed.splitn(3, |b| *b == b' '); + let mut tokens = trimmed.splitn(4, |b| *b == b' '); match (tokens.next(), tokens.next()) { (Some(hex_hash), Some(path)) => { let id = if hex_hash == b"unborn" { @@ -183,7 +198,9 @@ pub(in crate::handshake::refs) fn parse_v2(line: &BStr) -> Result<Ref, Error> { if path.is_empty() { return Err(Error::MalformedV2RefLine(trimmed.to_owned().into())); } - Ok(if let Some(attribute) = tokens.next() { + let mut symref_target = None; + let mut peeled = None; + for attribute in tokens.by_ref().take(2) { let mut tokens = attribute.splitn(2, |b| *b == b':'); match (tokens.next(), tokens.next()) { (Some(attribute), Some(value)) => { @@ -191,32 +208,12 @@ pub(in crate::handshake::refs) fn parse_v2(line: &BStr) -> Result<Ref, Error> { return Err(Error::MalformedV2RefLine(trimmed.to_owned().into())); } match attribute { - b"peeled" => Ref::Peeled { - full_ref_name: path.into(), - object: gix_hash::ObjectId::from_hex(value.as_bytes())?, - tag: id.ok_or(Error::InvariantViolation { - message: "got 'unborn' as tag target", - })?, - }, - b"symref-target" => match value { - b"(null)" => Ref::Direct { - full_ref_name: path.into(), - object: id.ok_or(Error::InvariantViolation { - message: "got 'unborn' while (null) was a symref target", - })?, - }, - name => match id { - Some(id) => Ref::Symbolic { - full_ref_name: path.into(), - object: id, - target: name.into(), - }, - None => Ref::Unborn { - full_ref_name: path.into(), - target: name.into(), - }, - }, - }, + b"peeled" => { + peeled = Some(gix_hash::ObjectId::from_hex(value.as_bytes())?); + } + b"symref-target" => { + symref_target = Some(value); + } _ => { return Err(Error::UnknownAttribute { attribute: attribute.to_owned().into(), @@ -227,13 +224,53 @@ pub(in crate::handshake::refs) fn parse_v2(line: &BStr) -> Result<Ref, Error> { } _ => return Err(Error::MalformedV2RefLine(trimmed.to_owned().into())), } - } else { - Ref::Direct { + } + if tokens.next().is_some() { + return Err(Error::MalformedV2RefLine(trimmed.to_owned().into())); + } + Ok(match (symref_target, peeled) { + (Some(target_name), peeled) => match target_name { + b"(null)" => match peeled { + None => Ref::Direct { + full_ref_name: path.into(), + object: id.ok_or(Error::InvariantViolation { + message: "got 'unborn' while (null) was a symref target", + })?, + }, + Some(peeled) => Ref::Peeled { + full_ref_name: path.into(), + object: peeled, + tag: id.ok_or(Error::InvariantViolation { + message: "got 'unborn' while (null) was a symref target", + })?, + }, + }, + name => match id { + Some(id) => Ref::Symbolic { + full_ref_name: path.into(), + tag: peeled.map(|_| id), + object: peeled.unwrap_or(id), + target: name.into(), + }, + None => Ref::Unborn { + full_ref_name: path.into(), + target: name.into(), + }, + }, + }, + (None, Some(peeled)) => Ref::Peeled { + full_ref_name: path.into(), + object: peeled, + tag: id.ok_or(Error::InvariantViolation { + message: "got 'unborn' as tag target", + })?, + }, + (None, None) => Ref::Direct { object: id.ok_or(Error::InvariantViolation { message: "got 'unborn' as object name of direct reference", })?, full_ref_name: path.into(), - } + }, }) } _ => Err(Error::MalformedV2RefLine(trimmed.to_owned().into())), diff --git a/vendor/gix-protocol/src/handshake/refs/tests.rs b/vendor/gix-protocol/src/handshake/refs/tests.rs index 7d995da5c..3a6af8d2f 100644 --- a/vendor/gix-protocol/src/handshake/refs/tests.rs +++ b/vendor/gix-protocol/src/handshake/refs/tests.rs @@ -17,6 +17,7 @@ unborn refs/heads/symbolic symref-target:refs/heads/target 808e50d724f604f69ab93c6da2919c014667bedb refs/heads/main 7fe1b98b39423b71e14217aa299a03b7c937d656 refs/tags/foo peeled:808e50d724f604f69ab93c6da2919c014667bedb 7fe1b98b39423b71e14217aa299a03b7c937d6ff refs/tags/blaz +978f927e6397113757dfec6332e7d9c7e356ac25 refs/heads/symbolic symref-target:refs/tags/v1.0 peeled:4d979abcde5cea47b079c38850828956c9382a56 " .as_bytes(), ); @@ -29,6 +30,7 @@ unborn refs/heads/symbolic symref-target:refs/heads/target Ref::Symbolic { full_ref_name: "HEAD".into(), target: "refs/heads/main".into(), + tag: None, object: oid("808e50d724f604f69ab93c6da2919c014667bedb") }, Ref::Direct { @@ -56,8 +58,14 @@ unborn refs/heads/symbolic symref-target:refs/heads/target full_ref_name: "refs/tags/blaz".into(), object: oid("7fe1b98b39423b71e14217aa299a03b7c937d6ff") }, + Ref::Symbolic { + full_ref_name: "refs/heads/symbolic".into(), + target: "refs/tags/v1.0".into(), + tag: Some(oid("978f927e6397113757dfec6332e7d9c7e356ac25")), + object: oid("4d979abcde5cea47b079c38850828956c9382a56") + }, ] - ) + ); } #[maybe_async::test(feature = "blocking-client", async(feature = "async-client", async_std::test))] @@ -86,6 +94,7 @@ dce0ea858eef7ff61ad345cc5cdac62203fb3c10 refs/tags/gix-commitgraph-v0.0.0 Ref::Symbolic { full_ref_name: "HEAD".into(), target: "refs/heads/main".into(), + tag: None, object: oid("73a6868963993a3328e7d8fe94e5a6ac5078a944") }, Ref::Direct { |