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
@@ -121,6 +121,24 @@ show_topic () {
121 fi
122 }
123
124 +compare_topic () {
125 + b=$1 r=$2
126 + based=$(git rev-list --no-merges $b..$r | wc -l | tr -d ' ')
127 + bases=$(git rev-list --no-merges $r..$b | wc -l | tr -d ' ')
128 + case "$based,$bases" in
129 + 0,0) echo same; exit ;;
130 + 0,*) echo left; exit ;;
131 + *,0) echo right; exit ;;
132 + esac
133 +
134 + if test $based -lt $bases
135 + then
136 + echo left-p
137 + else
138 + echo fork
139 + fi
140 +}
141 +
142 # List commits that are shared between more than one topic branches
143 while read b
144 do
@@ -148,27 +166,23 @@ do
166 for r in $related
167 do
168 test "$b" = "$r" && continue
151 - based=$(git rev-list --no-merges $b..$r | wc -l | tr -d ' ')
152 - bases=$(git rev-list --no-merges $r..$b | wc -l | tr -d ' ')
153 - case "$based,$bases" in
154 - 0,0)
169 + case "$(compare_topic "$b" "$r")" in
170 + same)
171 same_as="$same_as$r "
172 ;;
157 - 0,*)
173 + left)
174 based_on="$based_on$r "
175 based_on_msg="$based_on_msg$r "
176 ;;
161 - *,0)
177 + left-p)
178 + based_on="$based_on$r "
179 + based_on_msg="${based_on_msg}#EPO-$r "
180 + ;;
181 + right)
182 used_by="$used_by$r "
183 ;;
164 - *,*)
165 - if test $based -lt $bases
166 - then
167 - based_on="$based_on$r "
168 - based_on_msg="${based_on_msg}#EPO-$r "
169 - else
170 - forks="$forks$r "
171 - fi
184 + fork)
185 + forks="$forks$r "
186 ;;
187 esac
188 done