git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH v2 02/11] rerere: scan $GIT_DIR/rr-cache/$ID when instantiating a rerere_id
Date: Mon, 28 Mar 2016 15:42:13 -0700	[thread overview]
Message-ID: <1459204942-26601-3-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1459204942-26601-1-git-send-email-gitster@pobox.com>

This will help fixing bootstrap corner-case issues, e.g. having an
empty $GIT_DIR/rr-cache/$ID directory would fail to record a
preimage, in later changes in this series.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * Unchanged.

 rerere.c | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/rerere.c b/rerere.c
index a5d8a06..fbdade8 100644
--- a/rerere.c
+++ b/rerere.c
@@ -26,8 +26,11 @@ static char *merge_rr_path;
 static int rerere_dir_nr;
 static int rerere_dir_alloc;
 
+#define RR_HAS_POSTIMAGE 1
+#define RR_HAS_PREIMAGE 2
 static struct rerere_dir {
 	unsigned char sha1[20];
+	unsigned char status;
 } **rerere_dir;
 
 static void free_rerere_dirs(void)
@@ -58,6 +61,27 @@ const char *rerere_path(const struct rerere_id *id, const char *file)
 	return git_path("rr-cache/%s/%s", rerere_id_hex(id), file);
 }
 
+static int is_rr_file(const char *name, const char *filename)
+{
+	return !strcmp(name, filename);
+}
+
+static void scan_rerere_dir(struct rerere_dir *rr_dir)
+{
+	struct dirent *de;
+	DIR *dir = opendir(git_path("rr-cache/%s", sha1_to_hex(rr_dir->sha1)));
+
+	if (!dir)
+		return;
+	while ((de = readdir(dir)) != NULL) {
+		if (is_rr_file(de->d_name, "postimage"))
+			rr_dir->status |= RR_HAS_POSTIMAGE;
+		else if (is_rr_file(de->d_name, "preimage"))
+			rr_dir->status |= RR_HAS_PREIMAGE;
+	}
+	closedir(dir);
+}
+
 static const unsigned char *rerere_dir_sha1(size_t i, void *table)
 {
 	struct rerere_dir **rr_dir = table;
@@ -76,6 +100,7 @@ static struct rerere_dir *find_rerere_dir(const char *hex)
 	if (pos < 0) {
 		rr_dir = xmalloc(sizeof(*rr_dir));
 		hashcpy(rr_dir->sha1, sha1);
+		rr_dir->status = 0;
 		pos = -1 - pos;
 
 		/* Make sure the array is big enough ... */
@@ -85,15 +110,14 @@ static struct rerere_dir *find_rerere_dir(const char *hex)
 		memmove(rerere_dir + pos + 1, rerere_dir + pos,
 			(rerere_dir_nr - pos - 1) * sizeof(*rerere_dir));
 		rerere_dir[pos] = rr_dir;
+		scan_rerere_dir(rr_dir);
 	}
 	return rerere_dir[pos];
 }
 
 static int has_rerere_resolution(const struct rerere_id *id)
 {
-	struct stat st;
-
-	return !stat(rerere_path(id, "postimage"), &st);
+	return (id->collection->status & RR_HAS_POSTIMAGE);
 }
 
 static struct rerere_id *new_rerere_id_hex(char *hex)
@@ -737,6 +761,7 @@ static void do_rerere_one_path(struct string_list_item *rr_item,
 	} else if (!handle_file(path, NULL, NULL)) {
 		/* The user has resolved it. */
 		copy_file(rerere_path(id, "postimage"), path, 0666);
+		id->collection->status |= RR_HAS_POSTIMAGE;
 		fprintf(stderr, "Recorded resolution for '%s'.\n", path);
 	} else {
 		return;
@@ -797,6 +822,7 @@ static int do_plain_rerere(struct string_list *rr, int fd)
 		 * normalized contents to the "preimage" file.
 		 */
 		handle_file(path, NULL, rerere_path(id, "preimage"));
+		id->collection->status |= RR_HAS_PREIMAGE;
 		fprintf(stderr, "Recorded preimage for '%s'\n", path);
 	}
 
