Skip to content

Commit

Permalink
tg: previous to next overhaul
Browse files Browse the repository at this point in the history
Completely overhaul tg-next.sh and tg-prev.sh.

They now navigate exactly as expected and can move
in increments of other than one step at a time.

They can also show the containing series name(s) of
the result(s) with --verbose (aka -v).

They are the "show, but don't go" versions of the
"tg checkout" command's "next" and "previous" options.

The "tg info" command provides the ability to view
a specific branch's immediate dependencies or
dependents if desired, but that is not the purpose
of the "tg next" and "tg prev" commands.

Signed-off-by: Kyle J. McKay <[email protected]>
  • Loading branch information
mackyle committed Mar 31, 2017
1 parent 203bb59 commit 9d1e18b
Show file tree
Hide file tree
Showing 3 changed files with 213 additions and 72 deletions.
28 changes: 23 additions & 5 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -1858,24 +1858,42 @@ tg revert

tg prev
~~~~~~~
Outputs the direct dependencies for the current or named branch.
Output the "previous" branch(es) in the patch series containing the
current or named branch. The "previous" branch(es) being one step
away by default.

Options:
-i show dependencies based on index instead of branch
-w show dependencies based on working tree instead of branch
-n <steps> take ``<steps>`` "previous" steps (default 1)
--all take as many "previous" steps as possible (aka ``-a``)
--verbose show containing series name(s) (aka ``-v``)

See also NAVIGATION_.
The ``-n`` option may also be given as ``--count`` or ``--count=<n>``.

To list all dependencies of a branch see the ``--deps`` option of
the `tg info`_ command.

See also NAVIGATION_ for full details on "previous" steps.

tg next
~~~~~~~
Outputs all branches which directly depend on the current or
named branch.
Output tne "next" branch(es) in the patch series containing the current
or named branch. The "next" branch(es) being one step away by default.

Options:
-i show dependencies based on index instead of branch
-w show dependencies based on working tree instead of branch
-n <steps> take ``<steps>`` "next" steps (default 1)
--all take as many "next" steps as possible (aka ``-a``)
--verbose show containing series name(s) (aka ``-v``)

See also NAVIGATION_.
The ``-n`` option may also be given as ``--count`` or ``--count=<n>``.

To list all dependents of a branch see the ``--dependents`` option of
the `tg info`_ command.

See also NAVIGATION_ for full details on "next" steps.

tg migrate-bases
~~~~~~~~~~~~~~~~
Expand Down
127 changes: 94 additions & 33 deletions tg-next.sh
Original file line number Diff line number Diff line change
@@ -1,43 +1,104 @@
#!/bin/sh
# TopGit - A different patch queue manager
# (c) Petr Baudis <[email protected]> 2008
# (c) Bert Wesarg <[email protected]> 2009
# GPLv2
# Copyright (C) 2008 Petr Baudis <[email protected]>
# Copyright (C) 2009 Bert Wesarg <[email protected]>
# Copyright (C) 2017 Kyle J. McKay <[email protected]>
# All rights reserved
# License GPLv2

name=
head_from=
USAGE="\
Usage: ${tgname:-tg} [...] next [-v] [-i | -w] [-a | -n <steps>] [<name>]"

usage()
{
[ -z "$2" ] || printf '%s\n' "$2" >&2
if [ "${1:-0}" != 0 ]; then
printf '%s\n' "$USAGE" >&2
else
printf '%s\n' "$USAGE"
fi
exit ${1:-0}
}

## Parse options
script='
NF == 1 { print }
NF > 1 {
names = ""
for (i = 2; i <= NF; ++i) names = names ", " $i
print $1 " [" substr(names, 3) "]"
}'

while [ -n "$1" ]; do
arg="$1"; shift
case "$arg" in
-i|-w)
[ -z "$head_from" ] || die "-i and -w are mutually exclusive"
head_from="$arg";;
-*)
echo "Usage: ${tgname:-tg} [...] next [-i | -w] [<name>]" >&2
exit 1;;
*)
[ -z "$name" ] || die "name already specified ($name)"
name="$arg";;
esac
done
# Parse options

head="$(git rev-parse --revs-only --abbrev-ref=loose HEAD --)"
[ -n "$name" ] ||
name="$head"
all=
steps=
head_from=
verbose=
aremutex="are mutually exclusive"

non_annihilated_branches |
while read parent; do
from=$head_from
# select .topdeps source for HEAD branch
[ "x$parent" = "x$head" ] ||
from=
docount()
{
case "$2" in
[1-9]*)
[ "$2" = "${2%%[!0-9]*}" ] ||
usage 1 "invalid $1 step count"
steps=$(( 0 + $2 ))
[ "$steps" != "0" ] ||
usage 1 "invalid $1 step count (0 not allowed)"
;;
"")
usage 1 "invalid $1 step count (may not be empty string)"
;;
*)
usage 1 "invalid $1 step count (must be positive number)"
;;
esac
}

