Include file content

andybalholm
Mar 20, 2023, 11:50 PM
FIIUZR4LJOB5DPB4CBMPJHMO7C5Q4ZINUVM52UK6SIM5WM7R7ZLAC

Dependencies

Change contents

  • edit in rust/src/repo.rs at line 7
    [8.91]
    [4.0]
    use std::sync::Arc;
    use std::sync::Mutex;
  • edit in rust/src/repo.rs at line 20
    [9.76]
    [8.137]
    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
    [8.205]
    [8.205]
    path: String,
  • edit in rust/src/repo.rs at line 56
    [8.570]
    [2.128]
    #[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
    [4.474]
    [4.474]
    path: path.to_string(),
  • edit in rust/src/repo.rs at line 205
    [8.1462]
    [8.1462]
    }
    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
    [8.1468]
    [8.1468]
    }
    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
    [4.1721]
    [3.98]
    let mut sandbox = repo.new_sandbox().unwrap();
  • edit in rust/src/main.rs at line 28
    [3.130]
    [3.130]
    sandbox.add_change(&changes[i]).unwrap();
    let files = sandbox.get_files().unwrap();
  • replacement in rust/src/main.rs at line 33
    [3.197][3.197:234]()
    Some(changes[i-1].state)
    [3.197]
    [3.234]
    Some(changes[i - 1].state)
  • replacement in rust/src/main.rs at line 35
    [3.245][3.245:295]()
    stream.write_commit(&changes[i], parent);
    [3.245]
    [4.939]
    stream.write_commit(&changes[i], parent, &files);
  • edit in rust/src/fast_export.rs at line 2
    [3.327]
    [3.327]
    use std::io::Write;
  • edit in rust/src/fast_export.rs at line 5
    [4.339]
    [4.339]
    use crate::repo::File;
  • edit in rust/src/fast_export.rs at line 12
    [3.406]
    [4.399]
    max_blob_mark: i32,
  • edit in rust/src/fast_export.rs at line 23
    [3.599]
    [3.599]
    max_blob_mark: 1000000000,
  • edit in rust/src/fast_export.rs at line 27
    [3.616]
    [3.616]
    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
    [3.617][3.617:700]()
    pub fn write_commit(&mut self, c: &Change, parent: Option<libpijul::Merkle>) {
    [3.617]
    [4.475]
  • replacement in rust/src/fast_export.rs at line 63
    [3.917][3.917:1108]()
    Some(p) => {
    match self.commit_marks.get(&p) {
    Some(p_mark) => println!("from :{}", p_mark),
    None => {},
    }
    [3.917]
    [3.1108]
    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
    [3.1123][3.1123:1147]()
    None => {},
    [3.1123]
    [3.1147]
    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
    [3.1157][4.1032:1082](),[4.1032][4.1032:1082]()
    // TODO: deleteall
    // TODO: files