Skip to content

Commit 88f8576

Browse files
bertwesarggitster
authored andcommitted
pull --rebase/remote rename: document and honor single-letter abbreviations rebase types
When 46af44b (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 145d59f commit 88f8576

File tree

7 files changed

+75
-49
lines changed

7 files changed

+75
-49
lines changed

Documentation/config/branch.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,16 @@ branch.<name>.rebase::
8181
"git pull" is run. See "pull.rebase" for doing this in a non
8282
branch-specific manner.
8383
+
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'
8585
so that the local merge commits are included in the rebase (see
8686
linkgit:git-rebase[1] for details).
8787
+
88-
When `preserve` (deprecated in favor of `merges`), also pass
88+
When `preserve` (or just 'p', deprecated in favor of `merges`), also pass
8989
`--preserve-merges` along to 'git rebase' so that locally committed merge
9090
commits will not be flattened by running 'git pull'.
9191
+
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.
9394
+
9495
*NOTE*: this is a possibly dangerous operation; do *not* use
9596
it unless you understand the implications (see linkgit:git-rebase[1]

Documentation/config/pull.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ pull.rebase::
1414
pull" is run. See "branch.<name>.rebase" for setting this on a
1515
per-branch basis.
1616
+
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'
1818
so that the local merge commits are included in the rebase (see
1919
linkgit:git-rebase[1] for details).
2020
+
21-
When `preserve` (deprecated in favor of `merges`), also pass
21+
When `preserve` (or just 'p', deprecated in favor of `merges`), also pass
2222
`--preserve-merges` along to 'git rebase' so that locally committed merge
2323
commits will not be flattened by running 'git pull'.
2424
+
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.
2627
+
2728
*NOTE*: this is a possibly dangerous operation; do *not* use
2829
it unless you understand the implications (see linkgit:git-rebase[1]

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,7 @@ LIB_OBJS += quote.o
954954
LIB_OBJS += range-diff.o
955955
LIB_OBJS += reachable.o
956956
LIB_OBJS += read-cache.o
957+
LIB_OBJS += rebase.o
957958
LIB_OBJS += rebase-interactive.o
958959
LIB_OBJS += reflog-walk.o
959960
LIB_OBJS += refs.o

builtin/pull.c

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "sha1-array.h"
1616
#include "remote.h"
1717
#include "dir.h"
18+
#include "rebase.h"
1819
#include "refs.h"
1920
#include "refspec.h"
2021
#include "revision.h"
@@ -26,15 +27,6 @@
2627
#include "commit-reach.h"
2728
#include "sequencer.h"
2829

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-
3830
/**
3931
* Parses the value of --rebase. If value is a false value, returns
4032
* REBASE_FALSE. If value is a true value, returns REBASE_TRUE. If value is
@@ -45,22 +37,9 @@ enum rebase_type {
4537
static enum rebase_type parse_config_rebase(const char *key, const char *value,
4638
int fatal)
4739
{
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;
6443

6544
if (fatal)
6645
die(_("Invalid value for %s: %s"), key, value);

builtin/remote.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "string-list.h"
77
#include "strbuf.h"
88
#include "run-command.h"
9+
#include "rebase.h"
910
#include "refs.h"
1011
#include "refspec.h"
1112
#include "object-store.h"
@@ -248,9 +249,7 @@ static int add(int argc, const char **argv)
248249
struct branch_info {
249250
char *remote_name;
250251
struct string_list merge;
251-
enum {
252-
NO_REBASE, NORMAL_REBASE, INTERACTIVE_REBASE, REBASE_MERGES
253-
} rebase;
252+
enum rebase_type rebase;
254253
};
255254

256255
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)
305304
space = strchr(value, ' ');
306305
}
307306
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);
319313
}
320314
return 0;
321315
}
@@ -943,7 +937,7 @@ static int add_local_to_show_info(struct string_list_item *branch_item, void *cb
943937
return 0;
944938
if ((n = strlen(branch_item->string)) > show_info->width)
945939
show_info->width = n;
946-
if (branch_info->rebase)
940+
if (branch_info->rebase >= REBASE_TRUE)
947941
show_info->any_rebase = 1;
948942

949943
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)
960954
int width = show_info->width + 4;
961955
int i;
962956

963-
if (branch_info->rebase && branch_info->merge.nr > 1) {
957+
if (branch_info->rebase >= REBASE_TRUE && branch_info->merge.nr > 1) {
964958
error(_("invalid branch.%s.merge; cannot rebase onto > 1 branch"),
965959
item->string);
966960
return 0;
967961
}
968962

969963
printf(" %-*s ", show_info->width, item->string);
970-
if (branch_info->rebase) {
964+
if (branch_info->rebase >= REBASE_TRUE) {
971965
const char *msg;
972-
if (branch_info->rebase == INTERACTIVE_REBASE)
966+
if (branch_info->rebase == REBASE_INTERACTIVE)
973967
msg = _("rebases interactively onto remote %s");
974968
else if (branch_info->rebase == REBASE_MERGES)
975969
msg = _("rebases interactively (with merges) onto "

rebase.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 */

0 commit comments

Comments
 (0)