chiark / gitweb /
Clean up Series.refresh_patch
[stgit] / contrib / stg-gitk
CommitLineData
cdd071ff
YD
1#!/bin/sh
2set -e
3
4# stg-gitk - helper script to graphically display an StGIT stack
5
6# Displays given branches and stacks, without getting disturbed by
7# patch logs.
8
9# LIMITATIONS:
cdd071ff
YD
10# - no support for spaces in branch names
11
12# Copyright (c) 2007 Yann Dirson <ydirson@altern.org>
13# Subject to the GNU GPL, version 2.
14
15usage()
16{
17 echo "Usage: $(basename $0) [<branches>|--all]"
18 exit 1
19}
20
21allbranches=0
ab2e0574
YD
22refsonly=0
23while [ "$#" -gt 0 ]; do
24 case "$1" in
25 --refs) refsonly=1 ;;
26 --all) allbranches=1 ;;
27 --*) usage ;;
28 *) break ;;
29 esac
30 shift
31done
cdd071ff
YD
32
33if [ $allbranches = 1 ] && [ "$#" -gt 0 ]; then
34 usage
35fi
36
37GIT_DIR=$(git-rev-parse --git-dir)
38GIT_DIR_SPKIPLEN=$(printf "$GIT_DIR/X" | wc -c)
39
40refdirs=''
41if [ $allbranches = 1 ]; then
42 refdirs="$GIT_DIR/refs"
43else
44 if [ "$#" = 0 ]; then
45 set -- "$(stg branch)"
46 fi
47
48 for b in "$@"; do
49 if [ -e "$GIT_DIR/refs/patches/$b" ]; then
50 # StGIT branch: show all patches
51 refdirs="$refdirs $GIT_DIR/refs/heads/$b $GIT_DIR/refs/patches/$b"
52 elif [ -e "$GIT_DIR/refs/heads/$b" ]; then
53 # other GIT branch
54 refdirs="$refdirs $GIT_DIR/refs/heads/$b"
55 elif [ $(git-for-each-ref "refs/$b" | wc -l) != 0 ]; then
56 # other ref
57 refdirs="$refdirs $(git-for-each-ref --format="$GIT_DIR/%(refname)" "refs/$b")"
58 else
59 echo >&2 "ERROR: no such ref '$b'"
60 usage
61 fi
62 done
63fi
64
ab2e0574
YD
65printrefs()
66{
67 find $refdirs -type f -not -name '*.log' | cut -c${GIT_DIR_SPKIPLEN}-
68}
69
70if [ $refsonly = 1 ]; then
71 printrefs
72elif grep -q -- --argscmd $(which gitk); then
73 # This gitk supports --argscmd.
74 # Let's use a hack to pass --all, which was consumed during command-line parsing
75 if [ $allbranches = 1 ]; then
76 gitk --argscmd="$0 --refs --all"
77 else
78 gitk --argscmd="$0 --refs $*"
79 fi
80else
81 # This gitk does not support --argscmd, just compute refs onces
82 gitk $(printrefs)
83fi