git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 04/11] rerere: delay the recording of preimage

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 28, 2016, 22:42 UTC
Message-ID
<1459204942-26601-5-git-send-email-gitster@pobox.com>
In-Reply-To
<1459204942-26601-1-git-send-email-gitster@pobox.com>

We record the preimage only when there is no directory to record the conflict we encountered, i.e. when $GIT_DIR/rr-cache/$ID does not exist. As the plan is to allow multiple <preimage,postimage> pairs as variants for the same conflict ID eventually, this logic needs to go.

As the first step in that direction, stop the "did we create the directory? Then we record the preimage" logic. Instead, we record if a preimage does not exist when we saw a conflict in a path. Also make sure that we remove a stale postimage, which most likely is totally unrelated to the resolution of this new conflict, when we create a new preimage under $ID when $GIT_DIR/rr-cache/$ID already exists.

In later patches, we will further update this logic to be "do we have <preimage,postimage> pair that cleanly resolve the current conflicts? If not, record a new preimage as a new variant", but that does not happen at this stage yet.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * The previous one had a handful of confusions between which of
   RR_HAS_{PRE,POST}IMAGE bit to clear, which was pointed out by
   J6t.  The corrections to them appear here and a few patches
   that follow this one in this round.
 rerere.c | 52 +++++++++++++++++++++++++---------------------------
 1 file changed, 25 insertions(+), 27 deletions(-)
diff --git a/rerere.c b/rerere.c
index a1e2963..33b1348 100644
--- a/rerere.c
+++ b/rerere.c
@@ -122,6 +122,11 @@ static int has_rerere_resolution(const struct rerere_id *id)
 	return ((id->collection->status & both) == both);
 }
 
