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

[PATCH 1/1] subtree: fix cache_set failure on commit reachable by multiple paths

From
RCRoland Conybeare <rconybeare@gmail.com>
Date
May 24, 2026, 21:23 UTC
Message-ID
<20260524212339.1493145-2-rconybeare@gmail.com>
In-Reply-To
<20260524212339.1493145-1-rconybeare@gmail.com>

When splitting a subtree, committs that do not intersect prefix receive identity mapping (oldrev -> oldrev). If such commit is reachable by multiple paths in the revision DAG, the cache_set() function may be called twice for the same (oldrev -> newrev) pair.

This triggers fatal error "cache for <hash> already exists"

Bugfix is to make cache_set() idempotent when the same (oldrev -> newrev) pair appears multiple times.

Signed-off-by: Roland Conybeare <rconybeare@gmail.com>
---
 contrib/subtree/git-subtree.sh | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 791fd8260c..64590e05e0 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -343,7 +343,13 @@ cache_set () {
 		test "$oldrev" != "latest_new" &&
 		test -e "$cachedir/$oldrev"
 	then
-		die "fatal: cache for $oldrev already exists!"
+		existing=$(cat "$cachedir/$oldrev")
+		if test "$existing" = "$newrev"
+		then
+			return
+		else
+			die "fatal: cache for $oldrev already exists!"
+		fi
 	fi
 	echo "$newrev" >"$cachedir/$oldrev"
 }
-- 
2.50.1
Previous: Roland Conybeare
Message 2 of 2 in “bugfix git subtree split”
  1. 0/1 bugfix git subtree splitRoland Conybeare, May 24, 2026
  2. 1/1 subtree: fix cache_set failure on commit reachable by multiple pathsRoland Conybeare, May 24, 2026

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.