Add common functions to load channel for CLI operations

dblsaiko
Mar 29, 2024, 9:15 PM
UBTOH654TM6FU5ZZERAQZPW2PMJ7QVDHPMV6O236GB4Y6G2QGMFAC

Dependencies

  • [2] GKSVBEUW Refactor Repository constructors to take Option<&Path> instead of Option<PathBuf>
  • [3] X243Z3Y5 Recording only the required metadata (can even be changed later!)
  • [4] A3RM526Y Integrating identity malleability
  • [5] E7UUQQCC Apply changes with prefixes in .pijul/changes
  • [6] SXEYMYF7 Fixing the bad changes in history (unfortunately, by rebooting).
  • [7] 3QXUJMZD More detailed display of conflicts
  • [8] C4MJ7D7Q Verbose printing of conflicts to stderr
  • [*] SLJ3OHD4 unrecord: show list of changes if none were given as arguments

Change contents

  • replacement in pijul/src/commands/mod.rs at line 1
    [3.133619][3.19755:19773]()
    use anyhow::bail;
    [3.133619]
    [2.1932]
    use anyhow::{anyhow, bail};
  • replacement in pijul/src/commands/mod.rs at line 326
    [3.1593][3.1593:1617]()
    use libpijul::Conflict;
    [3.1593]
    [3.1617]
    use libpijul::{ChannelRef, Conflict, TxnT};
  • edit in pijul/src/commands/mod.rs at line 370
    [3.3076]
    [10.5215]
    }
    fn get_channel<'a, T>(cli: Option<&'a str>, txn: &'a T) -> (&'a str, bool)
    where
    T: TxnT,
    {
    let cur = txn.current_channel().ok();
    let ch = cli.or(cur);
    (ch.unwrap_or(libpijul::DEFAULT_CHANNEL), ch == cur)
  • edit in pijul/src/commands/mod.rs at line 380
    [10.5217]
    fn load_channel<T>(cli: Option<&str>, txn: &T) -> anyhow::Result<(ChannelRef<T>, bool)>
    where
    T: TxnT,
    {
    let (channel_name, is_current_channel) = get_channel(cli, &*txn);
    let channel = load_channel_exact(&channel_name, txn)?;
    Ok((channel, is_current_channel))
    }
    fn load_channel_exact<T>(name: &str, txn: &T) -> anyhow::Result<ChannelRef<T>>
    where
    T: TxnT,
    {
    txn.load_channel(name)?
    .ok_or_else(|| anyhow!("No such channel: {}", name))
    }