git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: git@vger.kernel.org
Subject: [PATCH 5/5] rerere.autoupdate
Date: Sun, 22 Jun 2008 02:48:10 -0700	[thread overview]
Message-ID: <7v1w2pol5x.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: 7vskvd9kai.fsf@gitster.siamese.dyndns.org

When this configuration is set, paths that are autoresolved by git-rerere
are updated in the index as well.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/config.txt |    5 +++++
 builtin-rerere.c         |   37 +++++++++++++++++++++++++++++++++++++
 t/t4200-rerere.sh        |   10 ++++++++++
 3 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 5331b45..0c7cf61 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -650,6 +650,11 @@ gc.rerereunresolved::
 	kept for this many days when `git rerere gc` is run.
 	The default is 15 days.  See linkgit:git-rerere[1].
 
+rerere.autoupdate::
+	When set to true, `git-rerere` updates the index with the
+	resulting contents after it cleanly resolves conflicts using
+	previously recorded resolution.  Defaults to false.
+
 rerere.enabled::
 	Activate recording of resolved conflicts, so that identical
 	conflict hunks can be resolved automatically, should they
diff --git a/builtin-rerere.c b/builtin-rerere.c
index 0eec1f9..839b26e 100644
--- a/builtin-rerere.c
+++ b/builtin-rerere.c
@@ -16,6 +16,9 @@ static int cutoff_resolve = 60;
 /* if rerere_enabled == -1, fall back to detection of .git/rr-cache */
 static int rerere_enabled = -1;
 
+/* automatically update cleanly resolved paths to the index */
+static int rerere_autoupdate;
+
 static char *merge_rr_path;
 
 static const char *rr_path(const char *name, const char *file)
@@ -276,9 +279,36 @@ static int diff_two(const char *file1, const char *label1,
 	return 0;
 }
 
+static struct lock_file index_lock;
+
+static int update_paths(struct path_list *update)
+{
+	int i;
+	int fd = hold_locked_index(&index_lock, 0);
+	int status = 0;
+
+	if (fd < 0)
+		return -1;
+
+	for (i = 0; i < update->nr; i++) {
+		struct path_list_item *item = &update->items[i];
+		if (add_file_to_cache(item->path, ADD_CACHE_IGNORE_ERRORS))
+			status = -1;
+	}
+
+	if (!status && active_cache_changed) {
+		if (write_cache(fd, active_cache, active_nr) ||
+		    commit_locked_index(&index_lock))
+			die("Unable to write new index file");
+	} else if (fd >= 0)
+		rollback_lock_file(&index_lock);
+	return status;
+}
+
 static int do_plain_rerere(struct path_list *rr, int fd)
 {
 	struct path_list conflict = { NULL, 0, 0, 1 };
+	struct path_list update = { NULL, 0, 0, 1 };
 	int i;
 
 	find_conflict(&conflict);
@@ -323,6 +353,8 @@ static int do_plain_rerere(struct path_list *rr, int fd)
 			if (!merge(name, path)) {
 				fprintf(stderr, "Resolved '%s' using "
 						"previous resolution.\n", path);
+				if (rerere_autoupdate)
+					path_list_insert(path, &update);
 				goto mark_resolved;
 			}
 		}
@@ -338,6 +370,9 @@ static int do_plain_rerere(struct path_list *rr, int fd)
 		rr->items[i].util = NULL;
 	}
 
+	if (update.nr)
+		update_paths(&update);
+
 	return write_rr(rr, fd);
 }
 
@@ -349,6 +384,8 @@ static int git_rerere_config(const char *var, const char *value, void *cb)
 		cutoff_noresolve = git_config_int(var, value);
 	else if (!strcmp(var, "rerere.enabled"))
 		rerere_enabled = git_config_bool(var, value);
+	else if (!strcmp(var, "rerere.autoupdate"))
+		rerere_autoupdate = git_config_bool(var, value);
 	else
 		return git_default_config(var, value, cb);
 	return 0;
diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh
index afb3e3d..a64727d 100755
--- a/t/t4200-rerere.sh
+++ b/t/t4200-rerere.sh
@@ -193,9 +193,19 @@ test_expect_success 'resolution was recorded properly' '
 	echo Bello > file3 &&
 	git add file3 &&
 	git commit -m version2 &&
+	git tag version2 &&
 	test_must_fail git merge fifth &&
 	test Cello = "$(cat file3)" &&
 	test 0 != $(git ls-files -u | wc -l)
 '
 
+test_expect_success 'rerere.autoupdate' '
+	git config rerere.autoupdate true
+	git reset --hard &&
+	git checkout version2 &&
+	test_must_fail git merge fifth &&
+	test 0 = $(git ls-files -u | wc -l)
+
+'
+
 test_done
-- 
1.5.6.12.g73f03

  parent reply	other threads:[~2008-06-22  9:49 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-16 11:01 git-rerere observations and feature suggestions Ingo Molnar
2008-06-16 11:09 ` Mike Hommey
2008-06-16 15:48   ` Pierre Habouzit
2008-06-16 15:57     ` Pierre Habouzit
2008-06-16 16:18       ` Sverre Rabbelier
2008-06-17  7:37         ` Karl Hasselström
2008-06-16 11:26 ` David Kastrup
2008-06-16 11:27 ` Theodore Tso
2008-06-16 12:38   ` David Kastrup
2008-06-16 19:52   ` Ingo Molnar
2008-06-16 20:25     ` Junio C Hamano
2008-06-16 20:46       ` Ingo Molnar
2008-06-16 21:37         ` Junio C Hamano
2008-06-16 18:46 ` Junio C Hamano
2008-06-16 19:09   ` Ingo Molnar
2008-06-16 20:50     ` Junio C Hamano
2008-06-22  9:47       ` [PATCH 1/5] rerere: rerere_created_at() and has_resolution() abstraction Junio C Hamano
2008-06-22  9:47       ` [PATCH 2/5] git-rerere: detect unparsable conflicts Junio C Hamano
2008-06-22  9:47       ` [PATCH 3/5] rerere: remove dubious "tail_optimization" Junio C Hamano
2008-06-22  9:48       ` [PATCH 4/5] t4200: fix rerere test Junio C Hamano
2008-06-22  9:48       ` Junio C Hamano [this message]
2008-06-18 10:57     ` git-rerere observations and feature suggestions Ingo Molnar
2008-06-18 11:29       ` Miklos Vajna
2008-06-18 18:43         ` Ingo Molnar
2008-06-18 19:53           ` Miklos Vajna
2008-06-18 11:36       ` Ingo Molnar
2008-06-18 22:01       ` Jakub Narebski
2008-06-18 22:38         ` Miklos Vajna
2008-06-19  7:23           ` Karl Hasselström
2008-06-19  7:29             ` Miklos Vajna
2008-06-19  7:30             ` Junio C Hamano
2008-06-19  8:21               ` Karl Hasselström
2008-06-19  8:33                 ` Miklos Vajna
2008-06-19  9:19                   ` Karl Hasselström
2008-06-19 10:06                     ` Miklos Vajna
2008-06-19 10:35                       ` Karl Hasselström
2008-06-16 19:10   ` Junio C Hamano
2008-06-16 19:44     ` Ingo Molnar
2008-06-23  9:49   ` Ingo Molnar
2008-06-23 14:19     ` Peter Zijlstra
2008-06-23 14:26       ` Peter Zijlstra
2008-06-23 15:12     ` Jeff King
2008-06-23 15:22       ` Ingo Molnar
2008-06-16 20:11 ` Jakub Narebski
2008-06-17 10:24 ` Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7v1w2pol5x.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=mingo@elte.hu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).