Safeguarding `pijul channel new`: it was too easy to create a new, independent root

pmeunier
Feb 27, 2023, 2:37 PM
YK7EBTF6LAPMYEHPPOUKHO3IQTA4MTKOEI77I4UWXTM4T475QKRAC

Dependencies

  • [2] TDTCT6EG New channel: confusion in subcommand names
  • [3] A3RM526Y Integrating identity malleability
  • [4] TFK7CYFQ `pijul channel new` to create new, empty channels
  • [5] PGERZ3KJ Channel renaming (also do not create a new channel when recording on a channel that doesn't exist)
  • [6] SXEYMYF7 Fixing the bad changes in history (unfortunately, by rebooting).
  • [*] GHO6DWPI Refactoring iterators
  • [*] L4JXJHWX pijul/*: reorganize imports and remove extern crate

Change contents

  • edit in pijul/src/commands/channel.rs at line 9
    [8.987]
    [9.3080]
    use log::debug;
  • replacement in pijul/src/commands/channel.rs at line 39
    [2.26][4.66:92](),[4.66][4.66:92]()
    New { name: String },
    [2.26]
    [4.187365]
    New {
    name: String,
    #[clap(long = "empty")]
    empty: bool,
    #[clap(long = "force", short = 'f')]
    force: bool,
    },
  • replacement in pijul/src/commands/channel.rs at line 108
    [4.107][4.107:155]()
    Some(SubCommand::New { name }) => {
    [4.107]
    [3.24716]
    Some(SubCommand::New { name, empty, force }) => {
    if empty && !force {
    bail!("If creating an empty channel is really what you want, please use -f.")
    }
  • replacement in pijul/src/commands/channel.rs at line 117
    [4.425][4.425:477]()
    txn.open_or_create_channel(&name)?;
    [4.425]
    [4.477]
    let new = txn.open_or_create_channel(&name)?;
    if !empty {
    // Safeguard: apply the root patch if we're creating a new channel.
    let current = txn.current_channel()?;
    let channel = if let Some(channel) = txn.load_channel(current)? {
    channel
    } else {
    bail!("No such channel: {:?}", current)
    };
    let ch = channel.read();
    use libpijul::{GraphTxnT, MutTxnTExt};
    let h = if let Some(Ok((k, v))) =
    libpijul::pristine::changeid_log(&txn, &ch, 0u64.into())?.next()
    {
    debug!("initial patch on current channel: {:?} {:?}", k, v);
    Some(txn.get_external(&v.a)?.unwrap().into())
    } else {
    None
    };
    if let Some(h) = h {
    let mut new = new.write();
    txn.apply_change(&repo.changes, &mut new, &h)?;
    }
    }