Legacy-compatible `remotes` deserialization. Accepts the current `[[remotes]]` sequence and the legacy `[remotes. ]` map (0.17.x shape) interchangeably; the legacy map's `default` flag is structural to 0.17.x and carries no meaning in the current schema, so it is ignored here.
(deserializer: D)
| 436 | /// `default` flag is structural to 0.17.x and carries no meaning in the |
| 437 | /// current schema, so it is ignored here. |
| 438 | fn deserialize_remotes_compat<'de, D>(deserializer: D) -> Result<Vec<RemoteConfig>, D::Error> |
| 439 | where |
| 440 | D: serde::Deserializer<'de>, |
| 441 | { |
| 442 | let value = serde_json::Value::deserialize(deserializer)?; |
| 443 | match value { |
| 444 | serde_json::Value::Array(entries) => entries |
| 445 | .into_iter() |
| 446 | .map(|entry| { |
| 447 | serde_json::from_value::<RemoteConfig>(entry).map_err(serde::de::Error::custom) |
| 448 | }) |
| 449 | .collect(), |
| 450 | serde_json::Value::Object(map) => { |
| 451 | let mut remotes = Vec::new(); |
| 452 | for (name, entry) in map { |
| 453 | let url = entry |
| 454 | .get("url") |
| 455 | .and_then(serde_json::Value::as_str) |
| 456 | .ok_or_else(|| { |
| 457 | serde::de::Error::custom(format!("legacy remote '{name}' has no url")) |
| 458 | })?; |
| 459 | remotes.push(RemoteConfig { |
| 460 | name, |
| 461 | url: url.to_string(), |
| 462 | default_channel: entry |
| 463 | .get("default_channel") |
| 464 | .and_then(serde_json::Value::as_str) |
| 465 | .map(str::to_string), |
| 466 | }); |
| 467 | } |
| 468 | remotes.sort_by(|left, right| left.name.cmp(&right.name)); |
| 469 | Ok(remotes) |
| 470 | } |
| 471 | other => Err(serde::de::Error::custom(format!( |
| 472 | "remotes must be a sequence or a legacy name-keyed map, got {other:?}" |
| 473 | ))), |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | /// Serialize `remotes` in the legacy `[remotes.<name>]` map shape so 0.17.x |
| 478 | /// binaries keep parsing the file. |