2 # TopGit - A different patch queue manager
3 # Copyright (C) Petr Baudis <pasky@suse.cz> 2008
15 bool
="$(git config --get --bool topgit.from 2>/dev/null)" || gec
=$?
16 if [ $gec -eq 128 ]; then
17 fromaddr
="$(git config --get topgit.from 2>/dev/null)" ||
:
18 if [ "$fromaddr" = "quiet" ]; then
21 [ -z "$fromaddr" ] || fixfrom
=1
23 elif [ $gec -eq 0 ]; then
24 [ "$bool" = "false" ] || fixfrom
=1
40 echo "Usage: ${tgname:-tg} [...] patch [-q] [-i | -w] [--binary] [<name>] [--] [<git-diff-tree-option>...]" >&2
43 [ -z "$head_from" ] || die
"-i and -w are mutually exclusive"
54 fixfrom
=1 fromaddr
="${1#--from=}";;
56 if test="$(verify_topgit_branch "$arg" -f)"; then
57 [ -z "$name" ] || die
"name already specified ($name)"
63 [ -z "$name" ] || die
"name already specified ($name)"
69 head="$(git symbolic-ref -q HEAD)" ||
:
70 head="${head#refs/heads/}"
74 name
="$(verify_topgit_branch "$name")"
75 base_rev
="$(git rev-parse --short --verify "refs
/$topbases/$name^
0" -- 2>/dev/null)" ||
76 die
"not a TopGit-controlled branch"
78 if [ -n "$head_from" ] && [ "$name" != "$head" ]; then
79 die
"$head_from makes only sense for the current branch"
83 [ -z "$fixfrom" ] ||
[ -n "$fromaddr" ] ||
{
84 fromaddr
="$(git var GIT_AUTHOR_IDENT)" ||
exit
88 # We now collect the rest of the code in this file into a function
89 # so we can redirect the output to the pager.
93 # put out the commit message
94 # and put an empty line out, if the last one in the message was not an empty line
95 # and put out "---" if the commit message does not have one yet
97 cat_file
"refs/heads/$name:.topmsg" $head_from |
98 awk -v "fixfrom=$fixfrom" -v "fromaddr=$fromaddr" -v "usesob=$usesob" '
100 sub(/^[ \t]+/, "", s)
101 sub(/[ \t]+$/, "", s)
104 function fixident(val, fixmt, _name, _email) {
106 if (!fixmt && val == "") return ""
109 if ((leftangle = index(val, "<")) > 0) {
110 _name=trimfb(substr(val, 1, leftangle - 1))
111 _email=substr(val, leftangle+1)
112 sub(/>[^>]*$/, "", _email)
113 _email=trimfb(_email)
115 if ((atsign = index(val, "@")) > 0) {
116 _name=trimfb(substr(val, 1, atsign - 1))
120 if (_name != "") _email="-"
123 if (!fixmt && _name == "" && _email == "") return ""
124 if (_name == "") _name = "-"
125 if (_email == "") _email = "-"
126 return _name " <" _email ">"
133 fromaddr = fixident(fromaddr)
134 if (fromaddr == "" && !usesob) fixfrom = 0
139 inhdr && /^[Ff][Rr][Oo][Mm][ \t]*:/ {
141 sub(/^[^:]*:/, "", val)
143 if (val != "") sawfrom = 1
144 if (val != "" || !fixfrom) hdrs[++hdrline] = $0
147 inhdr && /^[ \t]*$/ {
151 inhdr { hdrs[++hdrline] = $0; next; }
152 function writehdrs() {
153 if (!sawfrom && fixfrom && fromaddr != "") {
154 print "From: " fromaddr
157 for (i=1; i <= hdrline; ++i) print hdrs[i]
160 /^---/ { has_3dash=1 }
161 usesob && /^[Ss][Ii][Gg][Nn][Ee][Dd]-[Oo][Ff][Ff]-[Bb][Yy][ \t]*:[ \t]*[^ \t]/ {
163 sub(/^[^:]*:/, "", val)
165 if (val != "") fromaddr=val
169 if ($0 == "") need_empty = 0
170 body[++bodyline] = $0
174 for (i = 1; i <= bodyline; ++i) print body[i]
175 if (need_empty) print ""
176 if (!has_3dash) print "---"
177 exit sawfrom ? 0 : 67 # EX_NOUSER
180 if [ "$result" = "67" ]; then
182 echo "### tg: missing From: in .topmsg, 'git am' will barf (use --from to add)" >&2
185 [ "${result:-0}" = "0" ] ||
exit "$result"
187 b_tree
=$
(pretty_tree
-t "$name" -b)
188 t_tree
=$
(pretty_tree
-t "$name" $head_from)
190 if [ $b_tree = $t_tree ]; then
195 [ "$a" != "--" ] ||
{ hasdd
=1; break; }
197 if [ -z "$hasdd" ]; then
198 git diff-tree
-p --stat --summary ${binary:+--binary} "$@" $b_tree $t_tree
200 cmd
="git diff-tree -p --stat --summary ${binary:+--binary}"
201 while [ $# -gt 0 -a "$1" != "--" ]; do
202 cmd
="$cmd $(quotearg "$1")"
205 cmd
="$cmd $(quotearg "$b_tree") $(quotearg "$t_tree")"
206 while [ $# -gt 0 ]; do
207 cmd
="$cmd $(quotearg "$1")"
216 depon
="$(cat_file "refs
/heads
/$name:.topdeps
" $head_from 2>/dev/null | paste -s -d ' ' -)"
217 echo "$tgname: ($base_rev..) $name${depon:+ (depends on: $depon)}"
218 branch_contains
"refs/heads/$name" "refs/$topbases/$name" ||
219 echo "$tgname: The patch is out-of-date wrt. the base! Run \`$tgdisplay update\`."
224 # ... and then we run it through the pager with the page function