[PATCH 5/6] rerere: let caller decide whether to renormalize

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a RERERE_RENORMALIZE flag to rerere so callers can decide
case-by-case whether the merge is likely to have overlapped with a
change in smudge/clean rules.

This is only a change in internal plumbing.  Many callers do not have
a way to use that setting; this patch does not change that.

NEEDSWORK: this is a step in the wrong direction.  rerere needs
an -s option to use an arbitrary merge strategy and a -X option to
pass arbitrary options to that driver.  And maybe the options used
in a merge should be recorded somewhere to help rerere repeat it.

This treats the renormalize option specially anyway, to support the
existing "git merge" behavior of using -Xrenormalize in its rerere
call when configured to do so.  It reluctant exposes that option in
the rerere command as --renormalize for the sake of experimentation,
too, but it does not advertise it.

Cc: Eyvind Bernhardsen <eyvind.bernhardsen@xxxxxxxxx>
Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
---
 builtin/commit.c |    4 ++++
 builtin/merge.c  |    7 +++++--
 builtin/rerere.c |    8 ++++++--
 builtin/revert.c |   11 +++++++++--
 rerere.c         |    5 +++--
 rerere.h         |    1 +
 6 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index 3d99cf9..56c998f 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1377,6 +1377,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		     "new_index file. Check that disk is not full or quota is\n"
 		     "not exceeded, and then \"git reset HEAD\" to recover.");
 
+	/*
+	 * NEEDSWORK: use RERERE_RENORMALIZE after a merge with
+	 * merge.renormalize set
+	 */
 	rerere(0);
 	run_hook(get_index_file(), "post-commit", NULL);
 	if (amend && !no_post_rewrite) {
diff --git a/builtin/merge.c b/builtin/merge.c
index b836e9c..823b76b 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -822,7 +822,7 @@ static int finish_automerge(struct commit_list *common,
 static int suggest_conflicts(void)
 {
 	FILE *fp;
-	int pos;
+	int pos, flag;
 
 	fp = fopen(git_path("MERGE_MSG"), "a");
 	if (!fp)
@@ -841,7 +841,10 @@ static int suggest_conflicts(void)
 		}
 	}
 	fclose(fp);
-	rerere(allow_rerere_auto);
+	flag = allow_rerere_auto;
+	if (merge_renormalize)
+		flag |= RERERE_RENORMALIZE;
+	rerere(flag);
 	printf("Automatic merge failed; "
 			"fix conflicts and then commit the result.\n");
 	return 1;
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 295fe75..4009c01 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -111,15 +111,19 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
 	struct option options[] = {
 		OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
 			"register clean resolutions in index", 1),
+		{ OPTION_BIT, 0, "renormalize-before-merge", &flags, NULL,
+			"simplify conflict hunks for normalization changes",
+			PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL,
+			RERERE_RENORMALIZE },
 		OPT_END(),
 	};
 
 	argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
 
 	if (autoupdate == 1)
-		flags = RERERE_AUTOUPDATE;
+		flags |= RERERE_AUTOUPDATE;
 	if (autoupdate == 0)
-		flags = RERERE_NOAUTOUPDATE;
+		flags |= RERERE_NOAUTOUPDATE;
 
 	if (argc < 1)
 		return rerere(flags);
diff --git a/builtin/revert.c b/builtin/revert.c
index 853e9e4..c694801 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -338,7 +338,7 @@ static void do_recursive_merge(struct commit *base, struct commit *next,
 	rollback_lock_file(&index_lock);
 
 	if (!clean) {
-		int i;
+		int i, flags;
 		strbuf_addstr(msgbuf, "\nConflicts:\n\n");
 		for (i = 0; i < active_nr;) {
 			struct cache_entry *ce = active_cache[i++];
@@ -354,7 +354,10 @@ static void do_recursive_merge(struct commit *base, struct commit *next,
 		write_message(msgbuf, defmsg);
 		fprintf(stderr, "Automatic %s failed.%s\n",
 			me, help_msg());
-		rerere(allow_rerere_auto);
+		flags = allow_rerere_auto;
+		if (o.renormalize)
+			flags |= RERERE_RENORMALIZE;
+		rerere(flags);
 		exit(1);
 	}
 	write_message(msgbuf, defmsg);
@@ -481,6 +484,10 @@ static int do_pick_commit(void)
 		if (res) {
 			fprintf(stderr, "Automatic %s with strategy %s failed.%s\n",
 				me, strategy, help_msg());
+			/*
+			 * NEEDSWORK: use RERERE_RENORMALIZE after
+			 * a merge with merge.renormalize set
+			 */
 			rerere(allow_rerere_auto);
 			exit(1);
 		}
diff --git a/rerere.c b/rerere.c
index 17dcc3c..8767024 100644
--- a/rerere.c
+++ b/rerere.c
@@ -553,12 +553,13 @@ int setup_rerere(struct string_list *merge_rr, int flags)
 int rerere(int flags)
 {
 	struct string_list merge_rr = { NULL, 0, 0, 1 };
-	int fd;
+	int fd, renormalize;
 
 	fd = setup_rerere(&merge_rr, flags);
 	if (fd < 0)
 		return 0;
-	return do_plain_rerere(&merge_rr, fd, merge_renormalize);
+	renormalize = (flags & RERERE_RENORMALIZE) ? 1 : 0;
+	return do_plain_rerere(&merge_rr, fd, renormalize);
 }
 
 static int rerere_forget_one_path(const char *path, struct string_list *rr)
diff --git a/rerere.h b/rerere.h
index eaa9004..a73555f 100644
--- a/rerere.h
+++ b/rerere.h
@@ -5,6 +5,7 @@
 
 #define RERERE_AUTOUPDATE   01
 #define RERERE_NOAUTOUPDATE 02
+#define RERERE_RENORMALIZE  04
 
 extern int setup_rerere(struct string_list *, int);
 extern int rerere(int);
-- 
1.7.2.1.544.ga752d.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]