{"thread":{"id":"29708","subject":"[PATCH] pretty: add '*' modifier to add LF after non-empty","startedAt":"2012-02-23T13:10:37Z","lastAt":"2012-04-14T20:01:26Z","messageCount":4,"participants":["Luc Pionchon","Junio C Hamano","Felipe Contreras"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"185272","messageId":"1330002637-9347-1-git-send-email-pionchon.luc@gmail.com","threadId":"29708","inReplyTo":null,"subject":"[PATCH] pretty: add '*' modifier to add LF after non-empty","fromName":"Luc Pionchon","fromEmail":"pionchon.luc@gmail.com","sentAt":"2012-02-23T13:10:37Z","receivedAt":"2012-02-23T13:10:37Z","isPatch":true,"sender":{"key":"pionchon.luc@gmail.com","avatar":null},"body":"Add the '*' modifier, similar to the '+' modifier,\nto add a line-feed after a non-empty placeholder.\n\nAllow to print a head-line which content can be empty.\nFor example for decorations:\n\n    $ git log --graph --pretty=format:\"%C(green)%*d %C(reset)%s\"\n                                                ^^^\n\n    *  (HEAD, origin/master, origin/HEAD, master)\n    |  Update draft release notes to 1.7.10\n    *    Merge branch 'jc/maint-request-pull-for-tag'\n    |\\  \n    | *  (origin/jc/maint-request-pull-for-tag)\n    | |  request-pull: explicitly ask tags/$name to be pulled\n    * |    Merge branch 'bl/gitweb-project-filter'\n    |\\ \\  \n    | * |  (origin/bl/gitweb-project-filter)\n    | | |  gitweb: Make project search respect project_filter\n\n\nSigned-off-by: Luc Pionchon <pionchon.luc@gmail.com>\n---\n Documentation/pretty-formats.txt |    4 ++++\n pretty.c                         |    6 ++++++\n t/t6006-rev-list-format.sh       |   10 ++++++++++\n 3 files changed, 20 insertions(+), 0 deletions(-)\n\nHi,\n\nI now started to use git.  When formatting my 'log' output, I have been looking for a modifier to add a line feed after a (potentially empty) placeholder.  Git allows to add a line feed before, but not after a placeholder.  This is a small patch that adds the feature.  I hope it is useful to others.\n\n\ndiff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt\nindex 880b6f2..9114d49 100644\n--- a/Documentation/pretty-formats.txt\n+++ b/Documentation/pretty-formats.txt\n@@ -159,6 +159,10 @@ If you add a `{plus}` (plus sign) after '%' of a placeholder, a line-feed\n is inserted immediately before the expansion if and only if the\n placeholder expands to a non-empty string.\n \n+If you add a `*` (asterisk sign) after '%' of a placeholder, a line-feed\n+is inserted immediately after the expansion if and only if the\n+placeholder expands to a non-empty string.\n+\n If you add a `-` (minus sign) after '%' of a placeholder, line-feeds that\n immediately precede the expansion are deleted if and only if the\n placeholder expands to an empty string.\ndiff --git a/pretty.c b/pretty.c\nindex 8688b8f..5ebaf88 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -1132,6 +1132,7 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,\n \t\tNO_MAGIC,\n \t\tADD_LF_BEFORE_NON_EMPTY,\n \t\tDEL_LF_BEFORE_EMPTY,\n+\t\tADD_LF_AFTER_NON_EMPTY,\n \t\tADD_SP_BEFORE_NON_EMPTY\n \t} magic = NO_MAGIC;\n \n@@ -1142,6 +1143,9 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,\n \tcase '+':\n \t\tmagic = ADD_LF_BEFORE_NON_EMPTY;\n \t\tbreak;\n+\tcase '*':\n+\t\tmagic = ADD_LF_AFTER_NON_EMPTY;\n+\t\tbreak;\n \tcase ' ':\n \t\tmagic = ADD_SP_BEFORE_NON_EMPTY;\n \t\tbreak;\n@@ -1162,6 +1166,8 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,\n \t} else if (orig_len != sb->len) {\n \t\tif (magic == ADD_LF_BEFORE_NON_EMPTY)\n \t\t\tstrbuf_insert(sb, orig_len, \"\\n\", 1);\n+\t\telse if (magic == ADD_LF_AFTER_NON_EMPTY)\n+\t\t\tstrbuf_addstr(sb, \"\\n\");\n \t\telse if (magic == ADD_SP_BEFORE_NON_EMPTY)\n \t\t\tstrbuf_insert(sb, orig_len, \" \", 1);\n \t}\ndiff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh\nindex 4442790..c692061 100755\n--- a/t/t6006-rev-list-format.sh\n+++ b/t/t6006-rev-list-format.sh\n@@ -208,6 +208,16 @@ test_expect_success 'add LF before non-empty (2)' '\n \tgrep \"^$\" actual\n '\n \n+test_expect_success 'add LF after non-empty (1) (empty)' '\n+\tgit show -s --pretty=format:\"%*d%s%nfoo%n\" HEAD^^ >actual &&\n+\ttest $(wc -l <actual) = 2\n+'\n+\n+test_expect_success 'add LF after non-empty (2) (non empty)' '\n+\tgit show -s --pretty=format:\"%*d%s%nfoo%n\" HEAD >actual &&\n+\ttest $(wc -l <actual) = 3\n+'\n+\n test_expect_success 'add SP before non-empty (1)' '\n \tgit show -s --pretty=format:\"%s% bThanks\" HEAD^^ >actual &&\n \ttest $(wc -w <actual) = 2\n-- \n1.7.4.1\n"},{"id":"185293","messageId":"7v7gzd498r.fsf@alter.siamese.dyndns.org","threadId":"29708","inReplyTo":"1330002637-9347-1-git-send-email-pionchon.luc@gmail.com","subject":"Re: [PATCH] pretty: add '*' modifier to add LF after non-empty","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-02-23T19:53:24Z","receivedAt":"2012-02-23T19:53:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Luc Pionchon <pionchon.luc@gmail.com> writes:\n\n> Add the '*' modifier, similar to the '+' modifier,\n> to add a line-feed after a non-empty placeholder.\n\nHrm, I thought I designed the plus and minus fairly carefully so that\nnobody needs to add this later.\n\nWouldn't it be sufficient to write\n\n        Foo%n%-d\n\nthat says \"We usually have LF after Foo, and write %d after that, but we\nmight not have anything interesting in %d at all, in which case we don't\nadd that %n\"?\n\n> +test_expect_success 'add LF after non-empty (1) (empty)' '\n> +\tgit show -s --pretty=format:\"%*d%s%nfoo%n\" HEAD^^ >actual &&\n\nShouldn't this be equivalent to \"%n%-d%s%nfoo%n\", which in turn is covered\nby one of the previous tests (del LF before empty)?\n"},{"id":"185328","messageId":"CAEYyJDyE88w2R5duQgm21w50OkU+J4qbs00=TfV=FvXPyUWaVA@mail.gmail.com","threadId":"29708","inReplyTo":"7v7gzd498r.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] pretty: add '*' modifier to add LF after non-empty","fromName":"Luc Pionchon","fromEmail":"pionchon.luc@gmail.com","sentAt":"2012-02-24T10:58:58Z","receivedAt":"2012-02-24T10:58:58Z","isPatch":true,"sender":{"key":"pionchon.luc@gmail.com","avatar":null},"body":"On Thu, Feb 23, 2012 at 21:53, Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Luc Pionchon <pionchon.luc@gmail.com> writes:\n>\n> > Add the '*' modifier, similar to the '+' modifier,\n> > to add a line-feed after a non-empty placeholder.\n>\n> Hrm, I thought I designed the plus and minus fairly carefully so that\n> nobody needs to add this later.\n>\n> Wouldn't it be sufficient to write\n>\n>        Foo%n%-d\n>\n>\n> that says \"We usually have LF after Foo, and write %d after that, but we\n> might not have anything interesting in %d at all, in which case we don't\n> add that %n\"?\n\nWhat I want is a LF after the non empty, rather than before.\nIt seems to me that %n%-d is equivalent to %+d,\nor did I miss something?\n\nSee the 3 examples below, with %n%-d, %+d and %*d\n\n$ ./git log -5 --graph --pretty=format:\"%C(yellow bold)%n%-d %C(reset)%s\"\n*\n|\\   (HEAD, origin/master, origin/HEAD, master) Sync with 1.7.9.2\n| *\n| |  (v1.7.9.2, origin/maint) Git 1.7.9.2\n| *  completion: use tabs for indentation\n| *  completion: remove stale \"to submit patches\" documentation\n* |  git-p4: the option to specify 'host' is -H, not -h\n\n$ ./git log -5 --graph --pretty=format:\"%C(yellow bold)%+d %C(reset)%s\"\n*\n|\\   (HEAD, origin/master, origin/HEAD, master) Sync with 1.7.9.2\n| *\n| |  (v1.7.9.2, origin/maint) Git 1.7.9.2\n| *  completion: use tabs for indentation\n| *  completion: remove stale \"to submit patches\" documentation\n* |  git-p4: the option to specify 'host' is -H, not -h\n\n$ ./git log -5 --graph --pretty=format:\"%C(yellow bold)%*d %C(reset)%s\"\n*    (HEAD, origin/master, origin/HEAD, master)\n|\\   Sync with 1.7.9.2\n| *  (v1.7.9.2, origin/maint)\n| |  Git 1.7.9.2\n| *  completion: use tabs for indentation\n| *  completion: remove stale \"to submit patches\" documentation\n* |  git-p4: the option to specify 'host' is -H, not -h\n\n\nAlso as a side note, I noticed that color is lost after new lines.\n\n>\n> > +test_expect_success 'add LF after non-empty (1) (empty)' '\n> > +     git show -s --pretty=format:\"%*d%s%nfoo%n\" HEAD^^ >actual &&\n>\n> Shouldn't this be equivalent to \"%n%-d%s%nfoo%n\", which in turn is covered\n> by one of the previous tests (del LF before empty)?\n\nI think the later is equivalent to %+d%s%nfoo%n, am I wrong?\n"},{"id":"189283","messageId":"CAMP44s0E21sBMPMNGd7GZQbPHeEan+AK2MdGm+8FkWgWHi7sSA@mail.gmail.com","threadId":"29708","inReplyTo":"7v7gzd498r.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] pretty: add '*' modifier to add LF after non-empty","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-04-14T20:01:26Z","receivedAt":"2012-04-14T20:01:26Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Thu, Feb 23, 2012 at 9:53 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Luc Pionchon <pionchon.luc@gmail.com> writes:\n>\n>> Add the '*' modifier, similar to the '+' modifier,\n>> to add a line-feed after a non-empty placeholder.\n>\n> Hrm, I thought I designed the plus and minus fairly carefully so that\n> nobody needs to add this later.\n>\n> Wouldn't it be sufficient to write\n>\n>        Foo%n%-d\n>\n> that says \"We usually have LF after Foo, and write %d after that, but we\n> might not have anything interesting in %d at all, in which case we don't\n> add that %n\"?\n>\n>> +test_expect_success 'add LF after non-empty (1) (empty)' '\n>> +     git show -s --pretty=format:\"%*d%s%nfoo%n\" HEAD^^ >actual &&\n>\n> Shouldn't this be equivalent to \"%n%-d%s%nfoo%n\", which in turn is covered\n> by one of the previous tests (del LF before empty)?\n\nNope.\n\nTry this:\n\n--- a/t/t6006-rev-list-format.sh\n+++ b/t/t6006-rev-list-format.sh\n@@ -208,6 +208,25 @@ test_expect_success 'add LF before non-empty (2)' '\n        grep \"^$\" actual\n '\n\n+test_expect_success 'add LF after non-empty (1) (empty)' '\n+       git show -s --pretty=format:\"%n%-d%s%nfoo%n\" HEAD^^ >actual &&\n+       cat >expect <<-EOF &&\n+       added foo\n+       foo\n+       EOF\n+       test_cmp expect actual\n+'\n+\n+test_expect_success 'add LF after non-empty (2) (non empty)' '\n+       git show -s --pretty=format:\"%n%-d%s%nfoo%n\" HEAD >actual &&\n+       cat >expect <<-EOF &&\n+        (HEAD, master)\n+       Test printing of complex bodies\n+       foo\n+       EOF\n+       test_cmp expect actual\n+'\n+\n test_expect_success 'add SP before non-empty (1)' '\n        git show -s --pretty=format:\"%s% bThanks\" HEAD^^ >actual &&\n        test $(wc -w <actual) = 2\n\nLuc's patch makes these tests work.\n\nI don't know if there's any way to have a format string that works\nwith the current code, but your suggestion doesn't seem to do the\ntrick.\n\nCheers.\n\n-- \nFelipe Contreras\n"}]}