aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMirek Kratochvil <exa.exa@gmail.com>2025-12-28 10:13:54 +0100
committerMirek Kratochvil <exa.exa@gmail.com>2025-12-28 10:13:54 +0100
commitdc3f34978376ff066892e369ccb287851581042c (patch)
treeac495b7da22560654d367bbfade0ee88fa9fbb72
parentf550022df4918036eb2a2b3bf745cf446f30db19 (diff)
downloadgit-deli-dc3f34978376ff066892e369ccb287851581042c.tar.gz
git-deli-dc3f34978376ff066892e369ccb287851581042c.tar.bz2
intern base finding
-rwxr-xr-xbin/git-deli53
-rwxr-xr-xlibexec/git-deli-find-base-commits.sh40
2 files changed, 52 insertions, 41 deletions
diff --git a/bin/git-deli b/bin/git-deli
index 6a00b40..60b5ff0 100755
--- a/bin/git-deli
+++ b/bin/git-deli
@@ -5,6 +5,10 @@
# Copytight (C) 2025 Mirek Kratochvil <exa.exa@gmail.com>
#
+#
+# ARGUMENT PARSING AND MAIN ENTRYPOINT
+#
+
OPTS_SPEC="\
git deli head [-b=<branch>] [-m=<msg>] [<commit>]
git deli commit ...
@@ -22,7 +26,6 @@ d,delete delete the boundary commit instead of adding it
'push' options:
f,force internally do a true force-push instead of the safe force-with-lease
"
-
main() {
if test $# -eq 0
then set -- -h
@@ -93,6 +96,10 @@ main() {
esac
}
+#
+# COMMANDS
+#
+
cmd_head () {
msg="$1"
branch="$2"
@@ -137,4 +144,48 @@ cmd_pull () {
# TODO like a normal git fetch followed by git deli merge
}
+#
+# PRUNING ANCESTORS
+#
+
+add_to_merge_points () {
+ shas="$1"
+ new="$2"
+ for sha in $shas ; do
+ [ "$sha" = "$new" ] && continue
+ git merge-base --is-ancestor "$sha" "$new"
+ res=$?
+ case $res in
+ 0) ;;
+ 1) echo "$sha" ;;
+ *) echo "$0: ancestor finding failed" >&2
+ exit 1 ;;
+ esac
+ done
+ old=no
+ for sha in $shas ; do
+ [ "$sha" = "$new" ] && continue
+ git merge-base --is-ancestor "$new" "$sha"
+ res=$?
+ case $res in
+ 0) old=yes ; break ;;
+ 1) ;;
+ *) echo "$0: ancestor finding failed" >&2
+ exit 1 ;;
+ esac
+ done
+ [ $old = no ] && echo "$new"
+}
+
+prune_merge_points () {
+ mps=
+ while read sha trailing_garbage
+ do mps=$( add_to_merge_points "$mps" "$sha" )
+ done
+ for sha in $mps
+ do echo "$sha"
+ done
+}
+
+# finally, run the main
main "$@"
diff --git a/libexec/git-deli-find-base-commits.sh b/libexec/git-deli-find-base-commits.sh
deleted file mode 100755
index 3e16227..0000000
--- a/libexec/git-deli-find-base-commits.sh
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/bin/bash
-
-extend_bases () {
- shas="$1"
- new="$2"
- for sha in $shas ; do
- [ "$sha" = "$new" ] && continue
- ${DELI_GIT_IS_ANCESTOR_CMD:-git merge-base --is-ancestor} "$sha" "$new"
- res=$?
- case $res in
- 0) ;;
- 1) echo "$sha" ;;
- *) echo "$0: ancestor finding failed" >&2
- exit 1 ;;
- esac
- done
- old=no
- for sha in $shas ; do
- [ "$sha" = "$new" ] && continue
- ${DELI_GIT_IS_ANCESTOR_CMD:-git merge-base --is-ancestor} "$new" "$sha"
- res=$?
- case $res in
- 0) old=yes ; break ;;
- 1) ;;
- *) echo "$0: ancestor finding failed" >&2
- exit 1 ;;
- esac
- done
- [ $old = no ] && echo "$new"
-}
-
-bases=""
-
-while read sha ; do
- bases=$( extend_bases "$bases" "$sha" )
-done
-
-for sha in $bases ; do
- echo "$sha"
-done