cat_file "refs/heads/$parent:.topdeps" $from 2>/dev/null | grep -Fqx "$name" ||
continue
while [ $# -gt 0 ]; do case "$1" in
-h|--help)
usage
;;
-v|--verbose)
verbose=1
;;
-i|-w)
[ -z "$head_from" ] || usage 1 "-i and -w $aremutex"
head_from="$1"
;;
-a|--all)
[ -z "$steps" ] || usage 1 "-a and -n $aremutex"
all=1
;;
--count=*)
[ -z "$all" ] || usage 1 "--count= and -a $aremutex"
docount "--count=" "${1#--count=}"
;;
--count|-n)
[ -z "$all" ] || usage 1 "$1 and -a $aremutex"
[ $# -ge 2 ] || usage 1 "$1 requires an argument"
docount "$1" "$2"
shift
;;
-?*)
usage 1 "Unknown option: $1"
;;
*)
break
;;
esac; shift; done
[ $# -ne 0 ] || set -- "HEAD"
[ $# -eq 1 ] || usage 1 "at most one branch name argument is allowed"
v_verify_topgit_branch name "$1"
[ -z "$all" ] || steps="-1"
[ -n "$steps" ] || steps="1"

echol "$parent"
done
tdopt=
[ -z "$head_from" ] || v_get_tdopt tdopt "$head_from"
oneopt="-1"
verbcmd=
if [ -n "$verbose" ]; then
oneopt=
verbcmd='| awk "$script"'
fi
eval navigate_deps "$tdopt" "$oneopt" '-n -t -s="$steps" -- "$name"' "$verbcmd"
130 changes: 96 additions & 34 deletions tg-prev.sh
Original file line number Diff line number Diff line change
@@ -1,42 +1,104 @@
#!/bin/sh
# TopGit - A different patch queue manager
# (c) Petr Baudis <[email protected]> 2008
# (c) Bert Wesarg <[email protected]> 2009
# GPLv2
# Copyright (C) 2008 Petr Baudis <[email protected]>
# Copyright (C) 2009 Bert Wesarg <[email protected]>
# Copyright (C) 2017 Kyle J. McKay <[email protected]>
# All rights reserved
# License GPLv2

name=
head_from=
USAGE="\
Usage: ${tgname:-tg} [...] prev [-v] [-i | -w] [-a | -n <steps>] [<name>]"

usage()
{
[ -z "$2" ] || printf '%s\n' "$2" >&2
if [ "${1:-0}" != 0 ]; then
printf '%s\n' "$USAGE" >&2
else
printf '%s\n' "$USAGE"
fi
exit ${1:-0}
}

script='
NF == 1 { print }
NF > 1 {
names = ""
for (i = 2; i <= NF; ++i) names = names ", " $i
print $1 " [" substr(names, 3) "]"
}'

# Parse options

all=
steps=
head_from=
verbose=
aremutex="are mutually exclusive"

## Parse options
docount()
{
case "$2" in
[1-9]*)
[ "$2" = "${2%%[!0-9]*}" ] ||
usage 1 "invalid $1 step count"
steps=$(( 0 + $2 ))
[ "$steps" != "0" ] ||
usage 1 "invalid $1 step count (0 not allowed)"
;;
"")
usage 1 "invalid $1 step count (may not be empty string)"
;;
*)
usage 1 "invalid $1 step count (must be positive number)"
;;
esac
}

while [ -n "$1" ]; do
arg="$1"; shift
case "$arg" in
while [ $# -gt 0 ]; do case "$1" in
-h|--help)
usage
;;
-v|--verbose)
verbose=1
;;
-i|-w)
[ -z "$head_from" ] || die "-i and -w are mutually exclusive"
head_from="$arg";;
-*)
echo "Usage: ${tgname:-tg} [...] prev [-i | -w] [<name>]" >&2
exit 1;;
[ -z "$head_from" ] || usage 1 "-i and -w $aremutex"
head_from="$1"
;;
-a|--all)
[ -z "$steps" ] || usage 1 "-a and -n $aremutex"
all=1
;;
--count=*)
[ -z "$all" ] || usage 1 "--count= and -a $aremutex"
docount "--count=" "${1#--count=}"
;;
--count|-n)
[ -z "$all" ] || usage 1 "$1 and -a $aremutex"
[ $# -ge 2 ] || usage 1 "$1 requires an argument"
docount "$1" "$2"
shift
;;
-?*)
usage 1 "Unknown option: $1"
;;
*)
[ -z "$name" ] || die "name already specified ($name)"
name="$arg";;
esac
done

head="$(git rev-parse --revs-only --abbrev-ref=loose HEAD --)"
[ -n "$name" ] ||
name="${head:-HEAD}"
name="$(verify_topgit_branch "$name")"
base_rev="$(git rev-parse --short --verify "refs/$topbases/$name" -- 2>/dev/null)" ||
die "not a TopGit-controlled branch"

# select .topdeps source for HEAD branch
[ "x$name" = "x$head" ] ||
head_from=

cat_file "refs/heads/$name:.topdeps" $head_from | while read dep; do
ref_exists "refs/$topbases/$dep" && branch_annihilated "$dep" && continue
echol "$dep"
done
break
;;
esac; shift; done
[ $# -ne 0 ] || set -- "HEAD"
[ $# -eq 1 ] || usage 1 "at most one branch name argument is allowed"
v_verify_topgit_branch name "$1"
[ -z "$all" ] || steps="-1"
[ -n "$steps" ] || steps="1"

tdopt=
[ -z "$head_from" ] || v_get_tdopt tdopt "$head_from"
oneopt="-1"
verbcmd=
if [ -n "$verbose" ]; then
oneopt=
verbcmd='| awk "$script"'
fi
eval navigate_deps "$tdopt" "$oneopt" '-n -t -s="$steps" -r -- "$name"' "$verbcmd"

0 comments on commit 9d1e18b

Please sign in to comment.