{"thread":{"id":"2801","subject":"[RFC, PATCH] Usage message clean-up, take #2","startedAt":"2005-12-11T09:55:49Z","lastAt":"2005-12-11T10:15:22Z","messageCount":2,"participants":["Fredrik Kuivinen","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"13484","messageId":"20051211095549.GB4919@c165.ib.student.liu.se","threadId":"2801","inReplyTo":null,"subject":"[RFC, PATCH] Usage message clean-up, take #2","fromName":"Fredrik Kuivinen","fromEmail":"freku045@student.liu.se","sentAt":"2005-12-11T09:55:49Z","receivedAt":"2005-12-11T09:55:49Z","isPatch":true,"sender":{"key":"frekui@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13770967?v=4"},"body":"Hi,\n\nThere were some problems with the usage message clean-up patch\nseries. I hadn't realised that subdirectory aware scripts can't source\ngit-sh-setup. I propose that we change this and let the scripts which\nare subdirectory aware set a variable, SUBDIRECTORY_OK, before they\nsource git-sh-setup.\n\nThe scripts will also set USAGE and possibly LONG_USAGE before they\nsource git-sh-setup. If LONG_USAGE isn't set it defaults to USAGE.\n\nIf we go this way it's easy to catch --help in git-sh-setup, print the\n(long) usage message to stdout and exit cleanly. git-sh-setup can\ndefine a 'usage' shell function which can be called by the scripts to\nprint the short usage string to stderr and exit non-cleanly. It will\nalso be easy to change $0 to basename $0 or something else, if would\nlike to do that sometime in the future.\n\nWhat follows is a patch to convert a couple of the commands to this\nstyle. If it's ok with everyone to do it this way I will convert the\nrest of the scripts too.\n\n\n- Fredrik\n\n---\n\n git-bisect.sh   |   24 +++++++++++-------------\n git-branch.sh   |   21 ++++++---------------\n git-sh-setup.sh |   34 +++++++++++++++++++++++++++++-----\n git-status.sh   |   11 ++++++++++-\n 4 files changed, 56 insertions(+), 34 deletions(-)\n\ndiff --git a/git-bisect.sh b/git-bisect.sh\nindex 05dae8a..51e1e44 100755\n--- a/git-bisect.sh\n+++ b/git-bisect.sh\n@@ -1,4 +1,15 @@\n #!/bin/sh\n+\n+USAGE='[start|bad|good|next|reset|visualize]'\n+LONG_USAGE='git bisect start [<pathspec>]\treset bisect state and start bisection.\n+git bisect bad [<rev>]\t\tmark <rev> a known-bad revision.\n+git bisect good [<rev>...]\tmark <rev>... known-good revisions.\n+git bisect next\t\t\tfind next bisection to test and check it out.\n+git bisect reset [<branch>]\tfinish bisection search and go back to branch.\n+git bisect visualize            show bisect status in gitk.\n+git bisect replay <logfile>\treplay bisection log\n+git bisect log\t\t\tshow bisect log.'\n+\n . git-sh-setup\n \n sq() {\n@@ -11,19 +22,6 @@ sq() {\n \t' \"$@\"\n }\n \n-usage() {\n-    echo >&2 'usage: git bisect [start|bad|good|next|reset|visualize]\n-git bisect start [<pathspec>]\treset bisect state and start bisection.\n-git bisect bad [<rev>]\t\tmark <rev> a known-bad revision.\n-git bisect good [<rev>...]\tmark <rev>... known-good revisions.\n-git bisect next\t\t\tfind next bisection to test and check it out.\n-git bisect reset [<branch>]\tfinish bisection search and go back to branch.\n-git bisect visualize            show bisect status in gitk.\n-git bisect replay <logfile>\treplay bisection log\n-git bisect log\t\t\tshow bisect log.'\n-    exit 1\n-}\n-\n bisect_autostart() {\n \ttest -d \"$GIT_DIR/refs/bisect\" || {\n \t\techo >&2 'You need to start by \"git bisect start\"'\ndiff --git a/git-branch.sh b/git-branch.sh\nindex 5306b27..0266f46 100755\n--- a/git-branch.sh\n+++ b/git-branch.sh\n@@ -1,21 +1,12 @@\n #!/bin/sh\n \n-GIT_DIR=`git-rev-parse --git-dir` || exit $?\n-\n-die () {\n-    echo >&2 \"$*\"\n-    exit 1\n-}\n-\n-usage () {\n-    echo >&2 \"usage: $(basename $0)\"' [-d <branch>] | [[-f] <branch> [start-point]]\n-\n-If no arguments, show available branches and mark current branch with a star.\n+USAGE='[-d <branch>] | [[-f] <branch> [start-point]]'\n+LONG_USAGE='If no arguments, show available branches and mark current branch with a star.\n If one argument, create a new branch <branchname> based off of current HEAD.\n-If two arguments, create a new branch <branchname> based off of <start-point>.\n-'\n-    exit 1\n-}\n+If two arguments, create a new branch <branchname> based off of <start-point>.'\n+\n+SUBDIRECTORY_OK='Yes'\n+. git-sh-setup\n \n headref=$(git-symbolic-ref HEAD | sed -e 's|^refs/heads/||')\n \ndiff --git a/git-sh-setup.sh b/git-sh-setup.sh\nindex b4f1022..1e638e4 100755\n--- a/git-sh-setup.sh\n+++ b/git-sh-setup.sh\n@@ -11,13 +11,37 @@\n # exporting it.\n unset CDPATH\n \n-: ${GIT_DIR=.git}\n-: ${GIT_OBJECT_DIRECTORY=\"$GIT_DIR/objects\"}\n-\n die() {\n \techo >&2 \"$@\"\n \texit 1\n }\n \n-# Make sure we are in a valid repository of a vintage we understand.\n-GIT_DIR=\"$GIT_DIR\" git-var GIT_AUTHOR_IDENT >/dev/null || exit\n+usage() {\n+\tdie \"Usage: $0 $USAGE\"\n+}\n+\n+if [ -z \"$LONG_USAGE\" ]\n+then\n+\tLONG_USAGE=\"Usage: $0 $USAGE\"\n+else\n+\tLONG_USAGE=\"Usage: $0 $USAGE\n+\n+$LONG_USAGE\"\n+fi\n+\n+case \"$1\" in\n+\t--h|--he|--hel|--help)\n+\techo \"$LONG_USAGE\"\n+\texit\n+esac\n+\n+if [ -z \"$SUBDIRECTORY_OK\" ]\n+then\n+\t: ${GIT_DIR=.git}\n+\t: ${GIT_OBJECT_DIRECTORY=\"$GIT_DIR/objects\"}\n+\n+\t# Make sure we are in a valid repository of a vintage we understand.\n+\tGIT_DIR=\"$GIT_DIR\" git-var GIT_AUTHOR_IDENT >/dev/null || exit\n+else\n+\tGIT_DIR=$(git-rev-parse --git-dir) || exit\n+fi\ndiff --git a/git-status.sh b/git-status.sh\nindex 2dda0c5..50ccd24 100755\n--- a/git-status.sh\n+++ b/git-status.sh\n@@ -2,7 +2,16 @@\n #\n # Copyright (c) 2005 Linus Torvalds\n #\n-GIT_DIR=$(git-rev-parse --git-dir) || exit\n+\n+USAGE=''\n+SUBDIRECTORY_OK='Yes'\n+\n+. git-sh-setup\n+\n+if [ \"$#\" != \"0\" ]\n+then\n+  usage\n+fi\n \n report () {\n   header=\"#\n"},{"id":"13485","messageId":"7vu0dglz2d.fsf@assigned-by-dhcp.cox.net","threadId":"2801","inReplyTo":"20051211095549.GB4919@c165.ib.student.liu.se","subject":"Re: [RFC, PATCH] Usage message clean-up, take #2","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-12-11T10:15:22Z","receivedAt":"2005-12-11T10:15:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Fredrik Kuivinen <freku045@student.liu.se> writes:\n\n> The scripts will also set USAGE and possibly LONG_USAGE before they\n> source git-sh-setup. If LONG_USAGE isn't set it defaults to USAGE.\n\nLooks like a good start to allow us to mechanically generate\nparts of the manpages in the future.\n\nLast time I played around with various bourne derivative shells,\nI was annoyed by that scripts sourced with '.'  behaved slightly\ndifferently regarding positional arguments such as \"$1\", which\nmay be one thing to watch out for (sorry, I do not remember the\ndetails right now, other than one case: \". ./foobra.sh arg1\narg2\", and depending on the shell the value of $# and $1\nfoobra.sh sees was different.  I do not think this would matter\nfor our purpose because in our case \". script\" form is never\nused with extra parameters).\n"}]}