@matheusbsbs / matheus-bagliano / commits / 88f8576eda
Fork 0

pull --rebase/remote rename: document and honor single-letter abbreviations rebase types

When 46af44b07d (pull --rebase=<type>: allow single-letter abbreviations for the type, 2018-08-04) landed in Git, it had the side effect that not only 'pull --rebase=<type>' accepted the single-letter abbreviations but also the 'pull.rebase' and 'branch.<name>.rebase' configurations. However, 'git remote rename' did not honor these single-letter abbreviations when reading the 'branch.*.rebase' configurations. We now document the single-letter abbreviations and both code places share a common function to parse the values of 'git pull --rebase=*', 'pull.rebase', and 'branches.*.rebase'. The only functional change is the handling of the `branch_info::rebase` value. Before it was an unsigned enum, thus the truth value could be checked with `branch_info::rebase != 0`. But `enum rebase_type` is signed, thus the truth value must now be checked with `branch_info::rebase >= REBASE_TRUE` Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Bert Wesarg committed Jan 27, 2020 at 08:04 UTC 88f8576eda2880587fb4487ba469d909dbe35a7b
7 files changed +75 -49
Documentation/config/branch.txt
+4 -3
@@ -81,15 +81,16 @@ branch.<name>.rebase::
81 "git pull" is run. See "pull.rebase" for doing this in a non
82 branch-specific manner.
83 +
84 -When `merges`, pass the `--rebase-merges` option to 'git rebase'
84 +When `merges` (or just 'm'), pass the `--rebase-merges` option to 'git rebase'
85 so that the local merge commits are included in the rebase (see
86 linkgit:git-rebase[1] for details).
87 +
88 -When `preserve` (deprecated in favor of `merges`), also pass
88 +When `preserve` (or just 'p', deprecated in favor of `merges`), also pass
89 `--preserve-merges` along to 'git rebase' so that locally committed merge
90 commits will not be flattened by running 'git pull'.
91 +
92 -When the value is `interactive`, the rebase is run in interactive mode.
92 +When the value is `interactive` (or just 'i'), the rebase is run in interactive
93 +mode.
94 +
95 *NOTE*: this is a possibly dangerous operation; do *not* use
96 it unless you understand the implications (see linkgit:git-rebase[1]
Documentation/config/pull.txt
+4 -3
@@ -14,15 +14,16 @@ pull.rebase::
14 pull" is run. See "branch.<name>.rebase" for setting this on a
15 per-branch basis.
16 +
17 -When `merges`, pass the `--rebase-merges` option to 'git rebase'
17 +When `merges` (or just 'm'), pass the `--rebase-merges` option to 'git rebase'
18 so that the local merge commits are included in the rebase (see
19 linkgit:git-rebase[1] for details).
20 +
21 -When `preserve` (deprecated in favor of `merges`), also pass
21 +When `preserve` (or just 'p', deprecated in favor of `merges`), also pass
22 `--preserve-merges` along to 'git rebase' so that locally committed merge
23 commits will not be flattened by running 'git pull'.
24 +
25 -When the value is `interactive`, the rebase is run in interactive mode.
25 +When the value is `interactive` (or just 'i'), the rebase is run in interactive
26 +mode.
27 +
28 *NOTE*: this is a possibly dangerous operation; do *not* use
29 it unless you understand the implications (see linkgit:git-rebase[1]
Makefile
+1
@@ -954,6 +954,7 @@ LIB_OBJS += quote.o
954 LIB_OBJS += range-diff.o
955 LIB_OBJS += reachable.o
956 LIB_OBJS += read-cache.o
957 +LIB_OBJS += rebase.o
958 LIB_OBJS += rebase-interactive.o
959 LIB_OBJS += reflog-walk.o
960 LIB_OBJS += refs.o
builtin/pull.c
+4 -25
@@ -15,6 +15,7 @@
15 #include "sha1-array.h"
16 #include "remote.h"
17 #include "dir.h"
18 +#include "rebase.h"
19 #include "refs.h"
20 #include "refspec.h"
21 #include "revision.h"
@@ -26,15 +27,6 @@
27 #include "commit-reach.h"
28 #include "sequencer.h"
29
29 -enum rebase_type {
30 - REBASE_INVALID = -1,
31 - REBASE_FALSE = 0,
32 - REBASE_TRUE,
33 - REBASE_PRESERVE,
34 - REBASE_MERGES,
35 - REBASE_INTERACTIVE
36 -};
37 -
30 /**
31 * Parses the value of --rebase. If value is a false value, returns
32 * REBASE_FALSE. If value is a true value, returns REBASE_TRUE. If value is
@@ -45,22 +37,9 @@ enum rebase_type {
37 static enum rebase_type parse_config_rebase(const char *key, const char *value,
38 int fatal)
39 {
48 - int v = git_parse_maybe_bool(value);
49 -
50 - if (!v)
51 - return REBASE_FALSE;
52 - else if (v > 0)
53 - return REBASE_TRUE;
54 - else if (!strcmp(value, "preserve") || !strcmp(value, "p"))
55 - return REBASE_PRESERVE;
56 - else if (!strcmp(value, "merges") || !strcmp(value, "m"))
57 - return REBASE_MERGES;
58 - else if (!strcmp(value, "interactive") || !strcmp(value, "i"))
59 - return REBASE_INTERACTIVE;
60 - /*
61 - * Please update _git_config() in git-completion.bash when you
62 - * add new rebase modes.
63 - */
40 + enum rebase_type v = rebase_parse_value(value);
41 + if (v != REBASE_INVALID)
42 + return v;
43
44 if (fatal)
45 die(_("Invalid value for %s: %s"), key, value);
builtin/remote.c
+12 -18
@@ -6,6 +6,7 @@
6 #include "string-list.h"
7 #include "strbuf.h"
8 #include "run-command.h"
9 +#include "rebase.h"
10 #include "refs.h"
11 #include "refspec.h"
12 #include "object-store.h"
@@ -248,9 +249,7 @@ static int add(int argc, const char **argv)
249 struct branch_info {
250 char *remote_name;
251 struct string_list merge;
251 - enum {
252 - NO_REBASE, NORMAL_REBASE, INTERACTIVE_REBASE, REBASE_MERGES
253 - } rebase;
252 + enum rebase_type rebase;
253 };
254
255 static struct string_list branch_list = STRING_LIST_INIT_NODUP;
@@ -305,17 +304,12 @@ static int config_read_branches(const char *key, const char *value, void *cb)
304 space = strchr(value, ' ');
305 }
306 string_list_append(&info->merge, xstrdup(value));
308 - } else {
309 - int v = git_parse_maybe_bool(value);
310 - if (v >= 0)
311 - info->rebase = v;
312 - else if (!strcmp(value, "preserve"))
313 - info->rebase = NORMAL_REBASE;
314 - else if (!strcmp(value, "merges"))
315 - info->rebase = REBASE_MERGES;
316 - else if (!strcmp(value, "interactive"))
317 - info->rebase = INTERACTIVE_REBASE;
318 - }
307 + } else
308 + /*
309 + * Consider invalid values as false and check the
310 + * truth value with >= REBASE_TRUE.
311 + */
312 + info->rebase = rebase_parse_value(value);
313 }
314 return 0;
315 }
@@ -943,7 +937,7 @@ static int add_local_to_show_info(struct string_list_item *branch_item, void *cb
937 return 0;
938 if ((n = strlen(branch_item->string)) > show_info->width)
939 show_info->width = n;
946 - if (branch_info->rebase)
940 + if (branch_info->rebase >= REBASE_TRUE)
941 show_info->any_rebase = 1;
942
943 item = string_list_insert(show_info->list, branch_item->string);
@@ -960,16 +954,16 @@ static int show_local_info_item(struct string_list_item *item, void *cb_data)
954 int width = show_info->width + 4;
955 int i;
956
963 - if (branch_info->rebase && branch_info->merge.nr > 1) {
957 + if (branch_info->rebase >= REBASE_TRUE && branch_info->merge.nr > 1) {
958 error(_("invalid branch.%s.merge; cannot rebase onto > 1 branch"),
959 item->string);
960 return 0;
961 }
962
963 printf(" %-*s ", show_info->width, item->string);
970 - if (branch_info->rebase) {
964 + if (branch_info->rebase >= REBASE_TRUE) {
965 const char *msg;
972 - if (branch_info->rebase == INTERACTIVE_REBASE)
966 + if (branch_info->rebase == REBASE_INTERACTIVE)
967 msg = _("rebases interactively onto remote %s");
968 else if (branch_info->rebase == REBASE_MERGES)
969 msg = _("rebases interactively (with merges) onto "
rebase.c new
+35
@@ -0,0 +1,35 @@
1 +#include "rebase.h"
2 +#include "config.h"
3 +
4 +/*
5 + * Parses textual value for pull.rebase, branch.<name>.rebase, etc.
6 + * Unrecognised value yields REBASE_INVALID, which traditionally is
7 + * treated the same way as REBASE_FALSE.
8 + *
9 + * The callers that care if (any) rebase is requested should say
10 + * if (REBASE_TRUE <= rebase_parse_value(string))
11 + *
12 + * The callers that want to differenciate an unrecognised value and
13 + * false can do so by treating _INVALID and _FALSE differently.
14 + */
15 +enum rebase_type rebase_parse_value(const char *value)
16 +{
17 + int v = git_parse_maybe_bool(value);
18 +
19 + if (!v)
20 + return REBASE_FALSE;
21 + else if (v > 0)
22 + return REBASE_TRUE;
23 + else if (!strcmp(value, "preserve") || !strcmp(value, "p"))
24 + return REBASE_PRESERVE;
25 + else if (!strcmp(value, "merges") || !strcmp(value, "m"))
26 + return REBASE_MERGES;
27 + else if (!strcmp(value, "interactive") || !strcmp(value, "i"))
28 + return REBASE_INTERACTIVE;
29 + /*
30 + * Please update _git_config() in git-completion.bash when you
31 + * add new rebase modes.
32 + */
33 +
34 + return REBASE_INVALID;
35 +}
rebase.h new
+15
@@ -0,0 +1,15 @@
1 +#ifndef REBASE_H
2 +#define REBASE_H
3 +
4 +enum rebase_type {
5 + REBASE_INVALID = -1,
6 + REBASE_FALSE = 0,
7 + REBASE_TRUE,
8 + REBASE_PRESERVE,
9 + REBASE_MERGES,
10 + REBASE_INTERACTIVE
11 +};
12 +
13 +enum rebase_type rebase_parse_value(const char *value);
14 +
15 +#endif /* REBASE */