{"thread":{"id":"10984","subject":"[StGIT PATCH] stg-gitk: allow passing args to gitk; add --help.","startedAt":"2007-11-22T21:23:34Z","lastAt":"2007-11-22T21:23:34Z","messageCount":1,"participants":["Yann Dirson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"60710","messageId":"20071122212334.3351.4777.stgit@gandelf.nowhere.earth","threadId":"10984","inReplyTo":null,"subject":"[StGIT PATCH] stg-gitk: allow passing args to gitk; add --help.","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2007-11-22T21:23:34Z","receivedAt":"2007-11-22T21:23:34Z","isPatch":true,"sender":{"key":"ydirson@altern.org","avatar":"https://avatars.githubusercontent.com/u/1190950?v=4"},"body":"Quite handy to further limit the commits to be shown.\n---\n\n contrib/stg-gitk |   30 +++++++++++++++++++++---------\n 1 files changed, 21 insertions(+), 9 deletions(-)\n\ndiff --git a/contrib/stg-gitk b/contrib/stg-gitk\nindex 6ddcfb1..cb264e5 100755\n--- a/contrib/stg-gitk\n+++ b/contrib/stg-gitk\n@@ -12,25 +12,31 @@ set -e\n # Copyright (c) 2007 Yann Dirson <ydirson@altern.org>\n # Subject to the GNU GPL, version 2.\n \n+helptext=\"Usage: $(basename $0) [--refs] [<branches>|--all] [-- <gitk args>]\"\n+\n usage()\n {\n-    echo \"Usage: $(basename $0) [<branches>|--all]\"\n+    echo >&2 \"$helptext\"\n     exit 1\n }\n \n allbranches=0\n refsonly=0\n+branches=''\n while [ \"$#\" -gt 0 ]; do\n     case \"$1\" in\n \t--refs) refsonly=1 ;;\n \t--all) allbranches=1 ;;\n+\t--help) echo \"$helptext\"; exit 0 ;;\n+\t--) shift; break ;;\n \t--*) usage ;;\n-\t*) break ;;\n+\t*) branches=\"$branches $1\" ;;\n     esac\n     shift\n done\n+# Now any remaining stuff in $@ are additional options for gitk\n \n-if [ $allbranches = 1 ] && [ \"$#\" -gt 0 ]; then\n+if [ $allbranches = 1 ] && [ \"$branches\" != \"\" ]; then\n     usage\n fi\n \n@@ -41,11 +47,17 @@ refdirs=''\n if [ $allbranches = 1 ]; then\n     refdirs=\"$GIT_DIR/refs\"\n else\n-    if [ \"$#\" = 0 ]; then\n-\tset -- \"$(stg branch)\"\n+    # default to current branch\n+    if [ \"$branches\" == \"\" ]; then\n+\tbranches=\"$(stg branch)\"\n+    fi\n+    if [ \"$branches\" == \"\" ]; then\n+\techo >&2 \"ERROR: cannot find current branch.\"\n+\texit 1\n     fi\n \n-    for b in \"$@\"; do\n+    # expand patches for each named branch\n+    for b in $branches; do\n \tif [ -e \"$GIT_DIR/refs/patches/$b\" ]; then\n \t    # StGIT branch: show all patches\n \t    refdirs=\"$refdirs $GIT_DIR/refs/heads/$b $GIT_DIR/refs/patches/$b\"\n@@ -73,11 +85,11 @@ elif grep -q -- --argscmd $(which gitk); then\n     # This gitk supports --argscmd.\n     # Let's use a hack to pass --all, which was consumed during command-line parsing\n     if [ $allbranches = 1 ]; then\n-\tgitk --argscmd=\"$0 --refs --all\"\n+\tgitk --argscmd=\"$0 --refs --all\" \"$@\"\n     else\n-\tgitk --argscmd=\"$0 --refs $*\"\n+\tgitk --argscmd=\"$0 --refs $branches\" \"$@\"\n     fi\n else\n     # This gitk does not support --argscmd, just compute refs onces\n-    gitk $(printrefs)\n+    gitk $(printrefs) \"$@\"\n fi\n"}]}