initial
[rrq/reviewtool.git] / git-review
1 #!/bin/zsh
2 #
3 # Review commits based on the branch graph
4 #
5
6 N=1
7 if [ $# = 1 ] ; then
8     if [ -e $1 ] ; then
9         FOCUS=$1
10     else
11         N=$1
12     fi
13 elif [ $# = 2 ] ; then
14     N=$1
15     FOCUS=$2
16 fi
17 FMT='--pretty=format:<s:%h>%h %d %s'
18
19 GRAPH="$(git log --graph --full-history "$FMT" --all $FOCUS )"
20
21 PROJECT="$(git rev-parse --show-toplevel| sed 's/.*\///')"
22
23 X=$(echo "$GRAPH" | iselect -t "$PROJECT" -n git-review -p $N -P -K -k/ -kp )
24
25 [ -z "$X" ] && exit 0
26 X=( ${(s[:])X} )
27 N=$X[1]
28 K=$X[2]
29 X=$X[3]
30 if [ "$K" = / ] ; then
31     read "x?Search: "
32     N=${"$(echo "$GRAPH" | grep -nF "$x")"%%:*}
33 elif [ "$K" = "p" ] ; then
34     # previous commit
35     Z=${"$(git rev-parse ${X}~1)"[1,7]}
36     [ -z "$Z" ] || N=${"$(echo "$GRAPH" | grep -nF "$Z")"%%:*}
37 else
38     FOCUS=$FOCUS git-show-i $X~1 $X
39 fi
40 exec $0 $N $FOCUS