tg.sh: next version is 0.16.1
[topgit/pro.git] / tg-patch.sh
blobbe8e74e79f0189a907ab94d49b54579d92ebc803
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # (c) Petr Baudis <pasky@suse.cz> 2008
4 # GPLv2
6 name=
7 head_from=
8 binary=
10 ## Parse options
12 while [ -n "$1" ]; do
13 arg="$1"; shift
14 case "$arg" in
15 -i|-w)
16 [ -z "$head_from" ] || die "-i and -w are mutually exclusive"
17 head_from="$arg";;
18 --binary)
19 binary=1;;
20 -*)
21 echo "Usage: ${tgname:-tg} [...] patch [-i | -w] [--binary] [<name>]" >&2
22 exit 1;;
24 [ -z "$name" ] || die "name already specified ($name)"
25 name="$arg";;
26 esac
27 done
29 head="$(git symbolic-ref HEAD)"
30 head="${head#refs/heads/}"
32 [ -n "$name" ] ||
33 name="${head:-HEAD}"
34 name="$(verify_topgit_branch "$name")"
35 base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
36 die "not a TopGit-controlled branch"
38 if [ -n "$head_from" ] && [ "$name" != "$head" ]; then
39 die "$head_from makes only sense for the current branch"
44 USE_PAGER_TYPE=diff
45 setup_pager
46 # We now collect the rest of the code in this file into a block
47 # so we can redirect the output to the pager.
50 # put out the commit message
51 # and put an empty line out, if the last one in the message was not an empty line
52 # and put out "---" if the commit message does not have one yet
53 cat_file "$name:.topmsg" $head_from |
54 awk '
55 /^---/ {
56 has_3dash=1;
59 need_empty = 1;
60 if ($0 == "")
61 need_empty = 0;
62 print;
64 END {
65 if (need_empty)
66 print "";
67 if (!has_3dash)
68 print "---";
72 b_tree=$(pretty_tree "$name" -b)
73 t_tree=$(pretty_tree "$name" $head_from)
75 if [ $b_tree = $t_tree ]; then
76 echo "No changes."
77 else
78 git diff-tree -p --stat ${binary:+--binary} $b_tree $t_tree
81 echo '-- '
82 echo "$tgname: ($base_rev..) $name (depends on: $(cat_file "$name:.topdeps" $head_from 2>/dev/null | paste -s -d ' ' -))"
83 branch_contains "$name" "$base_rev" ||
84 echo "$tgname: The patch is out-of-date wrt. the base! Run \`$tgdisplay update\`."
86 } | eval "$TG_PAGER"
87 # ... and then we pipe all the output through the pager
89 # vim:noet