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 <eyvind.bernhardsen@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Aug 5, 2010 at 06:32 UTC
7610fa57e63b0acc0a66717fc2d85755634db591
8 files changed
+45
-8
Documentation/merge-strategies.txt
+12
@@ -40,6 +40,18 @@ the other tree did, declaring 'our' history contains all that happened in it.
40
theirs;;
41
This is opposite of 'ours'.
42
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
+
55
subtree[=path];;
56
This option is a more advanced form of 'subtree' strategy, where
57
the strategy makes a guess on how two trees must be shifted to
builtin/checkout.c
+7
@@ -437,6 +437,13 @@ static int merge_working_tree(struct checkout_opts *opts,
437
*/
438
439
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
+ */
447
init_merge_options(&o);
448
o.verbosity = 0;
449
work = write_tree_from_memory(&o);
builtin/merge-recursive.c
+4
@@ -45,6 +45,10 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
45
o.subtree_shift = "";
46
else if (!prefixcmp(arg+2, "subtree="))
47
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;
52
else
53
die("Unknown option %s", arg);
54
continue;
builtin/merge.c
+14
-5
@@ -54,6 +54,7 @@ static size_t use_strategies_nr, use_strategies_alloc;
54
static const char **xopts;
55
static size_t xopts_nr, xopts_alloc;
56
static const char *branch;
57
+static int option_renormalize;
58
static int verbosity;
59
static int allow_rerere_auto;
60
@@ -503,9 +504,8 @@ static int git_merge_config(const char *k, const char *v, void *cb)
504
return git_config_string(&pull_octopus, k, v);
505
else if (!strcmp(k, "merge.log") || !strcmp(k, "merge.summary"))
506
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);
509
return git_diff_ui_config(k, v, cb);
510
}
511
@@ -627,6 +627,11 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
627
if (!strcmp(strategy, "subtree"))
628
o.subtree_shift = "";
629
630
+ o.renormalize = option_renormalize;
631
+
632
+ /*
633
+ * NEEDSWORK: merge with table in builtin/merge-recursive
634
+ */
635
for (x = 0; x < xopts_nr; x++) {
636
if (!strcmp(xopts[x], "ours"))
637
o.recursive_variant = MERGE_RECURSIVE_OURS;
@@ -636,6 +641,10 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
641
o.subtree_shift = "";
642
else if (!prefixcmp(xopts[x], "subtree="))
643
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;
648
else
649
die("Unknown option for merge-recursive: -X%s", xopts[x]);
650
}
@@ -819,7 +828,7 @@ static int finish_automerge(struct commit_list *common,
828
return 0;
829
}
830
822
-static int suggest_conflicts(void)
831
+static int suggest_conflicts(int renormalizing)
832
{
833
FILE *fp;
834
int pos;
@@ -1304,5 +1313,5 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1313
"stopped before committing as requested\n");
1314
return 0;
1315
} else
1307
- return suggest_conflicts();
1316
+ return suggest_conflicts(option_renormalize);
1317
}
builtin/revert.c
+7
@@ -318,6 +318,13 @@ static void do_recursive_merge(struct commit *base, struct commit *next,
318
index_fd = hold_locked_index(&index_lock, 1);
319
320
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
+ */
328
init_merge_options(&o);
329
o.ancestor = base ? base_label : "(empty tree)";
330
o.branch1 = "HEAD";
cache.h
-1
@@ -551,7 +551,6 @@ extern int read_replace_refs;
551
extern int fsync_object_files;
552
extern int core_preload_index;
553
extern int core_apply_sparse_checkout;
554
-extern int merge_renormalize;
554
555
enum safe_crlf {
556
SAFE_CRLF_FALSE = 0,
environment.c
-1
@@ -53,7 +53,6 @@ enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
53
char *notes_ref_name;
54
int grafts_replace_parents = 1;
55
int core_apply_sparse_checkout;
56
-int merge_renormalize;
56
57
/* Parallel index stat data preload? */
58
int core_preload_index = 0;
merge-recursive.c
+1
-1
@@ -1486,7 +1486,7 @@ void init_merge_options(struct merge_options *o)
1486
o->buffer_output = 1;
1487
o->diff_rename_limit = -1;
1488
o->merge_rename_limit = -1;
1489
- o->renormalize = merge_renormalize;
1489
+ o->renormalize = 0;
1490
git_config(merge_recursive_config, o);
1491
if (getenv("GIT_MERGE_VERBOSITY"))
1492
o->verbosity =