@matheusbsbs / matheus-bagliano / commits / 8295ed690b
Fork 0

rebase: make the backend configurable via config setting

Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Feb 15, 2020 at 21:36 UTC 8295ed690bf1d458f80cffdc17d663eb3ba5162a
2 files changed +32 -7
Documentation/config/rebase.txt
+8
@@ -5,6 +5,14 @@ rebase.useBuiltin::
5 is always used. Setting this will emit a warning, to alert any
6 remaining users that setting this now does nothing.
7
8 +rebase.backend::
9 + Default backend to use for rebasing. Possible choices are
10 + 'am' or 'merge' (note that the merge backend is sometimes also
11 + refered to as the interactive backend or the interactive
12 + machinery elsewhere in the docs). Also, in the future, if the
13 + merge backend gains all remaining capabilities of the am
14 + backend, this setting may become unused.
15 +
16 rebase.stat::
17 Whether to show a diffstat of what changed upstream since the last
18 rebase. False by default.
builtin/rebase.c
+24 -7
@@ -60,6 +60,7 @@ enum empty_type {
60 struct rebase_options {
61 enum rebase_type type;
62 enum empty_type empty;
63 + const char *default_backend;
64 const char *state_dir;
65 struct commit *upstream;
66 const char *upstream_name;
@@ -100,6 +101,7 @@ struct rebase_options {
101 #define REBASE_OPTIONS_INIT { \
102 .type = REBASE_UNSPECIFIED, \
103 .empty = EMPTY_UNSPECIFIED, \
104 + .default_backend = "am", \
105 .flags = REBASE_NO_QUIET, \
106 .git_am_opts = ARGV_ARRAY_INIT, \
107 .git_format_patch_opt = STRBUF_INIT \
@@ -1272,6 +1274,10 @@ static int rebase_config(const char *var, const char *value, void *data)
1274 return 0;
1275 }
1276
1277 + if (!strcmp(var, "rebase.backend")) {
1278 + return git_config_string(&opts->default_backend, var, value);
1279 + }
1280 +
1281 return git_default_config(var, value, data);
1282 }
1283
@@ -1900,9 +1906,23 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1906 if (strcmp(options.git_am_opts.argv[i], "-q"))
1907 break;
1908
1903 - if (is_interactive(&options) && i >= 0)
1904 - die(_("cannot combine am options with either "
1905 - "interactive or merge options"));
1909 + if (i >= 0) {
1910 + if (is_interactive(&options))
1911 + die(_("cannot combine am options with either "
1912 + "interactive or merge options"));
1913 + else
1914 + options.type = REBASE_AM;
1915 + }
1916 + }
1917 +
1918 + if (options.type == REBASE_UNSPECIFIED) {
1919 + if (!strcmp(options.default_backend, "merge"))
1920 + options.type = REBASE_MERGE;
1921 + else if (!strcmp(options.default_backend, "am"))
1922 + options.type = REBASE_AM;
1923 + else
1924 + die(_("Unknown rebase backend: %s"),
1925 + options.default_backend);
1926 }
1927
1928 switch (options.type) {
@@ -1915,10 +1935,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1935 options.state_dir = apply_dir();
1936 break;
1937 default:
1918 - /* the default rebase backend is `--am` */
1919 - options.type = REBASE_AM;
1920 - options.state_dir = apply_dir();
1921 - break;
1938 + BUG("options.type was just set above; should be unreachable.");
1939 }
1940
1941 if (options.empty == EMPTY_UNSPECIFIED) {