summaryrefslogtreecommitdiff
path: root/contrib/subtree/git-subtree.sh
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@datawire.io>2021-04-27 21:17:33 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-04-28 07:47:17 (GMT)
commitf66430483645eb764135e5c79b753f1c09170ac8 (patch)
tree465556a9d10b2300e7a54d75512ea77244201179 /contrib/subtree/git-subtree.sh
parent8dc3240f5fc78aec1b1e6b10b94fa361bf016157 (diff)
downloadgit-f66430483645eb764135e5c79b753f1c09170ac8.zip
git-f66430483645eb764135e5c79b753f1c09170ac8.tar.gz
git-f66430483645eb764135e5c79b753f1c09170ac8.tar.bz2
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>
Diffstat (limited to 'contrib/subtree/git-subtree.sh')
-rwxr-xr-xcontrib/subtree/git-subtree.sh16
1 files changed, 1 insertions, 15 deletions
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 4503564..70e16b8 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -280,20 +280,6 @@ rev_exists () {
fi
}
-rev_is_descendant_of_branch () {
- newrev="$1"
- branch="$2"
- branch_hash=$(git rev-parse "$branch")
- match=$(git rev-list -1 "$branch_hash" "^$newrev")
-
- if test -z "$match"
- then
- return 0
- else
- return 1
- fi
-}
-
# if a commit doesn't have a parent, this might not work. But we only want
# to remove the parent from the rev-list, and since it doesn't exist, it won't
# be there anyway, so do nothing in that case.
@@ -811,7 +797,7 @@ cmd_split () {
then
if rev_exists "refs/heads/$branch"
then
- if ! rev_is_descendant_of_branch "$latest_new" "$branch"
+ if ! git merge-base --is-ancestor "$branch" "$latest_new"
then
die "Branch '$branch' is not an ancestor of commit '$latest_new'."
fi