forked from mackyle/topgit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
3 changed files
with
213 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |