Pass deletions and renames to Git

andybalholm
Apr 18, 2023, 5:47 PM
T3IX7GG7BIFN3AX3QQWRPS5CKFZVRU5TRQAMJSYN4FEJXQL75PJQC

Dependencies

Change contents

  • replacement in src/repo.rs at line 244
    [6.1942][6.1942:2013]()
    pub fn get_files(&mut self) -> Result<Vec<File>, Box<dyn Error>> {
    [6.1942]
    [6.2013]
    pub fn get_files(&mut self) -> Result<FileSet, Box<dyn Error>> {
  • replacement in src/repo.rs at line 246
    [6.2040][6.2040:2093]()
    files: Arc::new(Mutex::new(Vec::new())),
    [6.2040]
    [6.2093]
    operations: Arc::new(Mutex::new(Vec::new())),
  • replacement in src/repo.rs at line 260
    [6.2355][6.2355:2781]()
    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);
    [6.2355]
    [6.1462]
    return Ok(fs);
  • edit in src/repo.rs at line 264
    [6.2785][6.2785:2851](),[6.2851][6.1468:1470](),[6.1468][6.1468:1470](),[6.1470][6.2852:2853]()
    pub struct File {
    pub name: String,
    pub content: Vec<u8>,
    }
  • edit in src/repo.rs at line 282
    [6.3271]
    [6.3271]
    pub enum FileOp {
    Modify { fw: FileWriter },
    Delete { path: String },
    Rename { old: String, new: String },
    }
  • replacement in src/repo.rs at line 289
    [6.3288][6.3288:3349]()
    struct FileSet {
    pub files: Arc<Mutex<Vec<FileWriter>>>,
    [6.3288]
    [6.3349]
    pub struct FileSet {
    pub operations: Arc<Mutex<Vec<FileOp>>>,
  • replacement in src/repo.rs at line 294
    [6.3376][6.3376:3396]()
    enum FileSetError {
    [6.3376]
    [6.3472]
    pub enum FileSetError {
  • edit in src/repo.rs at line 296
    [6.3496][6.3496:3513]()
    MutexPoison,
  • edit in src/repo.rs at line 304
    [6.4041][6.4041:4111]()
    FileSetError::MutexPoison => write!(f, "poisoned mutex"),
  • replacement in src/repo.rs at line 331
    [6.4772][3.0:80]()
    fn remove_path(&self, _path: &str, _rec: bool) -> Result<(), Self::Error> {
    [6.4772]
    [3.80]
    fn remove_path(&self, path: &str, _rec: bool) -> Result<(), Self::Error> {
    self.operations.lock().unwrap().push(FileOp::Delete {
    path: path.to_owned(),
    });
  • replacement in src/repo.rs at line 339
    [6.4996][5.0:516]()
    let mut with_slash = old.to_owned();
    with_slash.push_str("/");
    let mut files = self.files.lock().unwrap();
    for f in files.iter_mut() {
    if f.name == old {
    f.name = new.to_owned();
    } else if f.name.starts_with(&with_slash) {
    let (_, remainder) = f.name.split_at(old.len());
    let mut new_name = new.to_owned();
    new_name.push_str(remainder);
    f.name = new_name;
    }
    }
    [6.4996]
    [5.516]
    self.operations.lock().unwrap().push(FileOp::Rename {
    old: old.to_owned(),
    new: new.to_owned(),
    });
  • replacement in src/repo.rs at line 355
    [6.5460][6.5460:5612]()
    match self.files.lock() {
    Ok(mut v) => v.push(f.clone()),
    Err(_err) => return Err(FileSetError::MutexPoison),
    }
    [6.5460]
    [6.5612]
    self.operations
    .lock()
    .unwrap()
    .push(FileOp::Modify { fw: f.clone() });
  • replacement in src/fast_export.rs at line 12
    [6.339][6.5917:5940]()
    use crate::repo::File;
    [6.339]
    [6.339]
    use crate::repo::FileOp;
    use crate::repo::FileSet;
  • replacement in src/fast_export.rs at line 53
    [6.6009][2.80:186](),[2.186][2.186:213](),[2.213][2.213:221](),[2.221][6.6111:6177](),[6.6111][6.6111:6177](),[6.6177][2.222:312](),[2.312][2.312:549](),[2.549][6.6262:6302](),[6.6262][6.6262:6302](),[6.6302][2.550:659](),[2.659][2.659:779](),[2.779][2.779:809]()
    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 {
    let content: &[u8] = &f.content;
    let h = sha256::digest(content);
    let mut new_blob = false;
    let blob_mark = *self.blob_marks.entry(h).or_insert_with(|| {
    new_blob = true;
    self.max_blob_mark += 1;
    self.max_blob_mark
    });
    file_marks.push(blob_mark);
    if new_blob {
    println!("blob");
    println!("mark :{}", blob_mark);
    println!("data {}", f.content.len());
    std::io::stdout().write_all(&f.content).unwrap();
    println!("");
    [6.6009]
    [2.809]
    pub fn write_commit(&mut self, c: &Change, parent: Option<libpijul::Merkle>, files: &FileSet) {
    let mut file_marks = HashMap::new();
    for op in &*files.operations.lock().unwrap() {
    match &op {
    FileOp::Modify { fw } => {
    let ct = fw.content.lock().unwrap();
    let content: &[u8] = &*ct;
    let h = sha256::digest(content);
    let mut new_blob = false;
    let blob_mark = *self.blob_marks.entry(h).or_insert_with(|| {
    new_blob = true;
    self.max_blob_mark += 1;
    self.max_blob_mark
    });
    file_marks.insert(fw.name.clone(), blob_mark);
    if new_blob {
    println!("blob");
    println!("mark :{}", blob_mark);
    println!("data {}", content.len());
    std::io::stdout().write_all(content).unwrap();
    println!("");
    }
    }
    _ => (),
  • replacement in src/fast_export.rs at line 112
    [6.6710][6.6710:6741](),[6.6741][6.6741:6775](),[6.6775][4.340:398](),[4.398][4.398:475](),[4.475][4.475:490]()
    println!("deleteall");
    for i in 0..files.len() {
    println!(
    "M 644 :{} \"{}\"",
    file_marks[i],
    escape_string(&files[i].name)
    );
    [6.6710]
    [6.1147]
    for op in &*files.operations.lock().unwrap() {
    match &op {
    FileOp::Modify { fw } => println!(
    "M 644 :{} \"{}\"",
    file_marks.get(&fw.name).unwrap(),
    escape_string(&fw.name)
    ),
    FileOp::Delete { path } => println!("D \"{}\"", escape_string(&path)),
    FileOp::Rename { old, new } => {
    println!("R \"{}\" \"{}\"", escape_string(&old), escape_string(&new))
    }
    };