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
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 ));;
45 terse
=1 verbose
=$
(( $verbose + 1 ));;
47 verbose
=$
(( $verbose + 2 ));;
49 terse
=1 verbose
=$
(( $verbose + 2 ));;
50 --heads|
--topgit-heads)
64 --without-deps|
--no-with-deps|
--without-related|
--no-with-related)
90 [ -n "${1#--exclude=}" ] || die
"--exclude= requires a branch name"
91 exclude
="$exclude ${1#--exclude=}";;
94 [ -n "$1" ] && [ "$1" != "--all" ] || die
"--exclude requires a branch name"
95 exclude
="$exclude $1";;
103 [ $# -eq 0 ] || defwithdeps
=1
104 [ -z "$exclude" ] || exclude
="$exclude "
106 [ $# -ne 0 ] ||
[ z
"$head" != z
"" ] || doingall
=1
107 if [ "$1" = "--all" ]; then
108 [ -z "$withdeps" ] || die
"mutually exclusive options given"
109 [ $# -eq 1 ] || usage
115 [ "$heads$rdeps" != "11" ] ||
head=
116 [ $# -ne 0 ] ||
[ -z "$head" ] ||
set -- "$head"
117 [ -z "$defwithdeps" ] ||
[ $# -ne 1 ] ||
{ [ z
"$1" != z
"HEAD" ] && [ z
"$1" != z
"@" ]; } || defwithdeps
=2
119 [ "$terse$heads$headsonly$graphviz$sort$deps$depsonly" = "" ] ||
120 [ "$terse$heads$headsonly$graphviz$sort$deps$depsonly$rdeps" = "1" ] ||
121 { [ "$terse$heads$headsonly$graphviz$sort$deps$depsonly$rdeps" = "11" ] && [ "$heads$rdeps" = "11" ]; } ||
122 die
"mutually exclusive options given"
123 [ -z "$withdeps" ] ||
[ -z "$rdeps$depsonly$heads$headsonly" ] ||
124 die
"mutually exclusive options given"
127 [ "$b" != "--all" ] || usage
128 v_verify_topgit_branch b
"$b"
129 branches
="$branches $b"
134 if [ -n "$branches" ]; then
136 printf '%s\n' $branches |
sort -u
138 printf '%s\n' $branches
141 non_annihilated_branches
145 show_heads_independent
()
147 topics
="$(get_temp topics)"
148 get_branch_list |
sed -e 's,^\(.*\)$,refs/heads/\1 \1,' |
149 git cat-file
--batch-check='%(objectname) %(rest)' |
150 sort -u -b -k1,1 >"$topics"
151 git merge-base
--independent $
(cut
-d ' ' -f 1 <"$topics") |
152 sort -u -b -k1,1 |
join - "$topics" |
sort -u -b -k2,2 |
153 while read rev name
; do
154 case "$exclude" in *" $name "*) continue; esac
155 printf '%s\n' "$name"
161 [ -z "$head_from" ] ||
[ -n "$with_deps_opts" ] ||
162 v_get_tdopt with_deps_opts
"$head_from"
163 if [ -n "$branches" ]; then
164 eval navigate_deps
"$with_deps_opts" -s=-1 -1 -- '"$branches"' |
sort
166 eval navigate_deps
"$with_deps_opts" -s=-1
168 while read -r name
; do
169 case "$exclude" in *" $name "*) continue; esac
170 printf '%s\n' "$name"
176 if [ -n "$headsindep" ]; then
177 show_heads_independent
"$@"
179 show_heads_topgit
"$@"
183 if [ -n "$heads" ] && [ -z "$rdeps" ]; then
188 # if $1 is non-empty, show the dep only (including self), not the edge (no self)
191 [ -z "$head_from" ] ||
[ -n "$with_deps_opts" ] ||
192 v_get_tdopt with_deps_opts
"$head_from"
193 if [ -n "$branches" ]; then
195 [ -z "$1" ] || edgenum
=1
197 recurse_deps_exclude
="$exclude"
198 recurse_deps_internal
-n ${tgish:+-t} -m ${1:+-s} -e=$edgenum -- $branches |
sort -u
201 [ -z "$1" ] || cutcmd
='| cut -d " " -f 2 | sort -u'
203 [ -z "$tg_read_only" ] ||
[ -z "$tg_ref_cache" ] ||
! [ -s "$tg_ref_cache" ] ||
204 refslist
="-r=\"$tg_ref_cache\""
206 eval run_awk_topgit_deps
"$refslist" "$with_deps_opts" "${tgish:+-t}" \
207 "${1:+-s}" '-n -x="$exclude" "refs/$topbases"' "$cutcmd"
211 if [ -n "$deps$depsonly$sort" ]; then
212 eval show_deps
$depsonly "${sort:+|tsort}"
216 if [ -n "$rdeps" ]; then
219 recurse_deps_exclude
="$exclude"
221 v_get_tdopt with_deps_opts
"$head_from"
223 if [ -n "$heads" ]; then
228 } |
while read -r b
; do
229 case "$exclude" in *" $b "*) continue; esac
230 ref_exists
"refs/heads/$b" ||
continue
231 [ -z "$showbreak" ] ||
echo
233 recurse_deps_internal
${tgish:+-t} -n -s ${rdepsonce:+-o=-1} "$b" |
234 awk -v elided
="$rdepsonce" '{
235 if ($1 == "1" || NF < 5) next
238 if ($6 != "") haschild[$6] = 1
239 sub(/^[^ ]+ +[^ ]+ +[^ ]+ +[^ ]+ +[^ ]+/, "")
242 if (elided && xvisits > 0 && haschild[dep]) xtra="^"
249 if [ -n "$headsonly" ]; then
251 branches
="$(show_heads)"
254 [ -n "$withdeps" ] || withdeps
="$defwithdeps"
255 if [ -z "$doingall$terse$graphviz$sort$withdeps$branches" ]; then
256 branches
="$(tg info --heads 2>/dev/null | paste -d " " -s -)" ||
:
257 [ -z "$branches" ] || withdeps
=1
259 [ "$withdeps" != "0" ] || withdeps
=
260 if [ -n "$withdeps" ]; then
261 v_get_tdopt with_deps_opts
"$head_from"
262 [ "$withdeps" != "2" ] || branches
="$(show_heads_topgit | paste -d " " -s -)"
265 origbranches
="$branches"
266 branches
="$(show_deps 1 | paste -d " " -s -)"
270 if [ -n "$terse" ]; then
272 [ -z "$tg_read_only" ] ||
[ -z "$tg_ref_cache" ] ||
! [ -s "$tg_ref_cache" ] ||
273 refslist
="-r=\"$tg_ref_cache\""
274 cmd
="run_awk_topgit_branches -n"
275 if [ $verbose -gt 0 ]; then
276 v_get_tmopt tm_opt
"$head_from"
277 cmd
="run_awk_topgit_msg --list${tm_opt:+ $tm_opt}"
278 [ $verbose -lt 2 ] || cmd
="run_awk_topgit_msg -c -nokind${tm_opt:+ $tm_opt}"
280 eval "$cmd" "$refslist" '-i="$branches" -x="$exclude" "refs/$topbases"'
284 v_strip_ref curname
"$(git symbolic-ref -q HEAD)"
286 if [ -n "$graphviz" ]; then
288 '# GraphViz output; pipe to:
289 # | dot -Tpng -o <output>
297 label="TopGit Layout\n\n\n"
302 show_deps |
while read -r name dep
; do
303 printf '"%s" -> "%s";\n' "$name" "$dep"
304 if [ "$name" = "$curname" ] ||
[ "$dep" = "$curname" ]; then
305 printf '"%s" [%s];\n' "$curname" "style=filled,fillcolor=yellow"
316 [ -z "$tg_read_only" ] ||
[ -z "$tg_ref_cache" ] ||
! [ -s "$tg_ref_cache" ] ||
317 refslist
="-r=\"$tg_ref_cache\""
318 msgsfile
="$(get_temp msgslist)"
319 v_get_tmopt tm_opt
"$head_from"
320 eval run_awk_topgit_msg
"-nokind${tm_opt:+ $tm_opt}" "$refslist" '"refs/$topbases"' >"$msgsfile"
321 needs_update_check_clear
322 needs_update_check_no_same
=1
323 [ -z "$branches" ] ||
[ -n "$withdeps" ] ||
return 0
324 v_get_tdopt with_deps_opts
"$head_from"
325 [ -n "$withdeps" ] || origbranches
="$(navigate_deps -s=-1 | paste -d ' ' -s -)"
326 for onehead
in $origbranches; do
327 case "$exclude" in *" $onehead "*) continue; esac
328 needs_update_check
$onehead
330 aheadlist
=" $needs_update_ahead "
338 [ "$name" != "$curname" ] || current
='>'
340 [ "$name" = "$curname" ] ||
343 ! branch_empty
"$name" $from || nonempty
='0'
345 [ -z "$base_remote" ] || remote
='l'
346 ! has_remote
"$name" || remote
='r'
348 [ "$remote" != 'r' ] ||
! ref_exists
"refs/remotes/$base_remote/${topbases#heads/}/$name" ||
{
349 branch_contains
"refs/$topbases/$name" "refs/remotes/$base_remote/${topbases#heads/}/$name" &&
350 branch_contains
"refs/heads/$name" "refs/remotes/$base_remote/$name"
352 [ "$remote" != 'r' ] ||
[ "$rem_update" = 'R' ] ||
{
353 branch_contains
"refs/remotes/$base_remote/$name" "refs/heads/$name" 2>/dev
/null
355 needs_update_check
"$name"
357 ! vcontains needs_update_behind
"$name" || deps_update
='D'
359 ! vcontains needs_update_partial
"$name" || deps_missing
='!'
361 branch_contains
"refs/heads/$name" "refs/$topbases/$name" || base_update
='B'
363 case "$aheadlist" in *" $name "*) ahead
='*'; esac
365 printf '%-8s %s\n' "$current$nonempty$remote$rem_update$deps_update$deps_missing$base_update$ahead" \
371 if (msgsfile != "") {
372 while ((e = (getline msg <msgsfile)) > 0) {
373 gsub(/[ \t]+/, " ", msg)
375 if (split(msg, scratch, " ") < 2 ||
376 scratch[1] == "" || scratch[2] == "") continue
377 msg = substr(msg, length(scratch[1]) + 2)
378 msgs[scratch[1]] = msg
384 name = substr($0, 10)
385 if (name != "" && name in msgs)
386 printf "%-39s\t%s\n", $0, msgs[name]
393 cmd
='get_branch_list | while read name; do process_branch; done'
394 [ -z "$msgsfile" ] || cmd
="$cmd"' | awk -v msgsfile="$msgsfile" "$awkpgm"'