@@ -233,17 +233,16 @@ function cmd_linearize() {
233233 pre_branch=$( git branch --show-current)
234234
235235 if $EL_REBASE_SPLITS ; then
236- split_commits=()
236+ declare -A split_commit_map
237237 for branch in $( git for-each-ref --format=" %(refname:short)" refs/heads/) ; do
238238 if [ $branch == $pre_branch ]; then
239239 continue
240240 fi
241241 # merge_base=$(git merge-base "${commits[0]}" "$branch")
242242 merge_base=$( git merge-base $pre_branch $branch )
243243 echodebug " Found merge base $merge_base for branch $branch "
244- split_commits+=( " $merge_base " )
244+ split_commit_map[ " $merge_base " ]= " $branch "
245245 done
246- echodebug " Split commits: ${split_commits[*]} "
247246 fi
248247
249248 # Find start commit
@@ -292,20 +291,17 @@ function cmd_linearize() {
292291 echoinfo " [x] $sha1 is now $new_sha "
293292
294293 if $EL_REBASE_SPLITS ; then
295- if [[ " ${split_commits[*]} " =~ " ${sha1} " ]]; then
294+ # https://stackoverflow.com/a/46243464/14681457
295+ if [[ -n " ${split_commit_map[$sha1]+unset} " ]]; then
296296 # List all branches that share this commit
297297 # Then loop through them and rebase them onto the new commit.
298- echodebug " branches $EL_REBASE_SPLITS that contain this commit: $( git branch --contains $sha1 ) "
299- for branch in $( git branch --contains $sha1 ) ; do
300- if [ $branch != $pre_branch ]; then
301- echodebug " rebasing $branch onto $new_sha "
302- git switch $branch | debug
303- git rebase --onto $new_sha $sha1 | debug
304- git switch extremely-linear | debug
305- fi
306- done
298+ branch=${split_commit_map[$sha1]}
299+ git switch $branch | debug
300+ git rebase --onto $new_sha $sha1 | debug
301+ git switch extremely-linear | debug
307302 else
308- echo " $sha1 not in $split_commits "
303+ # echo "$sha1 not in ${split_commit_map[*]}"
304+ printf " $sha1 not in %s\n" " ${! split_commit_map[@]} " | debug
309305 fi
310306 fi
311307 fi # skip if hash is already nice
0 commit comments