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,2018,2021
9 Usage: ${tgname:-tg} [...] summary [<option>...] [--all | <branch>...]
10 Or: ${tgname:-tg} [...] summary [--terse | --list] [<option>...] [--all | <branch>...]
11 Or: ${tgname:-tg} [...] summary --rdeps[-full] [<option>...] [--all | <branch>...]
12 Or: ${tgname:-tg} [...] summary --heads[-independent] [<option>...] [--all | <branch>...]
13 Or: ${tgname:-tg} [...] summary --deps [<option>...] [--all | <branch>...]
14 Or: ${tgname:-tg} [...] summary --deps-only [<option>...] [--all | <branch>...]
15 Or: ${tgname:-tg} [...] summary --sort [<option>...] [--all | <branch>...]
16 Or: ${tgname:-tg} [...] summary --graphviz [<option>...] [--all | <branch>...]
18 --terse / --list list TopGit branches (aka '-t' / '-l')
19 --rdeps[-once] show branch dependencies as multi-indented list
20 --rdeps-full like '--rdeps' but do not collapse repeated items
21 --rdeps --heads use '--rdeps' and \$('--heads of <branch>...)
22 --[topgit]-heads list only independent TopGit branch heads
23 --heads-independent list only merge-base --independent heads
24 --deps list all .topdeps branch dependencies
25 --deps-only list sorted unique .topdeps branches + dependencies
26 --sort feed output of '--deps' through 'tsort'
27 --graphviz generate dependency graph description in DOT format
28 --verbose / -v include subjects with '-l' (twice shows annihilated)
29 --exclude <branch> exclude <branch> during operation (may be repeated)
30 --tgish-only exclude non-TopGit branches (aka '--tgish')
31 --with-deps include dependencies of given <branch>... (default)
32 --without-deps do not include dependencies of given <branch>...
33 --with-related use '--with-deps' and \$('--heads' of <branch>...)
34 --without-related do not use '--with-related' processing
35 --heads-only use '--without-deps' and \$('--heads' of <branch>...)
36 -i use TopGit metadata from index instead of HEAD branch
37 -w use metadata from working directory instead of branch"
41 if [ "${1:-0}" != 0 ]; then
42 printf '%s\n' "$USAGE" >&2
44 printf '%s\n' "$USAGE"
77 [ -z "$head_from" ] || die
"-i and -w are mutually exclusive"
82 verbose
=$
(( $verbose + 1 ));;
84 terse
=1 verbose
=$
(( $verbose + 1 ));;
86 verbose
=$
(( $verbose + 2 ));;
88 terse
=1 verbose
=$
(( $verbose + 2 ));;
89 --heads|
--topgit-heads)
103 --without-deps|
--no-with-deps|
--without-related|
--no-with-related)
112 --tgish-only|
--tgish)
125 rdeps
=1 rdepsonce
=1;;
129 [ -n "${1#--exclude=}" ] || die
"--exclude= requires a branch name"
130 exclude
="$exclude ${1#--exclude=}";;
133 [ -n "$1" ] && [ "$1" != "--all" ] || die
"--exclude requires a branch name"
134 exclude
="$exclude $1";;
142 [ $# -eq 0 ] || defwithdeps
=1
143 [ -z "$exclude" ] || exclude
="$exclude "
145 [ $# -ne 0 ] ||
[ z
"$head" != z
"" ] || doingall
=1
146 if [ "$1" = "--all" ]; then
147 [ -z "$withdeps" ] || die
"mutually exclusive options given"
148 [ $# -eq 1 ] || usage
154 [ "$heads$rdeps" != "11" ] ||
head=
155 [ $# -ne 0 ] ||
[ -z "$head" ] ||
set -- "$head"
156 [ -z "$defwithdeps" ] ||
[ $# -ne 1 ] ||
{ [ z
"$1" != z
"HEAD" ] && [ z
"$1" != z
"@" ]; } || defwithdeps
=2
158 [ "$terse$heads$headsonly$graphviz$sort$deps$depsonly" = "" ] ||
159 [ "$terse$heads$headsonly$graphviz$sort$deps$depsonly$rdeps" = "1" ] ||
160 { [ "$terse$heads$headsonly$graphviz$sort$deps$depsonly$rdeps" = "11" ] && [ "$heads$rdeps" = "11" ]; } ||
161 die
"mutually exclusive options given"
162 [ -z "$withdeps" ] ||
[ -z "$rdeps$depsonly$heads$headsonly" ] ||
163 die
"mutually exclusive options given"
166 [ "$b" != "--all" ] || usage
167 v_verify_topgit_branch b
"$b"
168 branches
="$branches $b"
173 if [ -n "$branches" ]; then
175 printf '%s\n' $branches |
sort -u
177 printf '%s\n' $branches
180 non_annihilated_branches
184 show_heads_independent
()
186 topics
="$(get_temp topics)"
187 get_branch_list |
sed -e 's,^\(.*\)$,refs/heads/\1 \1,' |
188 git cat-file
--batch-check='%(objectname) %(rest)' |
189 sort -u -b -k1,1 >"$topics"
190 git merge-base
--independent $
(cut
-d ' ' -f 1 <"$topics") |
191 sort -u -b -k1,1 |
join - "$topics" |
sort -u -b -k2,2 |
192 while read rev name
; do
193 case "$exclude" in *" $name "*) continue; esac
194 printf '%s\n' "$name"
200 [ -z "$head_from" ] ||
[ -n "$with_deps_opts" ] ||
201 v_get_tdopt with_deps_opts
"$head_from"
202 if [ -n "$branches" ]; then
203 eval navigate_deps
"$with_deps_opts" -s=-1 -1 -- '"$branches"' |
sort
205 eval navigate_deps
"$with_deps_opts" -s=-1
207 while read -r name
; do
208 case "$exclude" in *" $name "*) continue; esac
209 printf '%s\n' "$name"
215 if [ -n "$headsindep" ]; then
216 show_heads_independent
"$@"
218 show_heads_topgit
"$@"
222 if [ -n "$heads" ] && [ -z "$rdeps" ]; then
227 # if $1 is non-empty, show the dep only (including self), not the edge (no self)
230 [ -z "$head_from" ] ||
[ -n "$with_deps_opts" ] ||
231 v_get_tdopt with_deps_opts
"$head_from"
232 if [ -n "$branches" ]; then
234 [ -z "$1" ] || edgenum
=1
236 recurse_deps_exclude
="$exclude"
237 recurse_deps_internal
-n ${tgish:+-t} -m ${1:+-s} -e=$edgenum -- $branches |
sort -u
240 [ -z "$1" ] || cutcmd
='| cut -d " " -f 2 | sort -u'
242 [ -z "$tg_read_only" ] ||
[ -z "$tg_ref_cache" ] ||
! [ -s "$tg_ref_cache" ] ||
243 refslist
="-r=\"$tg_ref_cache\""
245 eval run_awk_topgit_deps
"$refslist" "$with_deps_opts" "${tgish:+-t}" \
246 "${1:+-s}" '-n -x="$exclude" "refs/$topbases"' "$cutcmd"
250 if [ -n "$deps$depsonly$sort" ]; then
251 eval show_deps
$depsonly "${sort:+|tsort}"
255 if [ -n "$rdeps" ]; then
258 recurse_deps_exclude
="$exclude"
260 v_get_tdopt with_deps_opts
"$head_from"
262 if [ -n "$heads" ]; then
267 } |
while read -r b
; do
268 case "$exclude" in *" $b "*) continue; esac
269 ref_exists
"refs/heads/$b" ||
continue
270 [ -z "$showbreak" ] ||
echo
272 recurse_deps_internal
${tgish:+-t} -n -s ${rdepsonce:+-o=-1} "$b" |
273 awk -v elided
="$rdepsonce" '{
274 if ($1 == "1" || NF < 5) next
277 if ($6 != "") haschild[$6] = 1
278 sub(/^[^ ]+ +[^ ]+ +[^ ]+ +[^ ]+ +[^ ]+/, "")
281 if (elided && xvisits > 0 && haschild[dep]) xtra="^"
288 if [ -n "$headsonly" ]; then
290 branches
="$(show_heads)"
293 [ -n "$withdeps" ] || withdeps
="$defwithdeps"
294 if [ -z "$doingall$terse$graphviz$sort$withdeps$branches" ]; then
295 branches
="$(tg info --heads 2>/dev/null | paste -d " " -s -)" ||
:
296 [ -z "$branches" ] || withdeps
=1
298 [ "$withdeps" != "0" ] || withdeps
=
299 if [ -n "$withdeps" ]; then
300 v_get_tdopt with_deps_opts
"$head_from"
301 [ "$withdeps" != "2" ] || branches
="$(show_heads_topgit | paste -d " " -s -)"
304 origbranches
="$branches"
305 branches
="$(show_deps 1 | paste -d " " -s -)"
309 if [ -n "$terse" ]; then
311 [ -z "$tg_read_only" ] ||
[ -z "$tg_ref_cache" ] ||
! [ -s "$tg_ref_cache" ] ||
312 refslist
="-r=\"$tg_ref_cache\""
313 cmd
="run_awk_topgit_branches -n"
314 if [ $verbose -gt 0 ]; then
315 v_get_tmopt tm_opt
"$head_from"
316 cmd
="run_awk_topgit_msg --list${tm_opt:+ $tm_opt}"
317 [ $verbose -lt 2 ] || cmd
="run_awk_topgit_msg -c -nokind${tm_opt:+ $tm_opt}"
319 eval "$cmd" "$refslist" '-i="$branches" -x="$exclude" "refs/$topbases"'
323 v_strip_ref curname
"$(git symbolic-ref -q HEAD)"
325 if [ -n "$graphviz" ]; then
327 '# GraphViz output; pipe to:
328 # | dot -Tpng -o <output>
336 label="TopGit Layout\n\n\n"
341 show_deps |
while read -r name dep
; do
342 printf '"%s" -> "%s";\n' "$name" "$dep"
343 if [ "$name" = "$curname" ] ||
[ "$dep" = "$curname" ]; then
344 printf '"%s" [%s];\n' "$curname" "style=filled,fillcolor=yellow"
355 [ -z "$tg_read_only" ] ||
[ -z "$tg_ref_cache" ] ||
! [ -s "$tg_ref_cache" ] ||
356 refslist
="-r=\"$tg_ref_cache\""
357 msgsfile
="$(get_temp msgslist)"
358 v_get_tmopt tm_opt
"$head_from"
359 eval run_awk_topgit_msg
"-nokind${tm_opt:+ $tm_opt}" "$refslist" '"refs/$topbases"' >"$msgsfile"
360 needs_update_check_clear
361 needs_update_check_no_same
=1
362 [ -z "$branches" ] ||
[ -n "$withdeps" ] ||
return 0
363 v_get_tdopt with_deps_opts
"$head_from"
364 [ -n "$withdeps" ] || origbranches
="$(navigate_deps -s=-1 | paste -d ' ' -s -)"
365 for onehead
in $origbranches; do
366 case "$exclude" in *" $onehead "*) continue; esac
367 needs_update_check
$onehead
369 aheadlist
=" $needs_update_ahead "
377 [ "$name" != "$curname" ] || current
='>'
379 [ "$name" = "$curname" ] ||
382 ! branch_empty
"$name" $from || nonempty
='0'
384 [ -z "$base_remote" ] || remote
='l'
385 ! has_remote
"$name" || remote
='r'
387 [ "$remote" != 'r' ] ||
! ref_exists
"refs/remotes/$base_remote/${topbases#heads/}/$name" ||
{
388 branch_contains
"refs/$topbases/$name" "refs/remotes/$base_remote/${topbases#heads/}/$name" &&
389 branch_contains
"refs/heads/$name" "refs/remotes/$base_remote/$name"
391 [ "$remote" != 'r' ] ||
[ "$rem_update" = 'R' ] ||
{
392 branch_contains
"refs/remotes/$base_remote/$name" "refs/heads/$name" 2>/dev
/null
394 needs_update_check
"$name"
396 ! vcontains needs_update_behind
"$name" || deps_update
='D'
398 ! vcontains needs_update_partial
"$name" || deps_missing
='!'
400 branch_contains
"refs/heads/$name" "refs/$topbases/$name" || base_update
='B'
402 case "$aheadlist" in *" $name "*) ahead
='*'; esac
404 printf '%-8s %s\n' "$current$nonempty$remote$rem_update$deps_update$deps_missing$base_update$ahead" \
410 if (msgsfile != "") {
411 while ((e = (getline msg <msgsfile)) > 0) {
412 gsub(/[ \t]+/, " ", msg)
414 if (split(msg, scratch, " ") < 2 ||
415 scratch[1] == "" || scratch[2] == "") continue
416 msg = substr(msg, length(scratch[1]) + 2)
417 msgs[scratch[1]] = msg
423 name = substr($0, 10)
424 if (name != "" && name in msgs)
425 printf "%-39s\t%s\n", $0, msgs[name]
432 cmd
='get_branch_list | while read name; do process_branch; done'
433 [ -z "$msgsfile" ] || cmd
="$cmd"' | awk -v msgsfile="$msgsfile" "$awkpgm"'