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

[PATCH/RFC 3/3] merge-recursive: Tolerate missing file when HEAD is up to date

From
Brad King <brad.king@kitware.com>
Date
Jan 24, 2014, 15:01 UTC
Message-ID
<5e5bfe752655c39fca626811972af9d0a90ddab9.1390574981.git.brad.king@kitware.com>
In-Reply-To
<cover.1390574980.git.brad.king@kitware.com>

Teach add_cacheinfo to optionally tolerate make_cache_entry failure when the reason is ENOENT from lstat. Tell it to do so in the call path when the entry from HEAD is known to be up to date.

This fixes the 'merge-recursive w/ empty work tree - ours has rename' case in t3030-merge-recursive.

Signed-off-by: Brad King <brad.king@kitware.com>
---
 merge-recursive.c          | 21 +++++++++++++--------
 t/t3030-merge-recursive.sh |  2 +-
 2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/merge-recursive.c b/merge-recursive.c
index 4394c44..6a2b962 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -198,13 +198,18 @@ static void output_commit_title(struct merge_options *o, struct commit *commit)
 }
 
 static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
-		const char *path, int stage, int refresh, int options)
+			 const char *path, int stage, int refresh,
+			 int options, int noent_okay)
 {
 	struct cache_entry *ce;
+	int cache_errno = 0;
 	ce = make_cache_entry(mode, sha1 ? sha1 : null_sha1, path,
-			      stage, refresh, NULL);
-	if (!ce)
+			      stage, refresh, &cache_errno);
+	if (!ce) {
+		if(cache_errno == ENOENT && noent_okay)
+			return 0;
 		return error(_("addinfo_cache failed for path '%s'"), path);
+	}
 	return add_cache_entry(ce, options);
 }
 
@@ -552,13 +557,13 @@ static int update_stages(const char *path, const struct diff_filespec *o,
 		if (remove_file_from_cache(path))
 			return -1;
 	if (o)
-		if (add_cacheinfo(o->mode, o->sha1, path, 1, 0, options))
+		if (add_cacheinfo(o->mode, o->sha1, path, 1, 0, options, 0))
 			return -1;
 	if (a)
-		if (add_cacheinfo(a->mode, a->sha1, path, 2, 0, options))
+		if (add_cacheinfo(a->mode, a->sha1, path, 2, 0, options, 0))
 			return -1;
 	if (b)
-		if (add_cacheinfo(b->mode, b->sha1, path, 3, 0, options))
+		if (add_cacheinfo(b->mode, b->sha1, path, 3, 0, options, 0))
 			return -1;
 	return 0;
 }
@@ -789,7 +794,7 @@ static void update_file_flags(struct merge_options *o,
 	}
  update_index:
 	if (update_cache)
-		add_cacheinfo(mode, sha, path, 0, update_wd, ADD_CACHE_OK_TO_ADD);
+		add_cacheinfo(mode, sha, path, 0, update_wd, ADD_CACHE_OK_TO_ADD, 0);
 }
 
 static void update_file(struct merge_options *o,
@@ -1624,7 +1629,7 @@ static int merge_content(struct merge_options *o,
 		path_renamed_outside_HEAD = !path2 || !strcmp(path, path2);
 		if (!path_renamed_outside_HEAD) {
 			add_cacheinfo(mfi.mode, mfi.sha, path,
-				      0, (!o->call_depth), 0);
+				      0, (!o->call_depth), 0, 1);
 			return mfi.clean;
 		}
 	} else
diff --git a/t/t3030-merge-recursive.sh b/t/t3030-merge-recursive.sh
index b6d3ed0..c8ba895 100755
--- a/t/t3030-merge-recursive.sh
+++ b/t/t3030-merge-recursive.sh
@@ -518,7 +518,7 @@ test_expect_success 'reset and bind merge' '
 
 '
 
-test_expect_failure 'merge-recursive w/ empty work tree - ours has rename' '
+test_expect_success 'merge-recursive w/ empty work tree - ours has rename' '
 	(
 	 GIT_WORK_TREE="$PWD/ours-has-rename-work" &&
 	 export GIT_WORK_TREE &&
-- 
1.8.5.2
Previous: Brad KingNext: Junio C Hamano
Message 6 of 21 in “merge-recursive: Avoid diagnostic on empty work tree”
  1. 0/3 merge-recursive: Avoid diagnostic on empty work treeBrad King, Jan 24, 2014
  2. 1/3 t3030-merge-recursive: Test known breakage with empty work treeBrad King, Jan 24, 2014
  3. Jonathan NiederJan 24, 2014
  4. Brad KingJan 24, 2014
  5. 2/3 read-cache.c: Thread lstat error through make_cache_entry signatureBrad King, Jan 24, 2014
  6. 3/3 merge-recursive: Tolerate missing file when HEAD is up to dateBrad King, Jan 24, 2014
  7. Junio C HamanoJan 24, 2014
  8. Brad KingJan 24, 2014
  9. 0/3 merge-recursive: Avoid diagnostic on empty work treeBrad King, Jan 24, 2014
  10. 1/3 t3030-merge-recursive: Test known breakage with empty work treeBrad King, Jan 24, 2014
  11. 2/3 read-cache.c: Optionally tolerate missing files in make_cache_entryBrad King, Jan 24, 2014
  12. Junio C HamanoJan 24, 2014
  13. 3/3 merge-recursive.c: Tolerate missing files while refreshing indexBrad King, Jan 24, 2014
  14. 0/3 merge-recursive: Avoid diagnostic on empty work treeBrad King, Jan 27, 2014
  15. 1/4 t3030-merge-recursive: Test known breakage with empty work treeBrad King, Jan 27, 2014
  16. 2/4 read-cache.c: Refactor --ignore-missing implementationBrad King, Jan 27, 2014
  17. Junio C HamanoJan 27, 2014
  18. 3/4 read-cache.c: Extend make_cache_entry refresh flag with optionsBrad King, Jan 27, 2014
  19. 4/4 merge-recursive.c: Tolerate missing files while refreshing indexBrad King, Jan 27, 2014
  20. Fwd: [PATCH/RFC 3/3] merge-recursive: Tolerate missing file when HEAD is up to datenewren, Jan 24, 2014
  21. Brad KingJan 24, 2014

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.