* Write the contents of the object named by "sha1" to the file "filename". * If "raw" is true, then the object's raw contents are printed according to * "type". Otherwise, we pretty-print the contents for human editing. */
| 231 | * "type". Otherwise, we pretty-print the contents for human editing. |
| 232 | */ |
| 233 | static int export_object(const struct object_id *oid, enum object_type type, |
| 234 | int raw, const char *filename) |
| 235 | { |
| 236 | struct child_process cmd = CHILD_PROCESS_INIT; |
| 237 | int fd; |
| 238 | |
| 239 | fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
| 240 | if (fd < 0) |
| 241 | return error_errno(_("unable to open %s for writing"), filename); |
| 242 | |
| 243 | strvec_push(&cmd.args, "--no-replace-objects"); |
| 244 | strvec_push(&cmd.args, "cat-file"); |
| 245 | if (raw) |
| 246 | strvec_push(&cmd.args, type_name(type)); |
| 247 | else |
| 248 | strvec_push(&cmd.args, "-p"); |
| 249 | strvec_push(&cmd.args, oid_to_hex(oid)); |
| 250 | cmd.git_cmd = 1; |
| 251 | cmd.out = fd; |
| 252 | |
| 253 | if (run_command(&cmd)) |
| 254 | return error(_("cat-file reported failure")); |
| 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | /* |
| 259 | * Read a previously-exported (and possibly edited) object back from "filename", |
no test coverage detected