cook.sh: refactor topic comparison into a separate function
Junio C Hamano committed
Jan 12, 2010 at 21:50 UTC
d77c0ff87352484ab4cd47e3532f5ba8295daa87
1 file changed
+28
-14
cook.sh
+28
-14
index 7c0d12778d..dabee4b38c 100755
--- a/cook.sh
+++ b/cook.sh
@@ -121,6 +121,24 @@ show_topic () {
fi
}
+compare_topic () {
+ b=$1 r=$2
+ based=$(git rev-list --no-merges $b..$r | wc -l | tr -d ' ')
+ bases=$(git rev-list --no-merges $r..$b | wc -l | tr -d ' ')
+ case "$based,$bases" in
+ 0,0) echo same; exit ;;
+ 0,*) echo left; exit ;;
+ *,0) echo right; exit ;;
+ esac
+
+ if test $based -lt $bases
+ then
+ echo left-p
+ else
+ echo fork
+ fi
+}
+
# List commits that are shared between more than one topic branches
while read b
do
@@ -148,27 +166,23 @@ do
for r in $related
do
test "$b" = "$r" && continue
- based=$(git rev-list --no-merges $b..$r | wc -l | tr -d ' ')
- bases=$(git rev-list --no-merges $r..$b | wc -l | tr -d ' ')
- case "$based,$bases" in
- 0,0)
+ case "$(compare_topic "$b" "$r")" in
+ same)
same_as="$same_as$r "
;;
- 0,*)
+ left)
based_on="$based_on$r "
based_on_msg="$based_on_msg$r "
;;
- *,0)
+ left-p)
+ based_on="$based_on$r "
+ based_on_msg="${based_on_msg}#EPO-$r "
+ ;;
+ right)
used_by="$used_by$r "
;;
- *,*)
- if test $based -lt $bases
- then
- based_on="$based_on$r "
- based_on_msg="${based_on_msg}#EPO-$r "
- else
- forks="$forks$r "
- fi
+ fork)
+ forks="$forks$r "
;;
esac
done