public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Colin Stagner <ask+git@howdoi.land>
To: git@vger.kernel.org, Christian Heusel <christian@heusel.eu>,
	 george@mail.dietrich.pub
Cc: Christian Hesse <list@eworm.de>,
	 Phillip Wood <phillip.wood@dunelm.org.uk>,
	 Junio C Hamano <gitster@pobox.com>,
	Colin Stagner <ask+git@howdoi.land>
Subject: [PATCH v2 1/3] contrib/subtree: reduce function side-effects
Date: Thu, 05 Mar 2026 17:55:47 -0600	[thread overview]
Message-ID: <20260305-cs-subtree-split-recursion-v2-1-7266be870ba9@howdoi.land> (raw)
In-Reply-To: <20260305-cs-subtree-split-recursion-v2-0-7266be870ba9@howdoi.land>

`process_subtree_split_trailer()` communicates its return value
to the caller by setting a variable (`sub`) that is also defined
by the calling function. This is both unclear and encourages
side-effects.

Invoke this function in a sub-shell instead.

Signed-off-by: Colin Stagner <ask+git@howdoi.land>
---
 contrib/subtree/git-subtree.sh | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 791fd8260c..bae5d9170b 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -373,6 +373,10 @@ try_remove_previous () {
 }
 
 # Usage: process_subtree_split_trailer SPLIT_HASH MAIN_HASH [REPOSITORY]
+#
+# Parse SPLIT_HASH as a commit. If the commit is not found, fetches
+# REPOSITORY and tries again. If found, prints full commit hash.
+# Otherwise, dies.
 process_subtree_split_trailer () {
 	assert test $# -ge 2
 	assert test $# -le 3
@@ -400,6 +404,7 @@ process_subtree_split_trailer () {
 			die "$fail_msg"
 		fi
 	fi
+	echo "${sub}"
 }
 
 # Usage: find_latest_squash DIR [REPOSITORY]
@@ -432,7 +437,7 @@ find_latest_squash () {
 			main="$b"
 			;;
 		git-subtree-split:)
-			process_subtree_split_trailer "$b" "$sq" "$repository"
+			sub="$(process_subtree_split_trailer "$b" "$sq" "$repository")" || exit 1
 			;;
 		END)
 			if test -n "$sub"
@@ -489,7 +494,7 @@ find_existing_splits () {
 			main="$b"
 			;;
 		git-subtree-split:)
-			process_subtree_split_trailer "$b" "$sq" "$repository"
+			sub="$(process_subtree_split_trailer "$b" "$sq" "$repository")" || exit 1
 			;;
 		END)
 			debug "Main is: '$main'"

-- 
2.43.0


  reply	other threads:[~2026-03-05 23:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-15 20:17 [PATCH 0/3] contrib/subtree: reduce recursion during split Colin Stagner
2026-02-15 20:17 ` [PATCH 1/3] contrib/subtree: reduce function side-effects Colin Stagner
2026-02-15 20:17 ` [PATCH 2/3] contrib/subtree: functionalize split traversal Colin Stagner
2026-02-15 20:17 ` [PATCH 3/3] contrib/subtree: reduce recursion during split Colin Stagner
2026-03-05 23:55 ` [PATCH v2 0/3] " Colin Stagner
2026-03-05 23:55   ` Colin Stagner [this message]
2026-03-05 23:55   ` [PATCH v2 2/3] contrib/subtree: functionalize split traversal Colin Stagner
2026-03-05 23:55   ` [PATCH v2 3/3] contrib/subtree: reduce recursion during split Colin Stagner
2026-03-13 22:51   ` [PATCH v2 0/3] " Junio C Hamano
2026-03-13 23:06     ` 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

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

  git send-email \
    --in-reply-to=20260305-cs-subtree-split-recursion-v2-1-7266be870ba9@howdoi.land \
    --to=ask+git@howdoi.land \
    --cc=christian@heusel.eu \
    --cc=george@mail.dietrich.pub \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=list@eworm.de \
    --cc=phillip.wood@dunelm.org.uk \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox