{"thread":{"id":"32455","subject":"[PATCH] stash: treat numerical arguments as shorthand for stash@{n}","startedAt":"2012-12-26T00:38:34Z","lastAt":"2012-12-26T02:08:05Z","messageCount":2,"participants":["Peter Collingbourne","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"205485","messageId":"1356482314-29044-1-git-send-email-peter@pcc.me.uk","threadId":"32455","inReplyTo":null,"subject":"[PATCH] stash: treat numerical arguments as shorthand for stash@{n}","fromName":"Peter Collingbourne","fromEmail":"peter@pcc.me.uk","sentAt":"2012-12-26T00:38:34Z","receivedAt":"2012-12-26T00:38:34Z","isPatch":true,"sender":{"key":"peter@pcc.me.uk","avatar":"https://avatars.githubusercontent.com/u/425024?v=4"},"body":"This patch causes git-stash to treat any argument consisting of\nbetween one and three numerical digits as if it were of the form\n`stash@{<n>}`, where `<n>` is the argument supplied.\n\nThis is a significant usability improvement for people dealing with\nmultiple stashes, as it avoids redundantly typing 'stash@{' ... '}'\n(which involves shifted characters on most keyboards) in the very\ncommon case that the stash was created using git-stash.\n\nSigned-off-by: Peter Collingbourne <peter@pcc.me.uk>\n---\n Documentation/git-stash.txt |    4 ++++\n git-stash.sh                |   15 ++++++++++++++-\n t/t3903-stash.sh            |   18 +++++++++---------\n 3 files changed, 27 insertions(+), 10 deletions(-)\n\ndiff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt\nindex 711ffe1..8ffcc97 100644\n--- a/Documentation/git-stash.txt\n+++ b/Documentation/git-stash.txt\n@@ -40,6 +40,10 @@ the usual reflog syntax (e.g. `stash@{0}` is the most recently\n created stash, `stash@{1}` is the one before it, `stash@{2.hours.ago}`\n is also possible).\n \n+Any argument supplied to this command consisting of between one\n+and three numerical digits is treated as if it were of the\n+form `stash@{<n>}`, where `<n>` is the argument supplied.\n+\n OPTIONS\n -------\n \ndiff --git a/git-stash.sh b/git-stash.sh\nindex bbefdf6..2232719 100755\n--- a/git-stash.sh\n+++ b/git-stash.sh\n@@ -327,7 +327,20 @@ parse_flags_and_rev()\n \ti_tree=\n \tu_tree=\n \n-\tREV=$(git rev-parse --no-flags --symbolic \"$@\") || exit 1\n+\tARGS=\n+\tfor arg\n+\tdo\n+\t\tcase \"$arg\" in\n+\t\t\t[0-9]|[0-9][0-9]|[0-9][0-9][0-9])\n+\t\t\t\tARGS=\"${ARGS}${ARGS:+ }${ref_stash}@{$arg}\"\n+\t\t\t;;\n+\t\t\t*)\n+\t\t\t\tARGS=\"${ARGS}${ARGS:+ }$arg\"\n+\t\t\t;;\n+\t\tesac\n+\tdone\n+\n+\tREV=$(git rev-parse --no-flags --symbolic $ARGS) || exit 1\n \n \tFLAGS=\n \tfor opt\ndiff --git a/t/t3903-stash.sh b/t/t3903-stash.sh\nindex 5dfbda7..5467acf 100755\n--- a/t/t3903-stash.sh\n+++ b/t/t3903-stash.sh\n@@ -38,7 +38,7 @@ test_expect_success 'parents of stash' '\n '\n \n test_expect_success 'applying bogus stash does nothing' '\n-\ttest_must_fail git stash apply stash@{1} &&\n+\ttest_must_fail git stash apply 1 &&\n \techo 1 >expect &&\n \ttest_cmp expect file\n '\n@@ -113,7 +113,7 @@ test_expect_success 'drop middle stash' '\n \tgit stash &&\n \techo 9 > file &&\n \tgit stash &&\n-\tgit stash drop stash@{1} &&\n+\tgit stash drop 1 &&\n \ttest 2 = $(git stash list | wc -l) &&\n \tgit stash apply &&\n \ttest 9 = $(cat file) &&\n@@ -570,16 +570,16 @@ test_expect_success 'ref with non-existent reflog' '\n \n test_expect_success 'invalid ref of the form stash@{n}, n >= N' '\n \tgit stash clear &&\n-\ttest_must_fail git stash drop stash@{0} &&\n+\ttest_must_fail git stash drop 0 &&\n \techo bar5 > file &&\n \techo bar6 > file2 &&\n \tgit add file2 &&\n \tgit stash &&\n-\ttest_must_fail git stash drop stash@{1} &&\n-\ttest_must_fail git stash pop stash@{1} &&\n-\ttest_must_fail git stash apply stash@{1} &&\n-\ttest_must_fail git stash show stash@{1} &&\n-\ttest_must_fail git stash branch tmp stash@{1} &&\n+\ttest_must_fail git stash drop 1 &&\n+\ttest_must_fail git stash pop 1 &&\n+\ttest_must_fail git stash apply 1 &&\n+\ttest_must_fail git stash show 1 &&\n+\ttest_must_fail git stash branch tmp 1 &&\n \tgit stash drop\n '\n \n@@ -590,7 +590,7 @@ test_expect_success 'stash branch should not drop the stash if the branch exists\n \tgit commit -m initial &&\n \techo bar >file &&\n \tgit stash &&\n-\ttest_must_fail git stash branch master stash@{0} &&\n+\ttest_must_fail git stash branch master 0 &&\n \tgit rev-parse stash@{0} --\n '\n \n-- \n1.7.5.3\n"},{"id":"205486","messageId":"7v623pr2ey.fsf@alter.siamese.dyndns.org","threadId":"32455","inReplyTo":"1356482314-29044-1-git-send-email-peter@pcc.me.uk","subject":"Re: [PATCH] stash: treat numerical arguments as shorthand for stash@{n}","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-12-26T02:08:05Z","receivedAt":"2012-12-26T02:08:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Peter Collingbourne <peter@pcc.me.uk> writes:\n\n> This patch causes git-stash to treat any argument consisting of\n> between one and three numerical digits as if it were of the form\n> `stash@{<n>}`, where `<n>` is the argument supplied.\n\nInperative mood.\n\n>\n> This is a significant usability improvement for people dealing with\n> multiple stashes, as it avoids redundantly typing 'stash@{' ... '}'\n> (which involves shifted characters on most keyboards) in the very\n> common case that the stash was created using git-stash.\n\nBe less subjective by dropping \"significant\"; do not shove the\njudgement down the throat of reviewers.\n\n> diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt\n> index 711ffe1..8ffcc97 100644\n> --- a/Documentation/git-stash.txt\n> +++ b/Documentation/git-stash.txt\n> @@ -40,6 +40,10 @@ the usual reflog syntax (e.g. `stash@{0}` is the most recently\n>  created stash, `stash@{1}` is the one before it, `stash@{2.hours.ago}`\n>  is also possible).\n>  \n> +Any argument supplied to this command consisting of between one\n> +and three numerical digits is treated as if it were of the\n> +form `stash@{<n>}`, where `<n>` is the argument supplied.\n\nWhy up to 999, not 99 or 9999?\n\nHow about doing it this way instead:\n\n\tif commit=$(git rev-parse --verify --quiet $arg^0)\n\tthen\n\t\t: that is a commit-ish, even though it is 0123\n\telif test \"$arg\" = 0 || expr \"$arg\" : '[1-9][0-9]*$' >/dev/null &&\n\t     commit=$(git rev-parse --verify --quiet \"stash@{$arg}^0\")\n\tthen\n\t\t: $arg is decimal integer and stash@{$arg} is a commit-ish\n\telse\n        \tBAD\n\tfi\n\n> diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh\n> index 5dfbda7..5467acf 100755\n> --- a/t/t3903-stash.sh\n> +++ b/t/t3903-stash.sh\n> @@ -38,7 +38,7 @@ test_expect_success 'parents of stash' '\n>  '\n>  \n>  test_expect_success 'applying bogus stash does nothing' '\n> -\ttest_must_fail git stash apply stash@{1} &&\n> +\ttest_must_fail git stash apply 1 &&\n\nIf you are _adding_ a feature, do not remove tests for existing one;\notherwise you will risk masking a breakage you may be introducing to\nan existing feature.  Add tests to check that (1) your new feature\nworks when it should, and (2) your new feature does *not* kick in\nwhen it should not.  For example, if you only accept up to 3-digit\ndecimal integer, make sure feeding 0000 (or something that is *not*\n3-digit decimal integer) does not trigger your new feature.\n\n>  \techo 1 >expect &&\n>  \ttest_cmp expect file\n>  '\n> @@ -113,7 +113,7 @@ test_expect_success 'drop middle stash' '\n>  \tgit stash &&\n>  \techo 9 > file &&\n>  \tgit stash &&\n> -\tgit stash drop stash@{1} &&\n> +\tgit stash drop 1 &&\n\nLikewise throughout the patch.\n"}]}