Include file content
Dependencies
- [2]
D467LQZ6Load identities - [3]
OZUZ5H6DUse marks for commits - [4]
UFSP7C7BExport metadata - [5]
YNZMKRJDinclude more information in log - [6]
W7HZ5VFMRIIR: list changes - [*]
ATRA7XTTRIIR: factor out Repository struct - [*]
RVRUZGHUFactor out load_channel function - [*]
TQBJZLD7RIIR: hello, world
Change contents
- edit in rust/src/repo.rs at line 7
use std::sync::Arc;use std::sync::Mutex; - edit in rust/src/repo.rs at line 20
use libpijul::pristine::InodeMetadata;use libpijul::working_copy::WorkingCopy;use libpijul::working_copy::WorkingCopyRead;use libpijul::MutTxnT;use libpijul::MutTxnTExt; - edit in rust/src/repo.rs at line 29
path: String, - edit in rust/src/repo.rs at line 56
#[derive(Debug, Clone)]pub struct StateMismatch {got: libpijul::Merkle,want: libpijul::Merkle,}impl fmt::Display for StateMismatch {fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {write!(f,"state mismatch: got {:?}, want {:?}",self.got, self.want)}}impl Error for StateMismatch {} - edit in rust/src/repo.rs at line 109
path: path.to_string(), - edit in rust/src/repo.rs at line 205
}pub fn new_sandbox(&mut self) -> Result<Sandbox, Box<dyn Error>> {let change_store =libpijul::changestore::filesystem::FileSystem::from_root(&Path::new(&self.path), 256);let txn = self.pristine.arc_txn_begin()?;let channel = txn.write().open_or_create_channel("pijul-export-sandbox")?;return Ok(Sandbox {change_store,txn,channel,});}}// A Sandbox has a temporary channel for applying changes and getting the// contents of the affected files.pub struct Sandbox {change_store: libpijul::changestore::filesystem::FileSystem,txn: libpijul::pristine::ArcTxn<libpijul::pristine::sanakirja::MutTxn<()>>,channel: libpijul::pristine::ChannelRef<libpijul::pristine::sanakirja::MutTxn<()>>,}impl Sandbox {pub fn add_change(&mut self, change: &Change) -> Result<(), Box<dyn Error>> {let (_, new_state) = self.txn.write().apply_change(&self.change_store,&mut *self.channel.write(),&change.hash,)?;if new_state != change.state {return Err(Box::new(StateMismatch {got: new_state,want: change.state,}));}return Ok(());}pub fn get_files(&mut self) -> Result<Vec<File>, Box<dyn Error>> {let fs = FileSet {files: Arc::new(Mutex::new(Vec::new())),};libpijul::output::output_repository_no_pending(&fs,&self.change_store,&self.txn,&self.channel,"",false,None,1,0,)?;let mut files: Vec<File> = Vec::new();let mut file_writers = match fs.files.lock() {Ok(fw) => fw,Err(err) => panic!("mutex error: {}", err),};for f in file_writers.drain(..) {files.push(File {name: f.name,content: Arc::try_unwrap(f.content).unwrap().into_inner()?,});}return Ok(files); - edit in rust/src/repo.rs at line 274
}pub struct File {pub name: String,pub content: Vec<u8>, - edit in rust/src/repo.rs at line 280[8.1470]
#[derive(Clone)]pub struct FileWriter {pub name: String,pub content: Arc<Mutex<Vec<u8>>>,}impl std::io::Write for FileWriter {fn write(&mut self, b: &[u8]) -> Result<usize, std::io::Error> {match self.content.lock() {Ok(mut c) => c.write(b),Err(e) => panic!("{}", e),}}fn flush(&mut self) -> Result<(), std::io::Error> {Ok(())}}#[derive(Clone)]struct FileSet {pub files: Arc<Mutex<Vec<FileWriter>>>,}#[derive(Debug, Clone)]enum FileSetError {RemoveNotImplemented(String),RenameNotImplemented(String, String),ReadNotImplemented,MutexPoison,}impl Error for FileSetError {}impl fmt::Display for FileSetError {fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {match self {FileSetError::RemoveNotImplemented(p) => {write!(f, "not implemented: remove_path({})", p)}FileSetError::RenameNotImplemented(old, new) => {write!(f, "not implemented: rename({}, {})", old, new)}FileSetError::ReadNotImplemented => write!(f, "not implemented: WorkingCopyRead"),FileSetError::MutexPoison => write!(f, "poisoned mutex"),}}}impl WorkingCopyRead for FileSet {type Error = FileSetError;fn file_metadata(&self, _file: &str) -> Result<InodeMetadata, Self::Error> {Err(FileSetError::ReadNotImplemented)}fn read_file(&self, _file: &str, _buffer: &mut Vec<u8>) -> Result<(), Self::Error> {Err(FileSetError::ReadNotImplemented)}fn modified_time(&self, _file: &str) -> Result<std::time::SystemTime, Self::Error> {Err(FileSetError::ReadNotImplemented)}}impl WorkingCopy for FileSet {type Writer = FileWriter;fn create_dir_all(&self, _file: &str) -> Result<(), Self::Error> {Ok(())}fn remove_path(&self, path: &str, _rec: bool) -> Result<(), Self::Error> {Err(FileSetError::RemoveNotImplemented(path.to_string()))}fn rename(&self, old: &str, new: &str) -> Result<(), Self::Error> {Err(FileSetError::RenameNotImplemented(old.to_string(),new.to_string(),))}fn set_permissions(&self, _file: &str, _permissions: u16) -> Result<(), Self::Error> {Ok(())}fn write_file(&self, file: &str, _: libpijul::Inode) -> Result<Self::Writer, Self::Error> {let f = FileWriter {name: file.to_string(),content: Arc::new(Mutex::new(Vec::new())),};match self.files.lock() {Ok(mut v) => v.push(f.clone()),Err(_err) => return Err(FileSetError::MutexPoison),}return Ok(f);}} - edit in rust/src/main.rs at line 25
let mut sandbox = repo.new_sandbox().unwrap(); - edit in rust/src/main.rs at line 28
sandbox.add_change(&changes[i]).unwrap();let files = sandbox.get_files().unwrap(); - replacement in rust/src/main.rs at line 33
Some(changes[i-1].state)Some(changes[i - 1].state) - replacement in rust/src/main.rs at line 35
stream.write_commit(&changes[i], parent);stream.write_commit(&changes[i], parent, &files); - edit in rust/src/fast_export.rs at line 2
use std::io::Write; - edit in rust/src/fast_export.rs at line 5
use crate::repo::File; - edit in rust/src/fast_export.rs at line 12
max_blob_mark: i32, - edit in rust/src/fast_export.rs at line 23
max_blob_mark: 1000000000, - edit in rust/src/fast_export.rs at line 27
pub fn write_commit(&mut self, c: &Change, parent: Option<libpijul::Merkle>, files: &Vec<File>) {let mut file_marks = Vec::new();for f in files {self.max_blob_mark += 1;let blob_mark = self.max_blob_mark;file_marks.push(blob_mark);println!("blob");println!("mark :{}", blob_mark);println!("data {}", f.content.len());std::io::stdout().write_all(&f.content).unwrap();println!("");} - replacement in rust/src/fast_export.rs at line 41
pub fn write_commit(&mut self, c: &Change, parent: Option<libpijul::Merkle>) { - replacement in rust/src/fast_export.rs at line 63
Some(p) => {match self.commit_marks.get(&p) {Some(p_mark) => println!("from :{}", p_mark),None => {},}Some(p) => match self.commit_marks.get(&p) {Some(p_mark) => println!("from :{}", p_mark),None => {} - replacement in rust/src/fast_export.rs at line 67
None => {},None => {}}println!("deleteall");for i in 0..files.len() {println!("M 644 :{} {}", file_marks[i], &files[i].name); - edit in rust/src/fast_export.rs at line 73
// TODO: deleteall// TODO: files