tg.sh: quote problem alternate directory paths
[topgit/pro.git] / tg-info.sh
blobdf88b6ff939135de736ab7bdcfd4f54f7c4bf285
1 #!/bin/sh
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
5 # GPLv2
7 USAGE="Usage: ${tgname:-tg} [...] info [--heads | --leaves] [<name>]"
9 usage()
11 if [ "${1:-0}" != 0 ]; then
12 printf '%s\n' "$USAGE" >&2
13 else
14 printf '%s\n' "$USAGE"
16 exit ${1:-0}
19 ## Parse options
21 heads=
22 leaves=
23 verbose=
25 while [ $# -gt 0 ]; do case "$1" in
26 -h|--help)
27 usage
29 --heads)
30 heads=1
32 --leaves)
33 leaves=1
35 -v|--verbose)
36 verbose=$(( ${verbose:-0} + 1 ))
38 -vv|-vvv|-vvvv|-vvvvv)
39 verbose=$(( ${verbose:-0} + ${#1} - 1 ))
41 -?*)
42 echo "Unknown option: $1" >&2
43 usage 1
46 break
48 esac; shift; done
49 [ "$heads$leaves" != "11" ] || die "mutually exclusive options --heads and --leaves"
50 [ $# -gt 0 ] || set -- HEAD
51 [ $# -eq 1 ] || die "name already specified ($1)"
52 name="$1"
54 process_dep()
56 if [ -n "$_dep_is_tgish" ] && [ -z "$_dep_missing$_dep_annihilated" ]; then
57 printf '%s\n' "$_dep ${_depchain##* }"
61 if [ -n "$heads" ]; then
62 no_remotes=1
63 base_remote=
64 verify="$name"
65 ! test="$(verify_topgit_branch "${name:-HEAD}" -f)" || verify="refs/heads/$test"
66 hash="$(git rev-parse --verify --quiet "$verify" --)" || die "no such ref: $name"
67 depslist="$(get_temp depslist)"
68 $tg summary --topgit-heads |
69 while read -r onetghead; do
70 printf '%s %s\n' "$onetghead" "$onetghead"
71 recurse_deps process_dep "$onetghead"
72 done | LC_ALL=C sort -u >"$depslist"
73 git branch --no-color --contains "$hash" | LC_ALL=C cut -c 3- |
74 LC_ALL=C join -o 2.2 - "$depslist" |
75 LC_ALL=C sort -u
76 exit 0
79 name="$(verify_topgit_branch "${name:-HEAD}")"
80 if [ -n "$leaves" ]; then
81 find_leaves "$name"
82 exit 0
84 base_rev="$(git rev-parse --short --verify "refs/$topbases/$name" -- 2>/dev/null)" ||
85 die "not a TopGit-controlled branch"
87 measure="$(measure_branch "refs/heads/$name" "$base_rev")"
89 echo "Topic Branch: $name ($measure)"
91 nocommits=
92 [ "$(git rev-parse --verify --short "refs/heads/$name" --)" != "$base_rev" ] || nocommits=1
94 [ -n "$nocommits" ] || git cat-file blob "$name:.topmsg" | grep ^Subject: || :
96 # true if $1 is contained by (or the same as) $2
97 contained_by()
99 [ "$(git rev-list --count --max-count=1 "$1" --not "$2" --)" = "0" ]
102 if [ "${verbose:-0}" -ge 1 ]; then
103 scratch="$(get_temp scratch)"
104 printf '%s\n' "$name" >"$scratch"
105 dependents="$(get_temp dependents_list)"
106 $tg summary --deps | sort -k2,2 | join -1 2 - "$scratch" | cut -d ' ' -f 2 | sort -u >"$dependents"
107 if ! [ -s "$dependents" ]; then
108 echo "Dependents: [none]"
109 else
110 if [ "${verbose:-0}" -le 1 ]; then
111 sed '1{ s/^/Dependents: /; n; }; s/^/ /;' <"$dependents"
112 else
113 minwidth=0
114 while read -r endent; do
115 [ ${#endent} -le $minwidth ] || minwidth=${#endent}
116 done <"$dependents"
117 prefix="Dependents:"
118 while read -r endent; do
119 ood=
120 contained_by "refs/heads/$name" "refs/$topbases/$endent" || ood=1
121 if [ -n "$ood" ]; then
122 printf '%s %-*s [needs merge]\n' "$prefix" $minwidth "$endent"
123 else
124 printf '%s %s\n' "$prefix" "$endent"
126 prefix=" "
127 done <"$dependents"
132 if [ -n "$nocommits" ]; then
133 echo "* No commits."
134 exit 0
137 echo "Base: $base_rev"
138 branch_contains "refs/heads/$name" "refs/$topbases/$name" ||
139 echo "* Base is newer than head! Please run \`$tgdisplay update\`."
141 if has_remote "$name"; then
142 echo "Remote Mate: $base_remote/$name"
143 branch_contains "refs/$topbases/$name" "refs/remotes/$base_remote/${topbases#heads/}/$name" ||
144 echo "* Local base is out of date wrt. the remote base."
145 branch_contains "refs/heads/$name" "refs/remotes/$base_remote/$name" ||
146 echo "* Local head is out of date wrt. the remote head."
147 branch_contains "refs/remotes/$base_remote/$name" "refs/heads/$name" ||
148 echo "* Local head is ahead of the remote head."
151 git cat-file blob "$name:.topdeps" 2>/dev/null |
152 sed '1{ s/^/Depends: /; n; }; s/^/ /;'
154 depcheck="$(get_temp tg-depcheck)"
155 missing_deps=
156 needs_update "$name" >"$depcheck" || :
157 if [ -n "$missing_deps" ]; then
158 echo "MISSING: $missing_deps"
160 depcheck2="$(get_temp tg-depcheck2)"
161 sed '/^!/d' <"$depcheck" >"$depcheck2"
162 if [ -s "$depcheck2" ]; then
163 echo "Needs update from:"
164 # 's/ [^ ]* *$//' -- last is $name
165 # 's/^[:] /:/' -- don't distinguish base updates
166 <"$depcheck2" sed -e 's/ [^ ]* *$//' -e 's/^[:] /:/' |
167 while read dep chain; do
168 case "$dep" in
170 dep="${dep#:}"
171 fulldep="refs/heads/$dep"
172 extradep="refs/$topbases/$dep"
175 extradep=
176 case "$dep" in
177 refs/*)
178 fulldep="$dep";;
180 fulldep="refs/heads/$dep";;
181 esac
183 esac
184 printf '%s' "$dep "
185 [ -n "$chain" ] && printf '%s' "(<= $(echol "$chain" | sed 's/ / <= /')) "
186 printf '%s' "($(eval measure_branch '"$fulldep"' '"refs/heads/$name"' ${extradep:+\"\$extradep\"}))"
187 echo
188 done | sed 's/^/ /'
189 else
190 echo "Up-to-date${missing_deps:+ (except for missing dependencies)}."