Skip to content

Commit f664304

Browse files
LukeShugitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8dc3240 commit f664304

File tree

1 file changed

+1
-15
lines changed

1 file changed

+1
-15
lines changed

contrib/subtree/git-subtree.sh

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -280,20 +280,6 @@ rev_exists () {
280280
fi
281281
}
282282

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-
297283
# if a commit doesn't have a parent, this might not work. But we only want
298284
# to remove the parent from the rev-list, and since it doesn't exist, it won't
299285
# be there anyway, so do nothing in that case.
@@ -811,7 +797,7 @@ cmd_split () {
811797
then
812798
if rev_exists "refs/heads/$branch"
813799
then
814-
if ! rev_is_descendant_of_branch "$latest_new" "$branch"
800+
if ! git merge-base --is-ancestor "$branch" "$latest_new"
815801
then
816802
die "Branch '$branch' is not an ancestor of commit '$latest_new'."
817803
fi

0 commit comments

Comments
 (0)