tg: avoid passing '--' options terminator to git cat-file
[topgit/pro.git] / tg-log.sh
blob7d6b3b1aa9694eafde9e3439f49281f376e72142
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # (c) Petr Baudis <pasky@suse.cz> 2008
4 # (c) Bert Wesarg <Bert.Wesarg@googlemail.com> 2009
5 # GPLv2
7 name=
10 ## Parse options
12 logcmd="log"
14 while [ -n "$1" ]; do
15 arg="$1"
16 case "$arg" in
17 --)
18 case "$2" in
19 -*)
20 shift; break;;
22 break;;
23 esac;;
24 -|-h|--help)
25 echo "Usage: ${tgname:-tg} [...] log [--compact] [<name>] [--] [<git-log-option>...]" >&2
26 exit 1;;
27 --compact)
28 logcmd="log-compact";;
29 --command=?*)
30 logcmd="${arg#--command=}";;
31 -?*)
32 if v_verify_topgit_branch test "$arg" -f; then
33 [ -z "$name" ] || die "name already specified ($name)"
34 name="$arg"
35 else
36 break
37 fi;;
39 [ -z "$name" ] || die "name already specified ($name)"
40 name="$arg";;
41 esac
42 shift
43 done
45 v_verify_topgit_branch name "${name:-HEAD}"
46 base_rev="$(git rev-parse --short --verify "refs/$topbases/$name^0" -- 2>/dev/null)" ||
47 die "not a TopGit-controlled branch"
48 depcnt="$(git cat-file blob "refs/heads/$name:.topdeps" 2>/dev/null | awk 'END {print NR}')"
49 nomerges=--no-merges
50 [ "$depcnt" -gt 0 ] || nomerges=
52 hasdd=
53 for a; do
54 [ "$a" != "--" ] || { hasdd=1; break; }
55 done
56 if [ -z "$hasdd" ]; then
57 git $logcmd --first-parent $nomerges "$@" "refs/$topbases/$name".."$name"
58 else
59 cmd='git $logcmd --first-parent $nomerges'
60 while [ $# -gt 0 ] && [ "$1" != "--" ]; do
61 cmd="$cmd $(quotearg "$1")"
62 shift
63 done
64 cmd="$cmd $(quotearg "refs/$topbases/$name".."$name")"
65 while [ $# -gt 0 ]; do
66 cmd="$cmd $(quotearg "$1")"
67 shift
68 done
69 eval "$cmd"