tg-export: strip [RELEASE] whenever stripping [BASE]
[topgit/pro.git] / tg-next.sh
blobe691cc1893534d83f4e7b66dad6a5e844be3f5b5
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # Copyright (C) 2008 Petr Baudis <pasky@suse.cz>
4 # Copyright (C) 2009 Bert Wesarg <Bert.Wesarg@googlemail.com>
5 # Copyright (C) 2017 Kyle J. McKay <mackyle@gmail.com>
6 # All rights reserved
7 # License GPLv2
9 USAGE="\
10 Usage: ${tgname:-tg} [...] next [-v] [-i | -w] [-a | -n <steps>] [<name>]"
12 usage()
14 [ -z "$2" ] || printf '%s\n' "$2" >&2
15 if [ "${1:-0}" != 0 ]; then
16 printf '%s\n' "$USAGE" >&2
17 else
18 printf '%s\n' "$USAGE"
20 exit ${1:-0}
23 script='
24 NF == 1 { print }
25 NF > 1 {
26 names = ""
27 for (i = 2; i <= NF; ++i) names = names ", " $i
28 print $1 " [" substr(names, 3) "]"
31 # Parse options
33 all=
34 steps=
35 head_from=
36 verbose=
37 aremutex="are mutually exclusive"
39 docount()
41 case "$2" in
42 [1-9]*)
43 [ "$2" = "${2%%[!0-9]*}" ] ||
44 usage 1 "invalid $1 step count"
45 steps=$(( 0 + $2 ))
46 [ "$steps" != "0" ] ||
47 usage 1 "invalid $1 step count (0 not allowed)"
49 "")
50 usage 1 "invalid $1 step count (may not be empty string)"
53 usage 1 "invalid $1 step count (must be positive number)"
55 esac
58 while [ $# -gt 0 ]; do case "$1" in
59 -h|--help)
60 usage
62 -v|--verbose)
63 verbose=1
65 -i|-w)
66 [ -z "$head_from" ] || usage 1 "-i and -w $aremutex"
67 head_from="$1"
69 -a|--all)
70 [ -z "$steps" ] || usage 1 "-a and -n $aremutex"
71 all=1
73 --count=*)
74 [ -z "$all" ] || usage 1 "--count= and -a $aremutex"
75 docount "--count=" "${1#--count=}"
77 --count|-n)
78 [ -z "$all" ] || usage 1 "$1 and -a $aremutex"
79 [ $# -ge 2 ] || usage 1 "$1 requires an argument"
80 docount "$1" "$2"
81 shift
83 -?*)
84 usage 1 "Unknown option: $1"
87 break
89 esac; shift; done
90 [ $# -ne 0 ] || set -- "HEAD"
91 [ $# -eq 1 ] || usage 1 "at most one branch name argument is allowed"
92 v_verify_topgit_branch name "$1"
93 [ -z "$all" ] || steps="-1"
94 [ -n "$steps" ] || steps="1"
96 tdopt=
97 [ -z "$head_from" ] || v_get_tdopt tdopt "$head_from"
98 oneopt="-1"
99 verbcmd=
100 if [ -n "$verbose" ]; then
101 oneopt=
102 verbcmd='| awk "$script"'
104 eval navigate_deps "$tdopt" "$oneopt" '-n -t -s="$steps" -- "$name"' "$verbcmd"