struct RemoteInfo {
id: Option<RemoteId>,
path: SmallString,
}
fn get_remote_by_any(
repo: &Repository,
txn: &mut MutTxn<()>,
spec: &str,
) -> Result<Option<RemoteInfo>, anyhow::Error> {
// Try indexing by ID first
if let Some(id) = RemoteId::from_base32(spec.as_bytes()) {
if let Some(r) = txn.get_remote(id)? {
let path = r.lock().path.clone();
return Ok(Some(RemoteInfo { id: Some(id), path }));
}
}
// Look it up by URL
for r in txn.iter_remotes(&RemoteId::nil())? {
let r = r?;
let path = r.lock().path.clone();
if path.as_str() == spec {
return Ok(Some(RemoteInfo {
id: Some(*r.id()),
path,
}));
}
}
// Otherwise, is it set as the default remote?
if repo.config.default_remote.as_deref() == Some(spec) {
return Ok(Some(RemoteInfo {
id: None,
path: SmallString::from_str(spec),
}));
}
Ok(None)
}