diff mbox series

[v2,2/2] subtree: changing location of commit ignore processing

Message ID d6811daf7cf7f1460877307575e4cbc363ae851a.1695399920.git.gitgitgadget@gmail.com (mailing list archive)
State New, archived
Headers show
Series subtree: fix split processing with multiple subtrees present | expand

Commit Message

Zach FettersMoore Sept. 22, 2023, 4:25 p.m. UTC
From: Zach FettersMoore <zach.fetters@apollographql.com>

Based on feedback from original commit:

-Updated the location of check whether a commit should
be ignored during split processing

-Updated code to better fit coding guidelines

Signed-off-by: Zach FettersMoore <zach.fetters@apollographql.com>
---
 contrib/subtree/git-subtree.sh | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index e9250dfb019..e69991a9d80 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -778,11 +778,13 @@  ensure_valid_ref_format () {
 		die "fatal: '$1' does not look like a ref"
 }
 
-# Usage: check if a commit from another subtree should be ignored from processing for splits
-should_ignore_subtree_commit () {
-  if [ "$(git log -1 --grep="git-subtree-dir:" $1)" ]
+# Usage: check if a commit from another subtree should be
+# ignored from processing for splits
+should_ignore_subtree_split_commit () {
+  if test -n "$(git log -1 --grep="git-subtree-dir:" $1)"
   then
-    if [[ -z "$(git log -1 --grep="git-subtree-mainline:" $1)" && -z "$(git log -1 --grep="git-subtree-dir: $dir$" $1)" ]]
+    if test -z "$(git log -1 --grep="git-subtree-mainline:" $1)" &&
+			test -z "$(git log -1 --grep="git-subtree-dir: $arg_prefix$" $1)"
     then
       return 0
     fi
@@ -796,11 +798,6 @@  process_split_commit () {
 	local rev="$1"
 	local parents="$2"
 
-    if should_ignore_subtree_commit $rev
-    then
-	    return
-    fi
-
 	if test $indent -eq 0
 	then
 		revcount=$(($revcount + 1))
@@ -980,7 +977,20 @@  cmd_split () {
 	eval "$grl" |
 	while read rev parents
 	do
-		process_split_commit "$rev" "$parents"
+		if should_ignore_subtree_split_commit "$rev"
+		then
+			continue
+		fi
+		parsedParents=''
+		for parent in $parents
+		do
+			should_ignore_subtree_split_commit "$parent"
+			if test $? -eq 1
+			then
+				parsedParents+="$parent "
+			fi
+		done
+		process_split_commit "$rev" "$parsedParents"
 	done || exit $?
 
 	latest_new=$(cache_get latest_new) || exit $?