- * Write the contents of the object named by "sha1" to the file "filename",
- * pretty-printed for human editing based on its type.
+ * 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.
-static void export_object(const unsigned char *sha1, const char *filename)
+static void export_object(const unsigned char *sha1, enum object_type type,
+ int raw, const char *filename)
argv_array_push(&cmd.args, "--no-replace-objects");
argv_array_push(&cmd.args, "cat-file");
argv_array_push(&cmd.args, "--no-replace-objects");
argv_array_push(&cmd.args, "cat-file");
- argv_array_push(&cmd.args, "-p");
+ if (raw)
+ argv_array_push(&cmd.args, typename(type));
+ else
+ argv_array_push(&cmd.args, "-p");
* The sha1 of the written object is returned via sha1.
*/
static void import_object(unsigned char *sha1, enum object_type type,
* The sha1 of the written object is returned via sha1.
*/
static void import_object(unsigned char *sha1, enum object_type type,
const char *argv[] = { "mktree", NULL };
struct child_process cmd = { argv };
struct strbuf result = STRBUF_INIT;
const char *argv[] = { "mktree", NULL };
struct child_process cmd = { argv };
struct strbuf result = STRBUF_INIT;
check_ref_valid(old, prev, ref, sizeof(ref), force);
check_ref_valid(old, prev, ref, sizeof(ref), force);
if (launch_editor(tmpfile, NULL, NULL) < 0)
die("editing object file failed");
if (launch_editor(tmpfile, NULL, NULL) < 0)
die("editing object file failed");
OPT_CMDMODE('d', "delete", &cmdmode, N_("delete replace refs"), MODE_DELETE),
OPT_CMDMODE('e', "edit", &cmdmode, N_("edit existing object"), MODE_EDIT),
OPT_BOOL('f', "force", &force, N_("replace the ref if it exists")),
OPT_CMDMODE('d', "delete", &cmdmode, N_("delete replace refs"), MODE_DELETE),
OPT_CMDMODE('e', "edit", &cmdmode, N_("edit existing object"), MODE_EDIT),
OPT_BOOL('f', "force", &force, N_("replace the ref if it exists")),
OPT_STRING(0, "format", &format, N_("format"), N_("use this format")),
OPT_END()
};
OPT_STRING(0, "format", &format, N_("format"), N_("use this format")),
OPT_END()
};
usage_msg_opt("-f only makes sense when writing a replacement",
git_replace_usage, options);
usage_msg_opt("-f only makes sense when writing a replacement",
git_replace_usage, options);
if (argc != 1)
usage_msg_opt("-e needs exactly one argument",
git_replace_usage, options);
if (argc != 1)
usage_msg_opt("-e needs exactly one argument",
git_replace_usage, options);