tg import: Remove tg_ prefixes from functions
[topgit.git] / tg-patch.sh
blob7a2471827d1e27db9a520f51541cecc4dd69c12a
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # (c) Petr Baudis <pasky@suse.cz> 2008
4 # GPLv2
6 name=
9 ## Parse options
11 while [ -n "$1" ]; do
12 arg="$1"; shift
13 case "$arg" in
14 -*)
15 echo "Usage: tg [...] patch [NAME]" >&2
16 exit 1;;
18 [ -z "$name" ] || die "name already specified ($name)"
19 name="$arg";;
20 esac
21 done
23 [ -n "$name" ] || name="$(git symbolic-ref HEAD | sed 's#^refs/heads/##')"
24 base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
25 die "not a TopGit-controlled branch"
27 git cat-file blob "$name:.topmsg"
28 echo
29 [ -n "$(git grep '^[-]--' "$name" -- ".topmsg")" ] || echo '---'
31 # Evil obnoxious hack to work around the lack of git diff --exclude
32 git_is_stupid="$(mktemp -t tg-patch-changes.XXXXXX)"
33 git diff-tree --name-only "$base_rev" "$name" |
34 fgrep -vx ".topdeps" |
35 fgrep -vx ".topmsg" >"$git_is_stupid" || : # fgrep likes to fail randomly?
36 if [ -s "$git_is_stupid" ]; then
37 cat "$git_is_stupid" | xargs git diff --patch-with-stat "$base_rev" "$name" --
38 else
39 echo "No changes."
41 rm "$git_is_stupid"
43 echo '-- '
44 echo "tg: ($base_rev..) $name (depends on: $(git cat-file blob "$name:.topdeps" | paste -s -d' '))"
45 branch_contains "$name" "$base_rev" ||
46 echo "tg: The patch is out-of-date wrt. the base! Run \`$tg update\`."