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

[PATCH 2/3] am: do not corrupt the index stat state

From
David Aguilar <davvid@gmail.com>
Date
Aug 21, 2015, 08:02 UTC
Message-ID
<1440144151-24026-2-git-send-email-davvid@gmail.com>
In-Reply-To
<1440144151-24026-1-git-send-email-davvid@gmail.com>
Reported-by: Linus Torvalds
Signed-off-by: David Aguilar <davvid@gmail.com>
---
 builtin/am.c        | 14 +++++++++++++-
 t/t4151-am-abort.sh |  2 +-
 2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/builtin/am.c b/builtin/am.c
index 1399c8d..9db1b34 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1949,6 +1949,8 @@ static int clean_index(const unsigned char *head, const unsigned char *remote)
 	struct tree *head_tree, *remote_tree, *index_tree;
 	unsigned char index[GIT_SHA1_RAWSZ];
 	struct pathspec pathspec;
+	struct tree_desc desc;
+	struct unpack_trees_options opts;
 
 	head_tree = parse_tree_indirect(head);
 	if (!head_tree)
@@ -1975,10 +1977,20 @@ static int clean_index(const unsigned char *head, const unsigned char *remote)
 
 	memset(&pathspec, 0, sizeof(pathspec));
 
+	memset(&opts, 0, sizeof(opts));
+	opts.fn = oneway_merge;
+	opts.pathspec = &pathspec;
+	opts.src_index = &the_index;
+	opts.dst_index = &the_index;
+	opts.head_idx = 1;
+	opts.merge = 1;
+	opts.reset = 1;
+	init_tree_desc(&desc, remote_tree->buffer, remote_tree->size);
+
 	lock_file = xcalloc(1, sizeof(struct lock_file));
 	hold_locked_index(lock_file, 1);
 
-	if (read_tree(remote_tree, 0, &pathspec)) {
+	if (unpack_trees(1, &desc, &opts)) {
 		rollback_lock_file(lock_file);
 		return -1;
 	}
diff --git a/t/t4151-am-abort.sh b/t/t4151-am-abort.sh
index bf2e6f4..9c3bbd1 100755
--- a/t/t4151-am-abort.sh
+++ b/t/t4151-am-abort.sh
@@ -168,7 +168,7 @@ test_expect_success 'am --abort on unborn branch will keep local commits intact'
 	test_cmp expect actual
 '
 
-test_expect_failure 'am --abort leaves index stat info alone' '
+test_expect_success 'am --abort leaves index stat info alone' '
 	git checkout -f --orphan stat-info &&
 	git reset &&
 	test_commit should-be-untouched &&
-- 
2.5.0.403.gd17121e
Previous: David AguilarNext: Junio C Hamano
Message 2 of 5 in “t4151: demonstrate that builtin am corrupts index' stat data”
  1. 1/3 t4151: demonstrate that builtin am corrupts index' stat dataDavid Aguilar, Aug 21, 2015
  2. 2/3 am: do not corrupt the index stat stateDavid Aguilar, Aug 21, 2015
  3. Junio C HamanoAug 21, 2015
  4. 3/3 am: rename "struct tree_desc t" to "desc" for readabilityDavid Aguilar, Aug 21, 2015
  5. Junio C HamanoAug 21, 2015

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.