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] [--exclude branch]... [--all | branch...]" >&2
38 [ -z "$head_from" ] || die
"-i and -w are mutually exclusive"
43 verbose
=$
(( $verbose + 1 ));;
44 --heads|
--topgit-heads)
55 --without-deps|
--no-with-deps)
81 [ -n "${1#--exclude=}" ] || die
"--exclude= requires a branch name"
82 exclude
="$exclude ${1#--exclude=}";;
85 [ -n "$1" -a "$1" != "--all" ] || die
"--exclude requires a branch name"
86 exclude
="$exclude $1";;
94 [ $# -eq 0 ] || defwithdeps
=1
95 [ -z "$exclude" ] || exclude
="$exclude "
97 [ $# -ne 0 ] ||
[ z
"$head" != z
"" ] || doingall
=1
98 if [ "$1" = "--all" ]; then
99 [ -z "$withdeps" ] || die
"mutually exclusive options given"
100 [ $# -eq 1 ] || usage
106 [ "$heads$rdeps" != "11" ] ||
head=
107 [ $# -ne 0 -o -z "$head" ] ||
set -- "$head"
109 [ "$terse$heads$headsonly$graphviz$sort$deps$depsonly" = "" ] ||
110 [ "$terse$heads$headsonly$graphviz$sort$deps$depsonly$rdeps" = "1" ] ||
111 [ "$terse$heads$headsonly$graphviz$sort$deps$depsonly$rdeps" = "11" -a "$heads$rdeps" = "11" ] ||
112 die
"mutually exclusive options given"
113 [ -z "$withdeps" -o -z "$rdeps$depsonly$heads$headsonly" ] ||
114 die
"mutually exclusive options given"
117 [ "$b" != "--all" ] || usage
118 branches
="$branches $(verify_topgit_branch "$b")"
123 if [ -n "$branches" ]; then
125 printf '%s\n' $branches |
sort -u
127 printf '%s\n' $branches
130 non_annihilated_branches
134 show_heads_independent
()
136 topics
="$(get_temp topics)"
137 get_branch_list |
sed -e 's,^\(.*\)$,refs/heads/\1 \1,' |
138 git cat-file
--batch-check='%(objectname) %(rest)' |
139 sort -u -b -k1,1 >"$topics"
140 git merge-base
--independent $
(cut
-d ' ' -f 1 <"$topics") |
141 sort -u -b -k1,1 |
join - "$topics" |
sort -u -b -k2,2 |
142 while read rev name
; do
143 case "$exclude" in *" $name "*) continue; esac
144 printf '%s\n' "$name"
150 if [ -n "$branches" ]; then
151 navigate_deps
-s=-1 -1 -- "$branches" |
sort
155 while read -r name
; do
156 case "$exclude" in *" $name "*) continue; esac
157 printf '%s\n' "$name"
163 if [ -n "$headsindep" ]; then
164 show_heads_independent
"$@"
166 show_heads_topgit
"$@"
170 if [ -n "$heads" -a -z "$rdeps" ]; then
177 case "$exclude" in *" $_dep "*) return; esac
178 case " $seen_deps " in *" $_dep "*) return 0; esac
179 seen_deps
="${seen_deps:+$seen_deps }$_dep"
180 [ -z "$tgish" -o -n "$_dep_is_tgish" ] ||
return 0
181 [ -z "$skip_ann" ] ||
[ -z "$_dep_annihilated" ] && printf '%s\n' "$_dep"
188 recurse_deps_exclude
=
189 get_branch_list |
while read _b
; do
190 case "$exclude" in *" $_b "*) continue; esac
191 case " $recurse_deps_exclude " in *" $_b "*) continue; esac
193 save_skip
="$skip_ann"
194 _dep
="$_b"; _dep_is_tgish
=1; skip_ann
=; show_dep
; skip_ann
="$save_skip"
195 recurse_deps show_dep
"$_b"
196 recurse_deps_exclude
="$recurse_deps_exclude $seen_deps"
200 if [ -n "$depsonly" ]; then
201 show_deps |
sort -u -b -k1,1
207 case "$exclude" in *" $_dep "*) return; esac
208 [ -z "$tgish" -o -n "$_dep_is_tgish" ] ||
return 0
210 [ -z "$rdepsonce" ] ||
[ "$_dep_xvisits" = 0 ] || elided
="^"
211 printf '%s %s\n' "$_depchain" "$_dep$elided"
214 if [ -n "$rdeps" ]; then
218 if [ -n "$heads" ]; then
224 case "$exclude" in *" $b "*) continue; esac
225 [ -z "$showbreak" ] ||
echo
227 ref_exists
"refs/heads/$b" ||
continue
231 recurse_deps
${rdepsonce:+-o=-o=-1} show_rdeps
"$b"
232 } |
sed -e 's/[^ ][^ ]*[ ]/ /g'
237 if [ -n "$deps" ]; then
238 if [ -n "$branches" ]; then
240 recurse_deps_exclude
="$exclude"
241 recurse_deps_internal
-n -t -m -e=2 -- $branches |
sort -u
244 [ -z "$tg_read_only" ] ||
[ -z "$tg_ref_cache" ] ||
! [ -s "$tg_ref_cache" ] ||
245 refslist
="-r=\"$tg_ref_cache\""
247 v_get_tdopt tdopt
"$head_from"
248 eval run_awk_topgit_deps
"$refslist" "$tdopt" '-n -t -x="$exclude" "refs/$topbases"'
253 if [ -n "$headsonly" ]; then
255 branches
="$(show_heads)"
258 [ -n "$withdeps" ] || withdeps
="$defwithdeps"
259 if [ -z "$doingall$terse$graphviz$sort$withdeps$branches" ]; then
260 branches
="$(tg info --heads 2>/dev/null | paste -d " " -s -)" ||
:
261 [ -z "$branches" ] || withdeps
=1
263 [ "$withdeps" != "0" ] || withdeps
=
264 if [ -n "$withdeps" ]; then
267 origbranches
="$branches"
268 branches
="$(skip_ann=1; show_deps | sort -u -b -k1,1 | paste -d " " -s -)"
272 curname
="$(strip_ref "$
(git symbolic-ref
-q HEAD
)")" ||
:
274 if [ -n "$graphviz" ]; then
276 # GraphViz output; pipe to:
277 # | dot -Tpng -o <output>
285 label="TopGit Layout\n\n\n"
294 if [ -n "$sort" ]; then
295 tsort_input
="$(get_temp tg-summary-sort)"
307 [ -z "$branches" ] ||
[ -n "$withdeps" ] ||
return 0
308 [ -n "$withdeps" ] || origbranches
="$(tg summary --topgit-heads | paste -d ' ' -s -)"
309 aheadfile
="$(get_temp aheadlist)"
310 savebr
="$base_remote"
314 for onehead
in $origbranches; do
315 case "$exclude" in *" $onehead "*) continue; esac
316 case "$processed" in *" $onehead "*) continue; esac
317 processed
="${processed}$onehead "
318 needs_update
"$onehead" || needslist
="${needslist}$onehead "
321 base_remote
="$savebr"
322 aheadlist
=" $(cut -d ' ' -f 1 <"$aheadfile" | sort -u | paste -d ' ' -s -) "
330 [ "$name" != "$curname" ] || current
='>'
332 [ "$name" = "$curname" ] ||
335 ! branch_empty
"$name" $from || nonempty
='0'
337 [ -z "$base_remote" ] || remote
='l'
338 ! has_remote
"$name" || remote
='r'
340 [ "$remote" != 'r' ] ||
! ref_exists
"refs/remotes/$base_remote/${topbases#heads/}/$name" ||
{
341 branch_contains
"refs/$topbases/$name" "refs/remotes/$base_remote/${topbases#heads/}/$name" &&
342 branch_contains
"refs/heads/$name" "refs/remotes/$base_remote/$name"
344 [ "$remote" != 'r' -o "$rem_update" = 'R' ] ||
{
345 branch_contains
"refs/remotes/$base_remote/$name" "refs/heads/$name" 2>/dev
/null
350 case "$needslist" in *" $name "*) deps_update
='D'; esac;;
352 needs_update
"$name" >/dev
/null || deps_update
='D';;
355 [ -z "$missing_deps" ] || deps_missing
='!'
357 branch_contains
"refs/heads/$name" "refs/$topbases/$name" || base_update
='B'
359 case "$aheadlist" in *" $name "*) ahead
='*'; esac
361 if [ "$(ref_exists_rev "refs
/heads
/$name")" != "$(ref_exists_rev "refs
/$topbases/$name")" ]; then
362 subject
="$(cat_file "refs
/heads
/$name:.topmsg
" $from | sed -n 's/^Subject: //p')"
365 subject
="(No commits)"
368 printf '%-8s %-30s\t%s\n' "$current$nonempty$remote$rem_update$deps_update$deps_missing$base_update$ahead" \
372 if [ -n "$terse" ]; then
374 [ -z "$tg_read_only" ] ||
[ -z "$tg_ref_cache" ] ||
! [ -s "$tg_ref_cache" ] ||
375 refslist
="-r=\"$tg_ref_cache\""
376 cmd
="run_awk_topgit_msg --list"
377 [ $verbose -lt 2 ] || cmd
="run_awk_topgit_msg -c -nokind"
378 [ $verbose -gt 0 ] || cmd
="run_awk_topgit_branches -n"
379 eval "$cmd" "$refslist" '-i="$branches" -x="$exclude" "refs/$topbases"'
383 [ -n "$graphviz$sort" ] || compute_ahead_list
386 case "$exclude" in *" $name "*) continue; esac
387 if [ -n "$graphviz$sort" ]; then
389 [ "$name" = "$curname" ] ||
391 cat_file
"refs/heads/$name:.topdeps" $from |
while read -r dep ||
[ -n "$dep" ]; do
393 ref_exists
"refs/$topbases/$dep" ||
395 [ -z "$tgish" ] ||
[ "$dep_is_tgish" = "true" ] ||
continue
396 if ! "$dep_is_tgish" ||
! branch_annihilated
$dep; then
397 if [ -n "$graphviz" ]; then
398 echo "\"$name\" -> \"$dep\";"
399 if [ "$name" = "$curname" ] ||
[ "$dep" = "$curname" ]; then
400 echo "\"$curname\" [style=filled,fillcolor=yellow];"
403 echo "$name $dep" >&4
412 if [ -n "$graphviz" ]; then
416 if [ -n "$sort" ]; then