pijul 1.0.0-alpha.9

The sound distributed version control system.
use std::path::PathBuf;

use clap::Clap;
use libpijul::TxnT;

use crate::repository::Repository;
use crate::Error;

#[derive(Clap, Debug)]
pub struct Debug {
    #[clap(long = "repository")]
    repo_path: Option<PathBuf>,
    #[clap(long = "channel")]
    channel: Option<String>,
}

impl Debug {
    pub fn run(self) -> Result<(), anyhow::Error> {
        let repo = Repository::find_root(self.repo_path)?;
        let txn = repo.pristine.txn_begin()?;
        libpijul::pristine::debug_inodes(&txn);
        libpijul::pristine::debug_tree_print(&txn);
        libpijul::pristine::debug_revtree_print(&txn);
        let channel_name = repo.config.get_current_channel(self.channel.as_ref());
        let channel = if let Some(channel) = txn.load_channel(&channel_name) {
            channel
        } else {
            return Err((Error::NoSuchChannel {
                channel: channel_name.to_string(),
            })
            .into());
        };
        let channel = channel.borrow();
        libpijul::pristine::debug(&txn, &channel, std::io::stdout())?;
        Ok(())
    }
}