Skip to content

Commit 7610fa5

Browse files
jrngitster
authored andcommitted
merge-recursive --renormalize
Teach "git merge-recursive" a --renormalize option to enable the merge.renormalize configuration. The --no-renormalize option can be used to override it in the negative. So in the future, you might be able to, e.g.: git checkout -m -Xrenormalize otherbranch or git revert -Xrenormalize otherpatch or git pull --rebase -Xrenormalize The bad part: merge.renormalize is still not honored for most commands. And it reveals lots of places that -X has not been plumbed in (so we get "git merge -Xrenormalize" but not much else). NEEDSWORK: tests Cc: Eyvind Bernhardsen <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ff8ba59 commit 7610fa5

File tree

8 files changed

+45
-8
lines changed

8 files changed

+45
-8
lines changed

Documentation/merge-strategies.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ the other tree did, declaring 'our' history contains all that happened in it.
4040
theirs;;
4141
This is opposite of 'ours'.
4242

43+
renormalize;;
44+
This runs a virtual check-out and check-in of all three stages
45+
of a file when resolving a three-way merge. This option is
46+
meant to be used when merging branches with different clean
47+
filters or end-of-line normalization rules. See "Merging
48+
branches with differing checkin/checkout attributes" in
49+
linkgit:gitattributes[5] for details.
50+
51+
no-renormalize;;
52+
Disables the `renormalize` option. This overrides the
53+
`merge.renormalize` configuration variable.
54+
4355
subtree[=path];;
4456
This option is a more advanced form of 'subtree' strategy, where
4557
the strategy makes a guess on how two trees must be shifted to

builtin/checkout.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,13 @@ static int merge_working_tree(struct checkout_opts *opts,
437437
*/
438438

439439
add_files_to_cache(NULL, NULL, 0);
440+
/*
441+
* NEEDSWORK: carrying over local changes
442+
* when branches have different end-of-line
443+
* normalization (or clean+smudge rules) is
444+
* a pain; plumb in an option to set
445+
* o.renormalize?
446+
*/
440447
init_merge_options(&o);
441448
o.verbosity = 0;
442449
work = write_tree_from_memory(&o);

builtin/merge-recursive.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
4545
o.subtree_shift = "";
4646
else if (!prefixcmp(arg+2, "subtree="))
4747
o.subtree_shift = arg + 10;
48+
else if (!strcmp(arg+2, "renormalize"))
49+
o.renormalize = 1;
50+
else if (!strcmp(arg+2, "no-renormalize"))
51+
o.renormalize = 0;
4852
else
4953
die("Unknown option %s", arg);
5054
continue;

builtin/merge.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ static size_t use_strategies_nr, use_strategies_alloc;
5454
static const char **xopts;
5555
static size_t xopts_nr, xopts_alloc;
5656
static const char *branch;
57+
static int option_renormalize;
5758
static int verbosity;
5859
static int allow_rerere_auto;
5960

@@ -503,9 +504,8 @@ static int git_merge_config(const char *k, const char *v, void *cb)
503504
return git_config_string(&pull_octopus, k, v);
504505
else if (!strcmp(k, "merge.log") || !strcmp(k, "merge.summary"))
505506
option_log = git_config_bool(k, v);
506-
else if (!strcmp(k, "merge.renormalize")) {
507-
merge_renormalize = git_config_bool(k, v);
508-
}
507+
else if (!strcmp(k, "merge.renormalize"))
508+
option_renormalize = git_config_bool(k, v);
509509
return git_diff_ui_config(k, v, cb);
510510
}
511511

@@ -627,6 +627,11 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
627627
if (!strcmp(strategy, "subtree"))
628628
o.subtree_shift = "";
629629

630+
o.renormalize = option_renormalize;
631+
632+
/*
633+
* NEEDSWORK: merge with table in builtin/merge-recursive
634+
*/
630635
for (x = 0; x < xopts_nr; x++) {
631636
if (!strcmp(xopts[x], "ours"))
632637
o.recursive_variant = MERGE_RECURSIVE_OURS;
@@ -636,6 +641,10 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
636641
o.subtree_shift = "";
637642
else if (!prefixcmp(xopts[x], "subtree="))
638643
o.subtree_shift = xopts[x]+8;
644+
else if (!strcmp(xopts[x], "renormalize"))
645+
o.renormalize = 1;
646+
else if (!strcmp(xopts[x], "no-renormalize"))
647+
o.renormalize = 0;
639648
else
640649
die("Unknown option for merge-recursive: -X%s", xopts[x]);
641650
}
@@ -819,7 +828,7 @@ static int finish_automerge(struct commit_list *common,
819828
return 0;
820829
}
821830

822-
static int suggest_conflicts(void)
831+
static int suggest_conflicts(int renormalizing)
823832
{
824833
FILE *fp;
825834
int pos;
@@ -1304,5 +1313,5 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
13041313
"stopped before committing as requested\n");
13051314
return 0;
13061315
} else
1307-
return suggest_conflicts();
1316+
return suggest_conflicts(option_renormalize);
13081317
}

builtin/revert.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,13 @@ static void do_recursive_merge(struct commit *base, struct commit *next,
318318
index_fd = hold_locked_index(&index_lock, 1);
319319

320320
read_cache();
321+
322+
/*
323+
* NEEDSWORK: cherry-picking between branches with
324+
* different end-of-line normalization is a pain;
325+
* plumb in an option to set o.renormalize?
326+
* (or better: arbitrary -X options)
327+
*/
321328
init_merge_options(&o);
322329
o.ancestor = base ? base_label : "(empty tree)";
323330
o.branch1 = "HEAD";

cache.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,6 @@ extern int read_replace_refs;
551551
extern int fsync_object_files;
552552
extern int core_preload_index;
553553
extern int core_apply_sparse_checkout;
554-
extern int merge_renormalize;
555554

556555
enum safe_crlf {
557556
SAFE_CRLF_FALSE = 0,

environment.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
5353
char *notes_ref_name;
5454
int grafts_replace_parents = 1;
5555
int core_apply_sparse_checkout;
56-
int merge_renormalize;
5756

5857
/* Parallel index stat data preload? */
5958
int core_preload_index = 0;

merge-recursive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,7 @@ void init_merge_options(struct merge_options *o)
14861486
o->buffer_output = 1;
14871487
o->diff_rename_limit = -1;
14881488
o->merge_rename_limit = -1;
1489-
o->renormalize = merge_renormalize;
1489+
o->renormalize = 0;
14901490
git_config(merge_recursive_config, o);
14911491
if (getenv("GIT_MERGE_VERBOSITY"))
14921492
o->verbosity =

0 commit comments

Comments
 (0)