replace: prepare create_graft() for converting graft files wholesale

When converting all grafts in a graft file to replace refs, and one of them happens to leave the original commit's parents unchanged, we do not want to error out. Instead, we would like to issue a warning. Prepare the create_graft() function for such a use case by adding a `gentle` parameter. If set, we do not return an error when the replace ref is unchanged, but a mere warning. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Apr 29, 2018 at 00:44 UTC 041c98e22d88d963a92f1bac6ab348a0d4c6d228
1 file changed +8 -3
builtin/replace.c
+8 -3
@@ -428,7 +428,7 @@ static int check_mergetags(struct commit *commit, int argc, const char **argv)
428 return for_each_mergetag(check_one_mergetag, commit, &mergetag_data);
429 }
430
431 -static int create_graft(int argc, const char **argv, int force)
431 +static int create_graft(int argc, const char **argv, int force, int gentle)
432 {
433 struct object_id old_oid, new_oid;
434 const char *old_ref = argv[0];
@@ -470,8 +470,13 @@ static int create_graft(int argc, const char **argv, int force)
470
471 strbuf_release(&buf);
472
473 - if (!oidcmp(&old_oid, &new_oid))
473 + if (!oidcmp(&old_oid, &new_oid)) {
474 + if (gentle) {
475 + warning("graft for '%s' unnecessary", oid_to_hex(&old_oid));
476 + return 0;
477 + }
478 return error("new commit is the same as the old one: '%s'", oid_to_hex(&old_oid));
479 + }
480
481 return replace_object_oid(old_ref, &old_oid, "replacement", &new_oid, force);
482 }
@@ -547,7 +552,7 @@ int cmd_replace(int argc, const char **argv, const char *prefix)
552 if (argc < 1)
553 usage_msg_opt("-g needs at least one argument",
554 git_replace_usage, options);
550 - return create_graft(argc, argv, force);
555 + return create_graft(argc, argv, force, 0);
556
557 case MODE_LIST:
558 if (argc > 1)