-- 
2.8.0-215-g046a488

  parent reply	other threads:[~2016-03-28 22:42 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-14 23:57 [PATCH 0/7] saving and replaying multiple variants with rerere Junio C Hamano
2015-09-14 23:57 ` [PATCH 1/7] rerere: split conflict ID further Junio C Hamano
2015-09-14 23:57 ` [PATCH 2/7] rerere: scan $GIT_DIR/rr-cache/$ID when instantiating a rerere_id Junio C Hamano
2015-09-14 23:57 ` [PATCH 3/7] rerere: handle leftover rr-cache/$ID directory and postimage files Junio C Hamano
2015-09-14 23:57 ` [PATCH 4/7] rerere: delay the recording of preimage Junio C Hamano
2015-09-14 23:57 ` [PATCH 5/7] rerere: allow multiple variants to exist Junio C Hamano
2015-09-14 23:57 ` [PATCH 6/7] t4200: rerere a merge with two identical conflicts Junio C Hamano
2015-09-14 23:57 ` [PATCH 7/7] rerere: do use multiple variants Junio C Hamano
2016-03-28 22:42 ` [PATCH v2 00/11] saving and replaying multiple variants with rerere Junio C Hamano
2016-03-28 22:42   ` [PATCH v2 01/11] rerere: split conflict ID further Junio C Hamano
2016-03-28 22:42   ` Junio C Hamano [this message]
2016-03-28 22:42   ` [PATCH v2 03/11] rerere: handle leftover rr-cache/$ID directory and postimage files Junio C Hamano
2016-03-28 22:42   ` [PATCH v2 04/11] rerere: delay the recording of preimage Junio C Hamano
2016-03-28 22:42   ` [PATCH v2 05/11] rerere: allow multiple variants to exist Junio C Hamano
2016-03-28 22:42   ` [PATCH v2 06/11] t4200: rerere a merge with two identical conflicts Junio C Hamano
2016-03-28 22:42   ` [PATCH v2 07/11] rerere: do use multiple variants Junio C Hamano
2016-03-28 22:42   ` [PATCH v2 08/11] rerere: gc and clear Junio C Hamano
2016-03-28 22:42   ` [PATCH v2 09/11] rerere: move code related to "forget" together Junio C Hamano
2016-03-28 22:42   ` [PATCH v2 10/11] rerere: split code to call ll_merge() further Junio C Hamano
2016-03-28 22:42   ` [PATCH v2 11/11] rerere: adjust 'forget' to multi-variant world order Junio C Hamano
2016-04-06 23:05   ` [PATCH v3 00/11] saving and replaying multiple variants with rerere Junio C Hamano
2016-04-06 23:05     ` [PATCH v3 01/11] rerere: split conflict ID further Junio C Hamano
2016-04-06 23:05     ` [PATCH v3 02/11] rerere: scan $GIT_DIR/rr-cache/$ID when instantiating a rerere_id Junio C Hamano
2016-04-06 23:05     ` [PATCH v3 03/11] rerere: handle leftover rr-cache/$ID directory and postimage files Junio C Hamano
2016-04-06 23:05     ` [PATCH v3 04/11] rerere: delay the recording of preimage Junio C Hamano
2016-04-06 23:05     ` [PATCH v3 05/11] rerere: allow multiple variants to exist Junio C Hamano
2016-04-06 23:05     ` [PATCH v3 06/11] t4200: rerere a merge with two identical conflicts Junio C Hamano
2016-04-06 23:05     ` [PATCH v3 07/11] rerere: do use multiple variants Junio C Hamano
2016-04-06 23:05     ` [PATCH v3 08/11] rerere: gc and clear Junio C Hamano
2016-04-06 23:05     ` [PATCH v3 09/11] rerere: move code related to "forget" together Junio C Hamano
2016-04-06 23:05     ` [PATCH v3 10/11] rerere: split code to call ll_merge() further Junio C Hamano
2016-04-06 23:05     ` [PATCH v3 11/11] rerere: adjust 'forget' to multi-variant world order Junio C Hamano

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=1459204942-26601-3-git-send-email-gitster@pobox.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).