{"thread":{"id":"25241","subject":"[PATCH v4 0/4] rev-parse: allow --flags to output rev-parse-like flags","startedAt":"2010-09-25T13:33:49Z","lastAt":"2010-09-25T16:19:59Z","messageCount":8,"participants":["Jon Seymour","Ævar Arnfjörð Bjarmason"],"isPatch":true,"patchVersion":4,"patchTotal":4},"messages":[{"id":"151640","messageId":"1285421633-22684-1-git-send-email-jon.seymour@gmail.com","threadId":"25241","inReplyTo":null,"subject":"[PATCH v4 0/4] rev-parse: allow --flags to output rev-parse-like flags","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2010-09-25T13:33:49Z","receivedAt":"2010-09-25T13:33:49Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"This series allows git rev-parse --flags to output remaining flag-like arguments\neven if such arguments are valid options to git rev-parse itself.\n\nPreviously:\n  $ git rev-parse --flags -q -X --no-flags -- Y -Z\n  -X\n  $\n\nNow:\n  $ git rev-parse --flags -q -X --no-flags -- Y -Z\n  -q -X --no-flags\n  $\n\nThis series also changes the interpretation of --flags so that\nspecification of this option implies --no-revs.\n\nPreviously:\n  $ git rev-parse --flags HEAD\n  HEAD\n  $\n\nNow:\n  $ git rev-parse --flags HEAD\n  $\n\nReviewers attention is drawn to the following behaviour which, while\nunchanged from current behaviour, differs from the behaviour specified\nby the documentation. Specifically:\n\n  $ git rev-parse -X --no-flags\n  -X\n  $ git rev-parse --no-flags -X\n  $\n\nIn other words, a git rev-parse option only ever affects the \ninterpretation of succeeding options, never preceding options.\n\nAevar's feedback on v2 of this series has been incorporated.\n\nJon Seymour (4):\n  rev-parse: stop interpreting flags as options to rev-parse once\n    --flags is specified\n  rev-parse: add tests for git rev-parse --flags.\n  rev-parse: update documentation of --flags and --no-flags options\n  rev-parse: make --flags imply --no-revs for remaining arguments.\n\n Documentation/git-rev-parse.txt |   12 ++++\n builtin/rev-parse.c             |   14 +++++-\n t/t1510-rev-parse-flags.sh      |  109 +++++++++++++++++++++++++++++++++++++++\n 3 files changed, 134 insertions(+), 1 deletions(-)\n create mode 100755 t/t1510-rev-parse-flags.sh\n\n-- \n1.7.3.3.gc4c52.dirty\n"},{"id":"151641","messageId":"1285421633-22684-2-git-send-email-jon.seymour@gmail.com","threadId":"25241","inReplyTo":"1285421633-22684-1-git-send-email-jon.seymour@gmail.com","subject":"[PATCH v4 1/4] rev-parse: stop interpreting flags as options to rev-parse once --flags is specified","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2010-09-25T13:33:50Z","receivedAt":"2010-09-25T13:33:50Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"Current git rev-parse behaviour makes --flags hard to use if the remaining\narguments to git rev-parse contain an option that would otherwise be interpreted\nas an option by git rev-parse itself.\n\nSo, for example:\n\n  $> git rev-parse --flags -q -X\n  -X\n\nNormally one might expect to use -- to prevent -q being interpreted:\n\n  $> git rev-parse --flags -- -q -X\n  -q -X\n\nBut we can't really use -- in this way, because commands that use\ngit rev-parse might reasonably expect:\n\n  $> git rev-parse --flags -Y -- -q -X\n  -Y\n\nThat is, -Y to be regarded as a flag but everything after -- to be uninterpreted.\n\nThis proposed change modifies git rev-parse so that git rev-parse stops\ninterpreting flag arguments as options to git rev-parse once --flags is\ninterpreted. We also exit early once -- is found.\n\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n builtin/rev-parse.c |    8 ++++++++\n 1 files changed, 8 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex a5a1c86..2ad269a 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -497,8 +497,16 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\t/* Pass on the \"--\" if we show anything but files.. */\n \t\t\t\tif (filter & (DO_FLAGS | DO_REVS))\n \t\t\t\t\tshow_file(arg);\n+\t\t\t\tif (!(filter & DO_NONFLAGS)) {\n+\t\t\t\t\treturn 0;\n+\t\t\t\t}\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!(filter & DO_NONFLAGS)) {\n+\t\t\t\t/* once we see --flags, we stop interpreting other flags */\n+\t\t\t\t show_flag(arg);\n+\t\t\t\t continue;\n+\t\t\t}\n \t\t\tif (!strcmp(arg, \"--default\")) {\n \t\t\t\tdef = argv[i+1];\n \t\t\t\ti++;\n-- \n1.7.3.3.gc4c52.dirty\n"},{"id":"151642","messageId":"1285421633-22684-3-git-send-email-jon.seymour@gmail.com","threadId":"25241","inReplyTo":"1285421633-22684-1-git-send-email-jon.seymour@gmail.com","subject":"[PATCH v4 2/4] rev-parse: add tests for git rev-parse --flags.","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2010-09-25T13:33:51Z","receivedAt":"2010-09-25T13:33:51Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"Signed-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n t/t1510-rev-parse-flags.sh |  109 ++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 109 insertions(+), 0 deletions(-)\n create mode 100755 t/t1510-rev-parse-flags.sh\n\ndiff --git a/t/t1510-rev-parse-flags.sh b/t/t1510-rev-parse-flags.sh\nnew file mode 100755\nindex 0000000..53002df\n--- /dev/null\n+++ b/t/t1510-rev-parse-flags.sh\n@@ -0,0 +1,109 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2010 Jon Seymour\n+#\n+\n+test_description='test git rev-parse --flags'\n+. ./test-lib.sh\n+\n+test_commit \"A\"\n+\n+test_expect_success 'git rev-parse --flags -> \"\"' \\\n+'\n+\t: >expected &&\n+\tgit rev-parse --flags >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'git rev-parse --flags X -> \"\"' \\\n+'\n+\t: >expected &&\n+\tgit rev-parse --flags X >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'git rev-parse --no-revs --flags HEAD -> \"\"' \\\n+'\n+\t: >expected &&\n+\tgit rev-parse --no-revs --flags HEAD >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'git rev-parse --symbolic --flags HEAD -> \"HEAD\"' \\\n+'\n+\techo HEAD > expected &&\n+\tgit rev-parse --symbolic --flags HEAD >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'git rev-parse --flags -- -> \"\"' \\\n+'\n+\t: >expected &&\n+\tgit rev-parse --flags -- >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'git rev-parse --flags -- X -> \"\"' \\\n+'\n+\t: >expected &&\n+\tgit rev-parse --flags -- X >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'git rev-parse --flags -- -X -> \"\"' \\\n+'\n+\t: >expected &&\n+\tgit rev-parse --flags -- -X >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'git rev-parse --flags -- -q --> \"\"' \\\n+'\n+\t: >expected &&\n+\tgit rev-parse --flags -- -q >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'git rev-parse --flags -X -> \"-X\"' \\\n+'\n+\techo -X > expected &&\n+\tgit rev-parse --flags -X >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'git rev-parse --flags -q -> \"-q\"' \\\n+'\n+\techo -q > expected &&\n+\tgit rev-parse --flags -q >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'git rev-parse --flags -X -- Y -Z -> \"-X\"' \\\n+'\n+\techo -X > expected &&\n+\tgit rev-parse --flags -X -- Y -Z >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'git rev-parse --flags --no-flags -> \"--no-flags\"' \\\n+'\n+\techo --no-flags > expected &&\n+\tgit rev-parse --flags --no-flags >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'git rev-parse --no-flags --flags -X -> \"\"' \\\n+'\n+\t: >expected &&\n+\tgit rev-parse --no-flags --flags -X >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'git rev-parse --symbolic --no-flags --flags HEAD -> \"HEAD\"' \\\n+'\n+\techo HEAD >expected &&\n+\tgit rev-parse --symbolic --no-flags --flags HEAD >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_done\n-- \n1.7.3.3.gc4c52.dirty\n"},{"id":"151643","messageId":"1285421633-22684-4-git-send-email-jon.seymour@gmail.com","threadId":"25241","inReplyTo":"1285421633-22684-1-git-send-email-jon.seymour@gmail.com","subject":"[PATCH v4 3/4] rev-parse: update documentation of --flags and --no-flags options","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2010-09-25T13:33:52Z","receivedAt":"2010-09-25T13:33:52Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"Signed-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n Documentation/git-rev-parse.txt |   12 +++++++++++-\n 1 files changed, 11 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt\nindex 341ca90..f5e6637 100644\n--- a/Documentation/git-rev-parse.txt\n+++ b/Documentation/git-rev-parse.txt\n@@ -49,10 +49,20 @@ OPTIONS\n \t'git rev-list' command.\n \n --flags::\n-\tDo not output non-flag parameters.\n+\tDo not output non-flag parameters which are not also revisions.\n+\t+\n+\tIf specified, this option causes 'git rev-parse' to stop\n+\tinterpreting remaining arguments as options for its own\n+\tconsumption. As such, this option should be specified\n+\tafter all other options that 'git rev-parse' is expected\n+\tto interpret.\n \n --no-flags::\n \tDo not output flag parameters.\n+\t+\n+\tIf both `--flags` and `--no-flags` are specified, the first\n+\toption specified wins and the other option is treated like\n+\ta non-option argument.\n \n --default <arg>::\n \tIf there is no parameter given by the user, use `<arg>`\n-- \n1.7.3.3.gc4c52.dirty\n"},{"id":"151644","messageId":"1285421633-22684-5-git-send-email-jon.seymour@gmail.com","threadId":"25241","inReplyTo":"1285421633-22684-1-git-send-email-jon.seymour@gmail.com","subject":"[PATCH v4 4/4] rev-parse: make --flags imply --no-revs for remaining arguments.","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2010-09-25T13:33:53Z","receivedAt":"2010-09-25T13:33:53Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"This change ensures that git rev-parse --flags complies with its documentation,\nnamely:\n\n   \"Do not output non-flag parameters\".\n\nPreviously:\n   $ git rev-parse --flags HEAD\n   <sha1 hash of HEAD>\n   $\n\nNow:\n   $ git rev-parse --flags HEAD\n   $\n\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n Documentation/git-rev-parse.txt |   24 +++++++++++++-----------\n builtin/rev-parse.c             |    6 +++++-\n t/t1510-rev-parse-flags.sh      |    2 +-\n 3 files changed, 19 insertions(+), 13 deletions(-)\n\ndiff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt\nindex f5e6637..f26fc7b 100644\n--- a/Documentation/git-rev-parse.txt\n+++ b/Documentation/git-rev-parse.txt\n@@ -49,20 +49,22 @@ OPTIONS\n \t'git rev-list' command.\n \n --flags::\n-\tDo not output non-flag parameters which are not also revisions.\n-\t+\n-\tIf specified, this option causes 'git rev-parse' to stop\n-\tinterpreting remaining arguments as options for its own\n-\tconsumption. As such, this option should be specified\n-\tafter all other options that 'git rev-parse' is expected\n-\tto interpret.\n+\tDo not output non-flag parameters.\n++\n+If specified, this option causes 'git rev-parse' to stop\n+interpreting remaining arguments as options for its own\n+consumption. As such, this option should be specified\n+after all other options that 'git rev-parse' is expected\n+to interpret.\n++\n+If `--flags` is specified, `--no-revs` is implied.\n \n --no-flags::\n \tDo not output flag parameters.\n-\t+\n-\tIf both `--flags` and `--no-flags` are specified, the first\n-\toption specified wins and the other option is treated like\n-\ta non-option argument.\n++\n+If both `--flags` and `--no-flags` are specified, the first\n+option specified wins and the other option is treated like\n+a non-option argument.\n \n --default <arg>::\n \tIf there is no parameter given by the user, use `<arg>`\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 2ad269a..84f9f07 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -13,7 +13,7 @@\n #define DO_REVS\t\t1\n #define DO_NOREV\t2\n #define DO_FLAGS\t4\n-#define DO_NONFLAGS\t8\n+#define DO_NONFLAGS\t(8|DO_REVS)\n static int filter = ~0;\n \n static const char *def;\n@@ -521,6 +521,10 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--flags\")) {\n+\t\t\t\tif (!(filter & DO_FLAGS)) {\n+\t\t\t\t\t/* prevent --flags being interpreted if --no-flags has been seen */\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n \t\t\t\tfilter &= ~DO_NONFLAGS;\n \t\t\t\tcontinue;\n \t\t\t}\ndiff --git a/t/t1510-rev-parse-flags.sh b/t/t1510-rev-parse-flags.sh\nindex 53002df..4dd6228 100755\n--- a/t/t1510-rev-parse-flags.sh\n+++ b/t/t1510-rev-parse-flags.sh\n@@ -31,7 +31,7 @@ test_expect_success 'git rev-parse --no-revs --flags HEAD -> \"\"' \\\n \n test_expect_success 'git rev-parse --symbolic --flags HEAD -> \"HEAD\"' \\\n '\n-\techo HEAD > expected &&\n+\t: > expected &&\n \tgit rev-parse --symbolic --flags HEAD >actual &&\n \ttest_cmp expected actual\n '\n-- \n1.7.3.3.gc4c52.dirty\n"},{"id":"151646","messageId":"3C9522B3-1386-4FD2-8607-F1A6A58D6D9A@gmail.com","threadId":"25241","inReplyTo":"1285421633-22684-5-git-send-email-jon.seymour@gmail.com","subject":"Re: [PATCH v4 4/4] rev-parse: make --flags imply --no-revs for remaining arguments.","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2010-09-25T14:20:42Z","receivedAt":"2010-09-25T14:20:42Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"Oops - 4/4 breaks --no-revs.\n\nWill issue v5 with guarding test shortly.\n\njon.\n\nOn 25/09/2010, at 23:33, Jon Seymour <jon.seymour@gmail.com> wrote:\n\n> This change ensures that git rev-parse --flags complies with its documentation,\n> namely:\n> \n>   \"Do not output non-flag parameters\".\n> \n> Previously:\n>   $ git rev-parse --flags HEAD\n>   <sha1 hash of HEAD>\n>   $\n> \n> Now:\n>   $ git rev-parse --flags HEAD\n>   $\n> \n> Signed-off-by: Jon Seymour <jon.seymour@gmail.com>\n> ---\n> Documentation/git-rev-parse.txt |   24 +++++++++++++-----------\n> builtin/rev-parse.c             |    6 +++++-\n> t/t1510-rev-parse-flags.sh      |    2 +-\n> 3 files changed, 19 insertions(+), 13 deletions(-)\n> \n> diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt\n> index f5e6637..f26fc7b 100644\n> --- a/Documentation/git-rev-parse.txt\n> +++ b/Documentation/git-rev-parse.txt\n> @@ -49,20 +49,22 @@ OPTIONS\n>    'git rev-list' command.\n> \n> --flags::\n> -    Do not output non-flag parameters which are not also revisions.\n> -    +\n> -    If specified, this option causes 'git rev-parse' to stop\n> -    interpreting remaining arguments as options for its own\n> -    consumption. As such, this option should be specified\n> -    after all other options that 'git rev-parse' is expected\n> -    to interpret.\n> +    Do not output non-flag parameters.\n> ++\n> +If specified, this option causes 'git rev-parse' to stop\n> +interpreting remaining arguments as options for its own\n> +consumption. As such, this option should be specified\n> +after all other options that 'git rev-parse' is expected\n> +to interpret.\n> ++\n> +If `--flags` is specified, `--no-revs` is implied.\n> \n> --no-flags::\n>    Do not output flag parameters.\n> -    +\n> -    If both `--flags` and `--no-flags` are specified, the first\n> -    option specified wins and the other option is treated like\n> -    a non-option argument.\n> ++\n> +If both `--flags` and `--no-flags` are specified, the first\n> +option specified wins and the other option is treated like\n> +a non-option argument.\n> \n> --default <arg>::\n>    If there is no parameter given by the user, use `<arg>`\n> diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\n> index 2ad269a..84f9f07 100644\n> --- a/builtin/rev-parse.c\n> +++ b/builtin/rev-parse.c\n> @@ -13,7 +13,7 @@\n> #define DO_REVS        1\n> #define DO_NOREV    2\n> #define DO_FLAGS    4\n> -#define DO_NONFLAGS    8\n> +#define DO_NONFLAGS    (8|DO_REVS)\n> static int filter = ~0;\n> \n> static const char *def;\n> @@ -521,6 +521,10 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n>                continue;\n>            }\n>            if (!strcmp(arg, \"--flags\")) {\n> +                if (!(filter & DO_FLAGS)) {\n> +                    /* prevent --flags being interpreted if --no-flags has been seen */\n> +                    continue;\n> +                }\n>                filter &= ~DO_NONFLAGS;\n>                continue;\n>            }\n> diff --git a/t/t1510-rev-parse-flags.sh b/t/t1510-rev-parse-flags.sh\n> index 53002df..4dd6228 100755\n> --- a/t/t1510-rev-parse-flags.sh\n> +++ b/t/t1510-rev-parse-flags.sh\n> @@ -31,7 +31,7 @@ test_expect_success 'git rev-parse --no-revs --flags HEAD -> \"\"' \\\n> \n> test_expect_success 'git rev-parse --symbolic --flags HEAD -> \"HEAD\"' \\\n> '\n> -    echo HEAD > expected &&\n> +    : > expected &&\n>    git rev-parse --symbolic --flags HEAD >actual &&\n>    test_cmp expected actual\n> '\n> -- \n> 1.7.3.3.gc4c52.dirty\n> \n"},{"id":"151647","messageId":"AANLkTimj--jZdX++=ZjF3A0HE11FbkgVb2gs3ADVEGvx@mail.gmail.com","threadId":"25241","inReplyTo":"1285421633-22684-3-git-send-email-jon.seymour@gmail.com","subject":"Re: [PATCH v4 2/4] rev-parse: add tests for git rev-parse --flags.","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-09-25T14:27:02Z","receivedAt":"2010-09-25T14:27:02Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Sat, Sep 25, 2010 at 13:33, Jon Seymour <jon.seymour@gmail.com> wrote:\n\n> +       : >expected &&\n\nWe've been dropping the \":>foo\" style in favor of \">foo\" in other\ntests. There's no need for the \":\".\n\n> +       echo -X > expected &&\n> +       echo -q > expected &&\n> +       echo -X > expected &&\n> +       echo --no-flags > expected &&\n\nMaybe some echo implementations don't like flag-like params, and we need:\n\n    printf \"%s\\n\" \"-X\"\n\nhere. I don't know whether that's the case.\n"},{"id":"151654","messageId":"AANLkTimW6shzyLqW-Ok_+kopjnq5t+AVxW0WRrmjkgQp@mail.gmail.com","threadId":"25241","inReplyTo":"AANLkTimj--jZdX++=ZjF3A0HE11FbkgVb2gs3ADVEGvx@mail.gmail.com","subject":"Re: [PATCH v4 2/4] rev-parse: add tests for git rev-parse --flags.","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2010-09-25T16:19:59Z","receivedAt":"2010-09-25T16:19:59Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"On Sun, Sep 26, 2010 at 12:27 AM, Ævar Arnfjörð Bjarmason\n<avarab@gmail.com> wrote:\n> On Sat, Sep 25, 2010 at 13:33, Jon Seymour <jon.seymour@gmail.com> wrote:\n>\n>> +       : >expected &&\n>\n> We've been dropping the \":>foo\" style in favor of \">foo\" in other\n> tests. There's no need for the \":\".\n>\n>> +       echo -X > expected &&\n>> +       echo -q > expected &&\n>> +       echo -X > expected &&\n>> +       echo --no-flags > expected &&\n>\n> Maybe some echo implementations don't like flag-like params, and we need:\n>\n>    printf \"%s\\n\" \"-X\"\n>\n> here. I don't know whether that's the case.\n>\n\nThanks for the review.\n\nMy latest revision incorporates this feedback, although I didn't use\nextra quotes around -X. (e.g. I wrote printf \"%s\\n\" -X)\n\njon.\n"}]}