display basic repo stuff
[?]
Feb 6, 2025, 5:16 PM
SWWE2R6MVBX5CNM6X3WLXZTSRTU53PBJL7WJSFVF77XBPXDX4COACDependencies
- [2]
6YZAVBWUInitial commit - [3]
IQDCHWCPload a pijul repo - [4]
3GZPRZXCs/-/_ in crate paths - [5]
KLR5FRIBadd fs state read/write of repos
Change contents
- file addition: repo.rs[4.36]
use std::collections::BTreeSet;use std::{borrow::Cow, ops::Deref, path::PathBuf};use derivative::Derivative;use libflowers::prelude::*;use pijul::change::{Author, ChangeHeader, Hunk, Local};use pijul::change::{BaseHunk, LocalChange};use pijul::Hash;#[derive(Derivative)]#[derivative(Debug)]pub struct State {#[derivative(Debug(format_with = "fmt_pijul_repository"))]pub state: pijul::Repository,pub changed_files: BTreeSet<String>,}impl Deref for State {type Target = pijul::Repository;fn deref(&self) -> &Self::Target {&self.state}}pub type Diff = LocalChange<Hunk<Option<Hash>, Local>, Author>;pub fn load(path: PathBuf) -> State {let state = pijul::Repository::find_root(Some(path)).unwrap();let diff = diff(&state);let changed_files = changed_files(&diff);State {state,changed_files,}}pub fn dir_name(repo: &pijul::Repository) -> Cow<'_, str> {repo.path.iter().last().unwrap().to_string_lossy()}pub fn current_channel(repo: &pijul::Repository) -> String {use pijul::TxnT;let txn = repo.pristine.arc_txn_begin().unwrap();let read_guard = txn.read();read_guard.current_channel().unwrap_or(pijul::DEFAULT_CHANNEL).to_string()}pub fn diff(repo: &pijul::Repository) -> Diff {use pijul::MutTxnT;use pijul::TxnT;let txn = repo.pristine.arc_txn_begin().unwrap();let cur_channel = txn.read().current_channel().unwrap_or(pijul::DEFAULT_CHANNEL).to_string();let channel = txn.write().open_or_create_channel(&cur_channel).unwrap();let mut state = pijul::RecordBuilder::new();state.record(txn.clone(),pijul::Algorithm::default(),false,&pijul::DEFAULT_SEPARATOR,channel.clone(),&repo.working_copy,&repo.changes,"",std::thread::available_parallelism().unwrap().get(),).unwrap();let rec = state.finish();let actions: Vec<_> = {let txn_ = txn.read();rec.actions.into_iter().map(|rec| rec.globalize(&*txn_).unwrap()).collect()};let contents = std::sync::Arc::try_unwrap(rec.contents).unwrap().into_inner();let mut change = LocalChange::make_change(&*txn.read(),&channel,actions,contents,ChangeHeader::default(),Vec::new(),).unwrap();let (dependencies, extra_known) = {let txn_ = txn.read();pijul::change::dependencies(&*txn_,&*channel.read(),change.changes.iter(),).unwrap()};change.dependencies = dependencies;change.extra_known = extra_known;change}fn changed_files(diff: &Diff) -> BTreeSet<String> {diff.changes.iter().map(|change| match change {BaseHunk::FileMove { del, add, path } => todo!(),BaseHunk::FileDel {del,contents,path,encoding,} => todo!(),BaseHunk::FileUndel {undel,contents,path,encoding,} => todo!(),BaseHunk::FileAdd {add_name,add_inode,contents,path,encoding,} => todo!(),BaseHunk::SolveNameConflict { name, path } => todo!(),BaseHunk::UnsolveNameConflict { name, path } => todo!(),BaseHunk::Edit {change,local,encoding,} => local.path.clone(),BaseHunk::Replacement {change,replacement,local,encoding,} => todo!(),BaseHunk::SolveOrderConflict { change, local } => todo!(),BaseHunk::UnsolveOrderConflict { change, local } => todo!(),BaseHunk::ResurrectZombies {change,local,encoding,} => todo!(),BaseHunk::AddRoot { name, inode } => todo!(),BaseHunk::DelRoot { name, inode } => todo!(),}).collect()}fn fmt_pijul_repository(value: &pijul::Repository,f: &mut std::fmt::Formatter,) -> Result<(), std::fmt::Error> {f.debug_struct("Repository").field("config", &value.config).field("path", &value.path).field("changes_dir", &value.changes_dir).finish()} - replacement in crates/libflowers_client/src/lib.rs at line 1[2.1360]→[3.7:224](∅→∅),[3.224]→[2.1361:1362](∅→∅),[2.1360]→[2.1361:1362](∅→∅),[2.1362]→[3.225:528](∅→∅)
use derivative::Derivative;use libflowers::prelude::*;#[derive(Derivative)]#[derivative(Debug)]pub struct Repo {#[derivative(Debug(format_with = "fmt_pijul_repository"))]pub state: pijul::Repository,}fn fmt_pijul_repository(value: &pijul::Repository,f: &mut std::fmt::Formatter,) -> Result<(), std::fmt::Error> {f.debug_struct("Repository").field("config", &value.config).field("path", &value.path).field("changes_dir", &value.changes_dir).finish()}[2.1360]pub mod repo; - edit in crates/flowers_ui/src/main.rs at line 1
use libflowers::prelude::*;use libflowers_client::Repo;use pijul::Repository; - edit in crates/flowers_ui/src/main.rs at line 2
use libflowers::prelude::*;use libflowers_client::repo; - replacement in crates/flowers_ui/src/main.rs at line 6
use iced::widget::{button, text};use iced::{Element, Task, Theme};use iced::widget::{column, horizontal_rule, row, text};use iced::{Element, Length, Task, Theme}; - replacement in crates/flowers_ui/src/main.rs at line 17
let repo = Repo {state: Repository::find_root(Some(repo_path.clone())).unwrap(),};(State { repo_path, repo }, Task::none())let repo = repo::load(repo_path);// dbg!(repo::diff(&repo));(State { repo }, Task::none()) - replacement in crates/flowers_ui/src/main.rs at line 24
repo_path: PathBuf,repo: Repo,repo: repo::State, - replacement in crates/flowers_ui/src/main.rs at line 32
enum Message {}enum Message {} - replacement in crates/flowers_ui/src/main.rs at line 35
match message {}match message {} - replacement in crates/flowers_ui/src/main.rs at line 39
let path = state.repo.state.path.to_string_lossy();text(path).into()let dir_name = repo::dir_name(&state.repo);let channel = repo::current_channel(&state.repo);let repo_info = Element::from(row([Element::from(text(dir_name)),Element::from(text(": ")),Element::from(text(channel)),]));let changed_files = Element::from(column(state.repo.changed_files.iter().map(|path| Element::from(text(path))),));let log = Element::from(column(["todo: commits"].iter().map(|hash| Element::from(text(*hash))),));Element::from(row([Element::from(column([repo_info,Element::from(horizontal_rule(1)),changed_files,Element::from(horizontal_rule(1)),log,]).width(Length::FillPortion(1)),),Element::from(column([]).width(Length::FillPortion(1))),]))