From: Pratik Karki <predatoramigo@gmail.com>
To: git@vger.kernel.org
Cc: christian.couder@gmail.com, Johannes.Schindelin@gmx.de,
sbeller@google.com, alban.gruin@gmail.com, gitster@pobox.com,
Pratik Karki <predatoramigo@gmail.com>
Subject: [PATCH 17/18] builtin rebase: add support for custom merge strategies
Date: Wed, 8 Aug 2018 21:06:39 +0545 [thread overview]
Message-ID: <20180808152140.14585-18-predatoramigo@gmail.com> (raw)
In-Reply-To: <20180808152140.14585-1-predatoramigo@gmail.com>
When running a rebase in non-am mode, it uses the recursive merge to
cherry-pick the commits, and the rebase command allows to configure
the merge strategy to be used in this operation.
This commit adds that support to the builtin rebase.
Signed-off-by: Pratik Karki <predatoramigo@gmail.com>
---
builtin/rebase.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/builtin/rebase.c b/builtin/rebase.c
index 72e64868b2..65e7be1c48 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -96,6 +96,7 @@ struct rebase_options {
char *cmd;
int allow_empty_message;
int rebase_merges, rebase_cousins;
+ char *strategy, *strategy_opts;
};
static int is_interactive(struct rebase_options *opts)
@@ -217,6 +218,22 @@ static int read_basic_state(struct rebase_options *opts)
opts->gpg_sign_opt = xstrdup(buf.buf);
}
+ if (file_exists(state_dir_path("strategy", opts))) {
+ strbuf_reset(&buf);
+ if (read_one(state_dir_path("strategy", opts), &buf))
+ return -1;
+ free(opts->strategy);
+ opts->strategy = xstrdup(buf.buf);
+ }
+
+ if (file_exists(state_dir_path("strategy_opts", opts))) {
+ strbuf_reset(&buf);
+ if (read_one(state_dir_path("strategy_opts", opts), &buf))
+ return -1;
+ free(opts->strategy_opts);
+ opts->strategy_opts = xstrdup(buf.buf);
+ }
+
strbuf_release(&buf);
return 0;
@@ -356,6 +373,8 @@ static int run_specific_rebase(struct rebase_options *opts)
opts->rebase_merges ? "t" : "");
add_var(&script_snippet, "rebase_cousins",
opts->rebase_cousins ? "t" : "");
+ add_var(&script_snippet, "strategy", opts->strategy);
+ add_var(&script_snippet, "strategy_opts", opts->strategy_opts);
switch (opts->type) {
case REBASE_AM:
@@ -633,6 +652,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
struct string_list exec = STRING_LIST_INIT_NODUP;
const char *rebase_merges = NULL;
int fork_point = -1;
+ struct string_list strategy_options = STRING_LIST_INIT_NODUP;
struct option builtin_rebase_options[] = {
OPT_STRING(0, "onto", &options.onto_name,
N_("revision"),
@@ -717,6 +737,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
PARSE_OPT_OPTARG, NULL, (intptr_t)""},
OPT_BOOL(0, "fork-point", &fork_point,
N_("use 'merge-base --fork-point' to refine upstream")),
+ OPT_STRING('s', "strategy", &options.strategy,
+ N_("strategy"), N_("use the given merge strategy")),
+ OPT_STRING_LIST('X', "strategy-option", &strategy_options,
+ N_("option"),
+ N_("pass the argument through to the merge "
+ "strategy")),
OPT_END(),
};
@@ -963,6 +989,37 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
imply_interactive(&options, "--rebase-merges");
}
+ if (strategy_options.nr) {
+ int i;
+
+ if (!options.strategy)
+ options.strategy = "recursive";
+
+ strbuf_reset(&buf);
+ for (i = 0; i < strategy_options.nr; i++)
+ strbuf_addf(&buf, " --%s",
+ strategy_options.items[i].string);
+ options.strategy_opts = xstrdup(buf.buf);
+ }
+
+ if (options.strategy) {
+ options.strategy = xstrdup(options.strategy);
+ switch (options.type) {
+ case REBASE_AM:
+ die(_("--strategy requires --merge or --interactive"));
+ case REBASE_MERGE:
+ case REBASE_INTERACTIVE:
+ case REBASE_PRESERVE_MERGES:
+ /* compatible */
+ break;
+ case REBASE_UNSPECIFIED:
+ options.type = REBASE_MERGE;
+ break;
+ default:
+ BUG("unhandled rebase type (%d)", options.type);
+ }
+ }
+
switch (options.type) {
case REBASE_MERGE:
case REBASE_INTERACTIVE:
--
2.18.0
next prev parent reply other threads:[~2018-08-08 15:23 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-08 15:21 [GSoC] [PATCH 00/18] builtin rebase options Pratik Karki
2018-08-08 15:21 ` [PATCH 01/18] builtin rebase: allow selecting the rebase "backend" Pratik Karki
2018-08-08 15:21 ` [PATCH 02/18] builtin rebase: support --signoff Pratik Karki
2018-08-08 15:21 ` [PATCH 03/18] builtin rebase: support --rerere-autoupdate Pratik Karki
2018-08-08 15:21 ` [PATCH 04/18] builtin rebase: support --committer-date-is-author-date Pratik Karki
2018-08-08 15:21 ` [PATCH 05/18] builtin rebase: support `ignore-whitespace` option Pratik Karki
2018-08-08 15:21 ` [PATCH 06/18] builtin rebase: support `ignore-date` option Pratik Karki
2018-08-08 15:21 ` [PATCH 07/18] builtin rebase: support `keep-empty` option Pratik Karki
2018-08-24 16:04 ` Johannes Schindelin
2018-08-08 15:21 ` [PATCH 08/18] builtin rebase: support `--autosquash` Pratik Karki
2018-08-08 15:21 ` [PATCH 09/18] builtin rebase: support `--gpg-sign` option Pratik Karki
2018-08-08 15:21 ` [PATCH 10/18] builtin rebase: support `-C` and `--whitespace=<type>` Pratik Karki
2018-08-08 15:21 ` [PATCH 11/18] builtin rebase: support `--autostash` option Pratik Karki
2018-08-18 15:59 ` Duy Nguyen
2018-08-24 16:06 ` Johannes Schindelin
2018-08-08 15:21 ` [PATCH 12/18] builtin rebase: support `--exec` Pratik Karki
2018-08-08 15:21 ` [PATCH 13/18] builtin rebase: support `--allow-empty-message` option Pratik Karki
2018-08-08 15:21 ` [PATCH 14/18] builtin rebase: support --rebase-merges[=[no-]rebase-cousins] Pratik Karki
2018-08-08 15:21 ` [PATCH 15/18] merge-base --fork-point: extract libified function Pratik Karki
2018-08-08 15:21 ` [PATCH 16/18] builtin rebase: support `fork-point` option Pratik Karki
2018-08-08 15:21 ` Pratik Karki [this message]
2018-08-08 15:21 ` [PATCH 18/18] builtin rebase: support --root Pratik Karki
2018-09-04 21:59 ` [PATCH v2 00/18] builtin rebase options Johannes Schindelin via GitGitGadget
2018-09-04 21:59 ` [PATCH v2 01/18] builtin rebase: allow selecting the rebase "backend" Pratik Karki via GitGitGadget
2018-09-04 21:59 ` [PATCH v2 02/18] builtin rebase: support --signoff Pratik Karki via GitGitGadget
2018-09-04 21:59 ` [PATCH v2 03/18] builtin rebase: support --rerere-autoupdate Pratik Karki via GitGitGadget
2018-09-04 21:59 ` [PATCH v2 04/18] builtin rebase: support --committer-date-is-author-date Pratik Karki via GitGitGadget
2018-09-04 21:59 ` [PATCH v2 05/18] builtin rebase: support `ignore-whitespace` option Pratik Karki via GitGitGadget
2018-09-04 21:59 ` [PATCH v2 06/18] builtin rebase: support `ignore-date` option Pratik Karki via GitGitGadget
2018-09-04 21:59 ` [PATCH v2 07/18] builtin rebase: support `keep-empty` option Pratik Karki via GitGitGadget
2018-09-04 21:59 ` [PATCH v2 08/18] builtin rebase: support `--autosquash` Pratik Karki via GitGitGadget
2018-09-04 22:00 ` [PATCH v2 09/18] builtin rebase: support `--gpg-sign` option Pratik Karki via GitGitGadget
2018-09-04 22:00 ` [PATCH v2 10/18] builtin rebase: support `-C` and `--whitespace=<type>` Pratik Karki via GitGitGadget
2018-09-04 22:00 ` [PATCH v2 11/18] builtin rebase: support `--autostash` option Pratik Karki via GitGitGadget
2018-09-04 22:00 ` [PATCH v2 12/18] builtin rebase: support `--exec` Pratik Karki via GitGitGadget
2018-09-04 22:00 ` [PATCH v2 13/18] builtin rebase: support `--allow-empty-message` option Pratik Karki via GitGitGadget
2018-09-04 22:00 ` [PATCH v2 14/18] builtin rebase: support --rebase-merges[=[no-]rebase-cousins] Pratik Karki via GitGitGadget
2018-09-04 22:00 ` [PATCH v2 15/18] merge-base --fork-point: extract libified function Pratik Karki via GitGitGadget
2018-09-04 22:00 ` [PATCH v2 16/18] builtin rebase: support `fork-point` option Pratik Karki via GitGitGadget
2018-09-04 22:00 ` [PATCH v2 17/18] builtin rebase: add support for custom merge strategies Pratik Karki via GitGitGadget
2018-09-04 22:00 ` [PATCH v2 18/18] builtin rebase: support --root Pratik Karki via GitGitGadget
2018-09-06 19:50 ` [PATCH v2 00/18] builtin rebase options Junio C Hamano
2018-09-06 20:38 ` Junio C Hamano
2018-10-12 12:01 ` Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180808152140.14585-18-predatoramigo@gmail.com \
--to=predatoramigo@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=alban.gruin@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=sbeller@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).