builtin rebase: support `-C` and `--whitespace=<type>`

This commit converts more code from the shell script version to the builtin rebase. In this instance, we just have to be careful to keep support for passing multiple `--whitespace` options, as the shell script version does so, too. Signed-off-by: Pratik Karki <predatoramigo@gmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pratik Karki committed Sep 4, 2018 at 15:00 UTC 7998dbe1ec40faffb429386d1c0971d4350a97eb
1 file changed +23
builtin/rebase.c
+23
@@ -574,6 +574,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
574 int ignore_date = 0;
575 int ignore_whitespace = 0;
576 const char *gpg_sign = NULL;
577 + int opt_c = -1;
578 + struct string_list whitespace = STRING_LIST_INIT_NODUP;
579 struct option builtin_rebase_options[] = {
580 OPT_STRING(0, "onto", &options.onto_name,
581 N_("revision"),
@@ -641,6 +643,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
643 { OPTION_STRING, 'S', "gpg-sign", &gpg_sign, N_("key-id"),
644 N_("GPG-sign commits"),
645 PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
646 + OPT_STRING_LIST(0, "whitespace", &whitespace,
647 + N_("whitespace"), N_("passed to 'git apply'")),
648 + OPT_SET_INT('C', NULL, &opt_c, N_("passed to 'git apply'"),
649 + REBASE_AM),
650 OPT_END(),
651 };
652
@@ -848,6 +854,23 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
854 options.gpg_sign_opt = xstrfmt("-S%s", gpg_sign);
855 }
856
857 + if (opt_c >= 0)
858 + strbuf_addf(&options.git_am_opt, " -C%d", opt_c);
859 +
860 + if (whitespace.nr) {
861 + int i;
862 +
863 + for (i = 0; i < whitespace.nr; i++) {
864 + const char *item = whitespace.items[i].string;
865 +
866 + strbuf_addf(&options.git_am_opt, " --whitespace=%s",
867 + item);
868 +
869 + if ((!strcmp(item, "fix")) || (!strcmp(item, "strip")))
870 + options.flags |= REBASE_FORCE;
871 + }
872 + }
873 +
874 switch (options.type) {
875 case REBASE_MERGE:
876 case REBASE_INTERACTIVE: