MCPcopy Create free account
hub / github.com/git/git / export_object

Function export_object

builtin/replace.c:233–256  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

231 * "type". Otherwise, we pretty-print the contents for human editing.
232 */
233static 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",

Callers 1

edit_and_replaceFunction · 0.85

Calls 6

error_errnoFunction · 0.85
strvec_pushFunction · 0.85
type_nameFunction · 0.85
oid_to_hexFunction · 0.85
run_commandFunction · 0.85
errorFunction · 0.85

Tested by

no test coverage detected