Skip to content

Commit

Permalink
update codegen from git by ignoring files that already exist on disk
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiaskrgr committed Jan 28, 2024
1 parent 4198efe commit f3a50c7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ http://github.com/langston-barrett/treereduce testcase reducion
http://github.com/langston-barrett/tree-splicer code mutator which icemaker can use to generate more code


Trophy case (930+): -a
Trophy case (930+):

https://github.com/rust-lang/rust/issues/120421
https://github.com/rust-lang/rust/issues/120397
https://github.com/rust-lang/rustfmt/issues/6043
https://github.com/rust-lang/rust/issues/120343
Expand Down
44 changes: 24 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2526,17 +2526,6 @@ fn codegen_git_original_dirs() {
let hash = split.next().unwrap();
let path = split.next().unwrap();

let obj = hash;

let stdout = std::process::Command::new("git")
.arg("cat-file")
.arg("-p")
.arg(obj)
.output()
.expect("git cat-file -p <obj> failed")
.stdout;
// the file content
let text = String::from_utf8(stdout).unwrap();
let path_path = PathBuf::from(path);
let file_path = path_path.file_name().unwrap();
let dir = path_path.parent().unwrap();
Expand All @@ -2547,16 +2536,31 @@ fn codegen_git_original_dirs() {
std::fs::create_dir_all(dir).expect("failed to create directories");
}

let final_path = format!("{}/{}", dir.display(), file_path.to_str().unwrap());
let actual_file_path: String =
format!("{}/{}", dir.display(), file_path.to_str().unwrap());

std::fs::write(&final_path, text).unwrap_or_else(|_| {
panic!("failed to write to file: '{final_path}'");
});
} else {
eprintln!(
"not writing file {}",
format_args!("{}/{}", dir.display(), file_path.to_str().unwrap())
);
if !&std::path::PathBuf::from(&actual_file_path).exists() {
let obj = hash;

let stdout = std::process::Command::new("git")
.arg("cat-file")
.arg("-p")
.arg(obj)
.output()
.expect("git cat-file -p <obj> failed")
.stdout;
// the file content
let text = String::from_utf8(stdout).unwrap();

std::fs::write(&actual_file_path, text).unwrap_or_else(|_| {
panic!("failed to write to file: '{actual_file_path}'");
});
} else {
eprintln!(
"not writing file {}",
format_args!("{}/{}", dir.display(), file_path.to_str().unwrap())
);
}
}
})
}
Expand Down

0 comments on commit f3a50c7

Please sign in to comment.