Allow deleting remote by URL and remove default remote if set to deleted remote

dblsaiko
Mar 27, 2024, 4:28 PM
OWJL5HO72US47LCBHUZVH6ONALVEADWMFAMXK5RMDHLXSCCFSFQAC

Dependencies

  • [2] IVLLXQ5Z Improved push/pull reporting
  • [3] YN63NUZO Sanakirja 1.0
  • [4] QCPIBC6M Make the default remote configurable through the cli
  • [5] CCLLB7OI Upgrading to Sanakirja 0.15 + version bump
  • [6] JL4WKA5P Implement the Sanakirja concurrency model in a cross-process way
  • [7] ZBNKSYA6 Fixing a bus error when starting a transaction on a full disk
  • [8] A3RM526Y Integrating identity malleability
  • [9] SXEYMYF7 Fixing the bad changes in history (unfortunately, by rebooting).
  • [10] VZL5OHF5 Remove the obsolete `remote list` command

Change contents

  • edit in pijul/src/commands/pushpull.rs at line 11
    [2.18516]
    [3.12857]
    use libpijul::pristine::RemoteId;
    use libpijul::small_string::SmallString;
  • edit in pijul/src/commands/pushpull.rs at line 40
    [3.112189]
    [3.112189]
    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)
    }
  • replacement in pijul/src/commands/pushpull.rs at line 91
    [3.112523][3.14653:14736]()
    for r in txn.iter_remotes(&libpijul::pristine::RemoteId::nil())? {
    [3.112523]
    [3.12924]
    for r in txn.iter_remotes(&RemoteId::nil())? {
  • replacement in pijul/src/commands/pushpull.rs at line 102
    [3.112712][3.14830:15111]()
    let remote =
    if let Some(r) = libpijul::pristine::RemoteId::from_base32(remote.as_bytes()) {
    r
    } else {
    bail!("Could not parse identifier: {:?}", remote)
    };
    [3.112712]
    [3.284]
    let mut repo = repo;
  • replacement in pijul/src/commands/pushpull.rs at line 104
    [3.346][3.15112:15225](),[3.15225][3.112910:112970](),[3.112910][3.112910:112970]()
    if !txn.drop_named_remote(remote)? {
    bail!("Remote not found: {:?}", remote)
    } else {
    txn.commit()?;
    [3.346]
    [3.112970]
    let Some(ri) = get_remote_by_any(&repo, &mut txn, &remote)? else {
    bail!("No such remote: {}", remote);
    };
    if let Some(id) = ri.id {
    txn.drop_named_remote(id)?;
    }
    if repo.config.default_remote.as_deref() == Some(ri.path.as_str()) {
    repo.config.default_remote = None;
  • edit in pijul/src/commands/pushpull.rs at line 116
    [3.112988]
    [3.112988]
    txn.commit()?;
    repo.update_config()?;