2 # TopGit - A different patch queue manager
3 # Copyright (C) Petr Baudis <pasky@suse.cz> 2008
4 # Copyright (C) Kyle J. McKay <mackyle@gmail.com> 2015,2016,2017
30 echo "Usage: ${tgname:-tg} [...] summary [-t | --list | --heads[-only] | --sort | --deps[-only] | --rdeps | --graphviz] [-i | -w] [--tgish-only] [--with[out]-(deps|related)] [--exclude branch]... [--all | branch...]" >&2
38 [ -z "$head_from" ] || die
"-i and -w are mutually exclusive"
43 verbose
=$
(( $verbose + 1 ));;
44 --heads|
--topgit-heads)
58 --without-deps|
--no-with-deps|
--without-related|
--no-with-related)
84 [ -n "${1#--exclude=}" ] || die
"--exclude= requires a branch name"
85 exclude
="$exclude ${1#--exclude=}";;
88 [ -n "$1" -a "$1" != "--all" ] || die
"--exclude requires a branch name"
89 exclude
="$exclude $1";;
97 [ $# -eq 0 ] || defwithdeps
=1
98 [ -z "$exclude" ] || exclude
="$exclude "
100 [ $# -ne 0 ] ||
[ z
"$head" != z
"" ] || doingall
=1
101 if [ "$1" = "--all" ]; then
102 [ -z "$withdeps" ] || die
"mutually exclusive options given"
103 [ $# -eq 1 ] || usage
109 [ "$heads$rdeps" != "11" ] ||
head=
110 [ $# -ne 0 -o -z "$head" ] ||
set -- "$head"
111 [ -z "$defwithdeps" ] ||
[ $# -ne 1 ] ||
[ z
"$1" != z
"HEAD" -a z
"$1" != z
"@" ] || defwithdeps
=2
113 [ "$terse$heads$headsonly$graphviz$sort$deps$depsonly" = "" ] ||
114 [ "$terse$heads$headsonly$graphviz$sort$deps$depsonly$rdeps" = "1" ] ||
115 [ "$terse$heads$headsonly$graphviz$sort$deps$depsonly$rdeps" = "11" -a "$heads$rdeps" = "11" ] ||
116 die
"mutually exclusive options given"
117 [ -z "$withdeps" -o -z "$rdeps$depsonly$heads$headsonly" ] ||
118 die
"mutually exclusive options given"
121 [ "$b" != "--all" ] || usage
122 branches
="$branches $(verify_topgit_branch "$b")"
127 if [ -n "$branches" ]; then
129 printf '%s\n' $branches |
sort -u
131 printf '%s\n' $branches
134 non_annihilated_branches
138 show_heads_independent
()
140 topics
="$(get_temp topics)"
141 get_branch_list |
sed -e 's,^\(.*\)$,refs/heads/\1 \1,' |
142 git cat-file
--batch-check='%(objectname) %(rest)' |
143 sort -u -b -k1,1 >"$topics"
144 git merge-base
--independent $
(cut
-d ' ' -f 1 <"$topics") |
145 sort -u -b -k1,1 |
join - "$topics" |
sort -u -b -k2,2 |
146 while read rev name
; do
147 case "$exclude" in *" $name "*) continue; esac
148 printf '%s\n' "$name"
154 if [ -n "$branches" ]; then
155 navigate_deps
-s=-1 -1 -- "$branches" |
sort
159 while read -r name
; do
160 case "$exclude" in *" $name "*) continue; esac
161 printf '%s\n' "$name"
167 if [ -n "$headsindep" ]; then
168 show_heads_independent
"$@"
170 show_heads_topgit
"$@"
174 if [ -n "$heads" -a -z "$rdeps" ]; then
181 case "$exclude" in *" $_dep "*) return; esac
182 case " $seen_deps " in *" $_dep "*) return 0; esac
183 seen_deps
="${seen_deps:+$seen_deps }$_dep"
184 [ -z "$tgish" -o -n "$_dep_is_tgish" ] ||
return 0
185 [ -z "$skip_ann" ] ||
[ -z "$_dep_annihilated" ] && printf '%s\n' "$_dep"
192 recurse_deps_exclude
=
193 get_branch_list |
while read _b
; do
194 case "$exclude" in *" $_b "*) continue; esac
195 case " $recurse_deps_exclude " in *" $_b "*) continue; esac
197 save_skip
="$skip_ann"
198 _dep
="$_b"; _dep_is_tgish
=1; skip_ann
=; show_dep
; skip_ann
="$save_skip"
199 recurse_deps show_dep
"$_b"
200 recurse_deps_exclude
="$recurse_deps_exclude $seen_deps"
204 if [ -n "$depsonly" ]; then
205 show_deps |
sort -u -b -k1,1
211 case "$exclude" in *" $_dep "*) return; esac
212 [ -z "$tgish" -o -n "$_dep_is_tgish" ] ||
return 0
214 [ -z "$rdepsonce" ] ||
[ "$_dep_xvisits" = 0 ] || elided
="^"
215 printf '%s %s\n' "$_depchain" "$_dep$elided"
218 if [ -n "$rdeps" ]; then
222 if [ -n "$heads" ]; then
228 case "$exclude" in *" $b "*) continue; esac
229 [ -z "$showbreak" ] ||
echo
231 ref_exists
"refs/heads/$b" ||
continue
235 recurse_deps
${rdepsonce:+-o=-o=-1} show_rdeps
"$b"
236 } |
sed -e 's/[^ ][^ ]*[ ]/ /g'
241 if [ -n "$deps" ]; then
242 if [ -n "$branches" ]; then
244 recurse_deps_exclude
="$exclude"
245 recurse_deps_internal
-n -t -m -e=2 -- $branches |
sort -u
248 [ -z "$tg_read_only" ] ||
[ -z "$tg_ref_cache" ] ||
! [ -s "$tg_ref_cache" ] ||
249 refslist
="-r=\"$tg_ref_cache\""
251 v_get_tdopt tdopt
"$head_from"
252 eval run_awk_topgit_deps
"$refslist" "$tdopt" '-n -t -x="$exclude" "refs/$topbases"'
257 if [ -n "$headsonly" ]; then
259 branches
="$(show_heads)"
262 [ -n "$withdeps" ] || withdeps
="$defwithdeps"
263 if [ -z "$doingall$terse$graphviz$sort$withdeps$branches" ]; then
264 branches
="$(tg info --heads 2>/dev/null | paste -d " " -s -)" ||
:
265 [ -z "$branches" ] || withdeps
=1
267 [ "$withdeps" != "0" ] || withdeps
=
268 if [ -n "$withdeps" ]; then
269 [ "$withdeps" != "2" ] || branches
="$(show_heads_topgit | paste -d " " -s -)"
272 origbranches
="$branches"
273 branches
="$(skip_ann=1; show_deps | sort -u -b -k1,1 | paste -d " " -s -)"
277 curname
="$(strip_ref "$
(git symbolic-ref
-q HEAD
)")" ||
:
279 if [ -n "$graphviz" ]; then
281 # GraphViz output; pipe to:
282 # | dot -Tpng -o <output>
290 label="TopGit Layout\n\n\n"
299 if [ -n "$sort" ]; then
300 tsort_input
="$(get_temp tg-summary-sort)"
312 [ -z "$branches" ] ||
[ -n "$withdeps" ] ||
return 0
313 [ -n "$withdeps" ] || origbranches
="$(tg summary --topgit-heads | paste -d ' ' -s -)"
314 aheadfile
="$(get_temp aheadlist)"
315 savebr
="$base_remote"
319 for onehead
in $origbranches; do
320 case "$exclude" in *" $onehead "*) continue; esac
321 case "$processed" in *" $onehead "*) continue; esac
322 processed
="${processed}$onehead "
323 needs_update
"$onehead" || needslist
="${needslist}$onehead "
326 base_remote
="$savebr"
327 aheadlist
=" $(cut -d ' ' -f 1 <"$aheadfile" | sort -u | paste -d ' ' -s -) "
335 [ "$name" != "$curname" ] || current
='>'
337 [ "$name" = "$curname" ] ||
340 ! branch_empty
"$name" $from || nonempty
='0'
342 [ -z "$base_remote" ] || remote
='l'
343 ! has_remote
"$name" || remote
='r'
345 [ "$remote" != 'r' ] ||
! ref_exists
"refs/remotes/$base_remote/${topbases#heads/}/$name" ||
{
346 branch_contains
"refs/$topbases/$name" "refs/remotes/$base_remote/${topbases#heads/}/$name" &&
347 branch_contains
"refs/heads/$name" "refs/remotes/$base_remote/$name"
349 [ "$remote" != 'r' -o "$rem_update" = 'R' ] ||
{
350 branch_contains
"refs/remotes/$base_remote/$name" "refs/heads/$name" 2>/dev
/null
355 case "$needslist" in *" $name "*) deps_update
='D'; esac;;
357 needs_update
"$name" >/dev
/null || deps_update
='D';;
360 [ -z "$missing_deps" ] || deps_missing
='!'
362 branch_contains
"refs/heads/$name" "refs/$topbases/$name" || base_update
='B'
364 case "$aheadlist" in *" $name "*) ahead
='*'; esac
366 if [ "$(ref_exists_rev "refs
/heads
/$name")" != "$(ref_exists_rev "refs
/$topbases/$name")" ]; then
367 subject
="$(cat_file "refs
/heads
/$name:.topmsg
" $from | sed -n 's/^Subject: //p')"
370 subject
="(No commits)"
373 printf '%-8s %-30s\t%s\n' "$current$nonempty$remote$rem_update$deps_update$deps_missing$base_update$ahead" \
377 if [ -n "$terse" ]; then
379 [ -z "$tg_read_only" ] ||
[ -z "$tg_ref_cache" ] ||
! [ -s "$tg_ref_cache" ] ||
380 refslist
="-r=\"$tg_ref_cache\""
381 cmd
="run_awk_topgit_msg --list"
382 [ $verbose -lt 2 ] || cmd
="run_awk_topgit_msg -c -nokind"
383 [ $verbose -gt 0 ] || cmd
="run_awk_topgit_branches -n"
384 eval "$cmd" "$refslist" '-i="$branches" -x="$exclude" "refs/$topbases"'
388 [ -n "$graphviz$sort" ] || compute_ahead_list
391 case "$exclude" in *" $name "*) continue; esac
392 if [ -n "$graphviz$sort" ]; then
394 [ "$name" = "$curname" ] ||
396 cat_file
"refs/heads/$name:.topdeps" $from |
while read -r dep ||
[ -n "$dep" ]; do
398 ref_exists
"refs/$topbases/$dep" ||
400 [ -z "$tgish" ] ||
[ "$dep_is_tgish" = "true" ] ||
continue
401 if ! "$dep_is_tgish" ||
! branch_annihilated
$dep; then
402 if [ -n "$graphviz" ]; then
403 echo "\"$name\" -> \"$dep\";"
404 if [ "$name" = "$curname" ] ||
[ "$dep" = "$curname" ]; then
405 echo "\"$curname\" [style=filled,fillcolor=yellow];"
408 echo "$name $dep" >&4
417 if [ -n "$graphviz" ]; then
421 if [ -n "$sort" ]; then