Pass deletions and renames to Git
Dependencies
- [2]
VK2ZYIOFdeduplicate blobs - [3]
ZGFCBIPXFileSet: no error for remove_path - [4]
FRQZB7LJquote and escape filenames - [5]
WQACY5X6FileSet: implement rename - [6]
ATRA7XTTRIIR: factor out Repository struct - [7]
UFSP7C7BExport metadata - [8]
OZUZ5H6DUse marks for commits - [9]
FIIUZR4LInclude file content - [10]
QWLMNP5Fnew ChangeStore implementation
Change contents
- replacement in src/repo.rs at line 244
pub fn get_files(&mut self) -> Result<Vec<File>, Box<dyn Error>> {pub fn get_files(&mut self) -> Result<FileSet, Box<dyn Error>> { - replacement in src/repo.rs at line 246
files: Arc::new(Mutex::new(Vec::new())),operations: Arc::new(Mutex::new(Vec::new())), - replacement in src/repo.rs at line 260
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);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
pub enum FileOp {Modify { fw: FileWriter },Delete { path: String },Rename { old: String, new: String },} - replacement in src/repo.rs at line 289
struct FileSet {pub files: Arc<Mutex<Vec<FileWriter>>>,pub struct FileSet {pub operations: Arc<Mutex<Vec<FileOp>>>, - replacement in src/repo.rs at line 294
enum FileSetError {pub enum FileSetError { - edit in src/repo.rs at line 296
MutexPoison, - edit in src/repo.rs at line 304
FileSetError::MutexPoison => write!(f, "poisoned mutex"), - replacement in src/repo.rs at line 331
fn remove_path(&self, _path: &str, _rec: bool) -> Result<(), Self::Error> {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
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;}}self.operations.lock().unwrap().push(FileOp::Rename {old: old.to_owned(),new: new.to_owned(),}); - replacement in src/repo.rs at line 355
match self.files.lock() {Ok(mut v) => v.push(f.clone()),Err(_err) => return Err(FileSetError::MutexPoison),}self.operations.lock().unwrap().push(FileOp::Modify { fw: f.clone() }); - replacement in src/fast_export.rs at line 12
use crate::repo::File;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!("");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));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))}};