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)"
313 [ -z "$tg_read_only" ] ||
[ -z "$tg_ref_cache" ] ||
! [ -s "$tg_ref_cache" ] ||
314 refslist
="-r=\"$tg_ref_cache\""
315 msgsfile
="$(get_temp msgslist)"
316 eval run_awk_topgit_msg
-nokind "$refslist" '"refs/$topbases"' >"$msgsfile"
317 needs_update_check_clear
318 needs_update_check_no_same
=1
319 [ -z "$branches" ] ||
[ -n "$withdeps" ] ||
return 0
320 [ -n "$withdeps" ] || origbranches
="$(navigate_deps -s=-1 | paste -d ' ' -s -)"
321 for onehead
in $origbranches; do
322 case "$exclude" in *" $onehead "*) continue; esac
323 needs_update_check
$onehead
325 aheadlist
=" $needs_update_ahead "
333 [ "$name" != "$curname" ] || current
='>'
335 [ "$name" = "$curname" ] ||
338 ! branch_empty
"$name" $from || nonempty
='0'
340 [ -z "$base_remote" ] || remote
='l'
341 ! has_remote
"$name" || remote
='r'
343 [ "$remote" != 'r' ] ||
! ref_exists
"refs/remotes/$base_remote/${topbases#heads/}/$name" ||
{
344 branch_contains
"refs/$topbases/$name" "refs/remotes/$base_remote/${topbases#heads/}/$name" &&
345 branch_contains
"refs/heads/$name" "refs/remotes/$base_remote/$name"
347 [ "$remote" != 'r' -o "$rem_update" = 'R' ] ||
{
348 branch_contains
"refs/remotes/$base_remote/$name" "refs/heads/$name" 2>/dev
/null
350 needs_update_check
"$name"
352 ! vcontains needs_update_behind
"$name" || deps_update
='D'
354 ! vcontains needs_update_partial
"$name" || deps_missing
='!'
356 branch_contains
"refs/heads/$name" "refs/$topbases/$name" || base_update
='B'
358 case "$aheadlist" in *" $name "*) ahead
='*'; esac
360 printf '%-8s %s\n' "$current$nonempty$remote$rem_update$deps_update$deps_missing$base_update$ahead" \
364 if [ -n "$terse" ]; then
366 [ -z "$tg_read_only" ] ||
[ -z "$tg_ref_cache" ] ||
! [ -s "$tg_ref_cache" ] ||
367 refslist
="-r=\"$tg_ref_cache\""
368 cmd
="run_awk_topgit_msg --list"
369 [ $verbose -lt 2 ] || cmd
="run_awk_topgit_msg -c -nokind"
370 [ $verbose -gt 0 ] || cmd
="run_awk_topgit_branches -n"
371 eval "$cmd" "$refslist" '-i="$branches" -x="$exclude" "refs/$topbases"'
376 [ -n "$graphviz$sort" ] || compute_ahead_list
380 case "$exclude" in *" $name "*) continue; esac
381 if [ -n "$graphviz$sort" ]; then
383 [ "$name" = "$curname" ] ||
385 cat_file
"refs/heads/$name:.topdeps" $from |
while read -r dep ||
[ -n "$dep" ]; do
387 ref_exists
"refs/$topbases/$dep" ||
389 [ -z "$tgish" ] ||
[ "$dep_is_tgish" = "true" ] ||
continue
390 if ! "$dep_is_tgish" ||
! branch_annihilated
$dep; then
391 if [ -n "$graphviz" ]; then
392 echo "\"$name\" -> \"$dep\";"
393 if [ "$name" = "$curname" ] ||
[ "$dep" = "$curname" ]; then
394 echo "\"$curname\" [style=filled,fillcolor=yellow];"
397 echo "$name $dep" >&4
408 if (msgsfile != "") {
409 while ((e = (getline msg <msgsfile)) > 0) {
410 gsub(/[ \t]+/, " ", msg)
412 if (split(msg, scratch, " ") < 2 ||
413 scratch[1] == "" || scratch[2] == "") continue
414 msg = substr(msg, length(scratch[1]) + 2)
415 msgs[scratch[1]] = msg
421 name = substr($0, 10)
422 if (name != "" && name in msgs)
423 printf "%-39s\t%s\n", $0, msgs[name]
428 cmd
='get_branch_list | process_branches'
429 [ -z "$msgsfile" ] || cmd
="$cmd"' | awk -v msgsfile="$msgsfile" "$awkpgm"'
432 if [ -n "$graphviz" ]; then
436 if [ -n "$sort" ]; then