+static int has_rerere_preimage(const struct rerere_id *id)
+{
+	return (id->collection->status & RR_HAS_PREIMAGE);
+}
+
 static struct rerere_id *new_rerere_id_hex(char *hex)
 {
 	struct rerere_id *id = xmalloc(sizeof(*id));
@@ -749,8 +754,24 @@ static void do_rerere_one_path(struct string_list_item *rr_item,
 	const char *path = rr_item->string;
 	const struct rerere_id *id = rr_item->util;
 
-	/* Is there a recorded resolution we could attempt to apply? */
-	if (has_rerere_resolution(id)) {
+	if (!has_rerere_preimage(id)) {
+		/*
+		 * We are the first to encounter this conflict.  Ask
+		 * handle_file() to write the normalized contents to
+		 * the "preimage" file.
+		 */
+		handle_file(path, NULL, rerere_path(id, "preimage"));
+		if (id->collection->status & RR_HAS_POSTIMAGE) {
+			const char *path = rerere_path(id, "postimage");
+			if (unlink(path))
+				die_errno("cannot unlink stray '%s'", path);
+			id->collection->status &= ~RR_HAS_POSTIMAGE;
+		}
+		id->collection->status |= RR_HAS_PREIMAGE;
+		fprintf(stderr, "Recorded preimage for '%s'\n", path);
+		return;
+	} else if (has_rerere_resolution(id)) {
+		/* Is there a recorded resolution we could attempt to apply? */
 		if (merge(id, path))
 			return; /* failed to replay */
 
@@ -807,31 +828,8 @@ static int do_plain_rerere(struct string_list *rr, int fd)
 		id = new_rerere_id(sha1);
 		string_list_insert(rr, path)->util = id;
 
-		/*
-		 * Ensure that the directory exists.
-		 * mkdir_in_gitdir() will fail with EEXIST if there
-		 * already is one.
-		 */
-		if (mkdir_in_gitdir(rerere_path(id, NULL)) &&
-		    errno != EEXIST)
-			continue; /* NEEDSWORK: perhaps we should die? */
-
-		if (id->collection->status & RR_HAS_PREIMAGE) {
-			;
-		} else {
-			/*
-			 * We are the first to encounter this
-			 * conflict.  Ask handle_file() to write the
-			 * normalized contents to the "preimage" file.
-			 *
-			 * NEEDSWORK: what should happen if we had a
-			 * leftover postimage that is totally
-			 * unrelated?  Perhaps we should unlink it?
-			 */
-			handle_file(path, NULL, rerere_path(id, "preimage"));
-			id->collection->status |= RR_HAS_PREIMAGE;
-			fprintf(stderr, "Recorded preimage for '%s'\n", path);
-		}
+		/* Ensure that the directory exists. */
+		mkdir_in_gitdir(rerere_path(id, NULL));
 	}
 
 	for (i = 0; i < rr->nr; i++)
-- 
2.8.0-215-g046a488
Previous: Junio C HamanoNext: Junio C Hamano
Message 13 of 32 in “saving and replaying multiple variants with rerere”
  1. 0/7 saving and replaying multiple variants with rerereJunio C Hamano, Sep 14, 2015
  2. 1/7 rerere: split conflict ID furtherJunio C Hamano, Sep 14, 2015
  3. 2/7 rerere: scan $GIT_DIR/rr-cache/$ID when instantiating a rerere_idJunio C Hamano, Sep 14, 2015
  4. 3/7 rerere: handle leftover rr-cache/$ID directory and postimage filesJunio C Hamano, Sep 14, 2015
  5. 4/7 rerere: delay the recording of preimageJunio C Hamano, Sep 14, 2015
  6. 5/7 rerere: allow multiple variants to existJunio C Hamano, Sep 14, 2015
  7. 6/7 t4200: rerere a merge with two identical conflictsJunio C Hamano, Sep 14, 2015
  8. 7/7 rerere: do use multiple variantsJunio C Hamano, Sep 14, 2015
  9. 00/11 saving and replaying multiple variants with rerereJunio C Hamano, Mar 28, 2016
  10. 01/11 rerere: split conflict ID furtherJunio C Hamano, Mar 28, 2016
  11. 02/11 rerere: scan $GIT_DIR/rr-cache/$ID when instantiating a rerere_idJunio C Hamano, Mar 28, 2016
  12. 03/11 rerere: handle leftover rr-cache/$ID directory and postimage filesJunio C Hamano, Mar 28, 2016
  13. 04/11 rerere: delay the recording of preimageJunio C Hamano, Mar 28, 2016
  14. 05/11 rerere: allow multiple variants to existJunio C Hamano, Mar 28, 2016
  15. 06/11 t4200: rerere a merge with two identical conflictsJunio C Hamano, Mar 28, 2016
  16. 07/11 rerere: do use multiple variantsJunio C Hamano, Mar 28, 2016
  17. 08/11 rerere: gc and clearJunio C Hamano, Mar 28, 2016
  18. 09/11 rerere: move code related to "forget" togetherJunio C Hamano, Mar 28, 2016
  19. 10/11 rerere: split code to call ll_merge() furtherJunio C Hamano, Mar 28, 2016
  20. 11/11 rerere: adjust 'forget' to multi-variant world orderJunio C Hamano, Mar 28, 2016
  21. 00/11 saving and replaying multiple variants with rerereJunio C Hamano, Apr 6, 2016
  22. 01/11 rerere: split conflict ID furtherJunio C Hamano, Apr 6, 2016
  23. 02/11 rerere: scan $GIT_DIR/rr-cache/$ID when instantiating a rerere_idJunio C Hamano, Apr 6, 2016
  24. 03/11 rerere: handle leftover rr-cache/$ID directory and postimage filesJunio C Hamano, Apr 6, 2016
  25. 04/11 rerere: delay the recording of preimageJunio C Hamano, Apr 6, 2016
  26. 05/11 rerere: allow multiple variants to existJunio C Hamano, Apr 6, 2016
  27. 06/11 t4200: rerere a merge with two identical conflictsJunio C Hamano, Apr 6, 2016
  28. 07/11 rerere: do use multiple variantsJunio C Hamano, Apr 6, 2016
  29. 08/11 rerere: gc and clearJunio C Hamano, Apr 6, 2016
  30. 09/11 rerere: move code related to "forget" togetherJunio C Hamano, Apr 6, 2016
  31. 10/11 rerere: split code to call ll_merge() furtherJunio C Hamano, Apr 6, 2016
  32. 11/11 rerere: adjust 'forget' to multi-variant world orderJunio C Hamano, Apr 6, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.