subtree: use `git merge-base --is-ancestor`

Instead of writing a slow `rev_is_descendant_of_branch $a $b` function in shell, just use the fast `git merge-base --is-ancestor $b $a`. Signed-off-by: Luke Shumaker <lukeshu@datawire.io> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Luke Shumaker committed Apr 27, 2021 at 15:17 UTC f66430483645eb764135e5c79b753f1c09170ac8
1 file changed +1 -15
contrib/subtree/git-subtree.sh
+1 -15
@@ -280,20 +280,6 @@ rev_exists () {
280 fi
281 }
282
283 -rev_is_descendant_of_branch () {
284 - newrev="$1"
285 - branch="$2"
286 - branch_hash=$(git rev-parse "$branch")
287 - match=$(git rev-list -1 "$branch_hash" "^$newrev")
288 -
289 - if test -z "$match"
290 - then
291 - return 0
292 - else
293 - return 1
294 - fi
295 -}
296 -
283 # if a commit doesn't have a parent, this might not work. But we only want
284 # to remove the parent from the rev-list, and since it doesn't exist, it won't
285 # be there anyway, so do nothing in that case.
@@ -811,7 +797,7 @@ cmd_split () {
797 then
798 if rev_exists "refs/heads/$branch"
799 then
814 - if ! rev_is_descendant_of_branch "$latest_new" "$branch"
800 + if ! git merge-base --is-ancestor "$branch" "$latest_new"
801 then
802 die "Branch '$branch' is not an ancestor of commit '$latest_new'."
803 fi