# [PATCH] log: fix indentation for --graph --show-signature

3 messages from 2014-07-08 to 2014-07-09. Participants: Zoltan Klinger, Eric Sunshine.
Thread: https://gitlist.dev/t/37075

## Zoltan Klinger, 2014-07-08 11:12

Subject: [PATCH] log: fix indentation for --graph --show-signature
Message-ID: <1404817948-7794-1-git-send-email-zoltan.klinger@gmail.com>
URL: https://gitlist.dev/e/1404817948-7794-1-git-send-email-zoltan.klinger%40gmail.com

```
The git log --graph --show-signature command incorrectly indents the gpg
information about signed commits and merged signed tags. It does not
follow the level of indentation of the current commit.

Example of garbled output:
$ git log --show-signature --graph
*   commit 258e0a237cb69aaa587b0a4fb528bb0316b1b776
|\  gpg: Signature made Mon, Jun 30, 2014 13:22:33 EDT using RSA key ID DA08
gpg: Good signature from "Jason Pyeron <jpye...@pdinc.us>"
Merge: 727c355 1ca13ed
| | Author: Jason Pyeron <jpye...@pdinc.us>
| | Date:   Mon Jun 30 13:22:29 2014 -0400
| |
| |     Merge of 1ca13ed2271d60ba9 branch - rebranding
| |
| * commit 1ca13ed2271d60ba93d40bcc8db17ced8545f172
| | gpg: Signature made Mon, Jun 23, 2014  9:45:47 EDT using RSA key ID DD37
gpg: Good signature from "Stephen Robert Guglielmo <s...@guglielmo.us>"
gpg:                 aka "Stephen Robert Guglielmo <srguglie...@gmail.com>"
Author: Stephen R Guglielmo <s...@guglielmo.us>
| | Date:   Mon Jun 23 09:45:27 2014 -0400
| |
| |     Minor URL updates

In log-tree.c modify show_sig_lines() function to call graph_show_oneline()
after each line of gpg information it has printed in order to preserve
the level of indentation for the next output line.

Reported-by: Jason Pyeron <jpyeron@pdinc.us>
Signed-off-by: Zoltan Klinger <zoltan.klinger@gmail.com>
---
 log-tree.c     |  1 +
 t/t4202-log.sh | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/log-tree.c b/log-tree.c
index 10e6844..f13b861 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -365,6 +365,7 @@ static void show_sig_lines(struct rev_info *opt, int status, const char *bol)
 		eol = strchrnul(bol, '\n');
 		printf("%s%.*s%s%s", color, (int)(eol - bol), bol, reset,
 		       *eol ? "\n" : "");
+		graph_show_oneline(opt->graph);
 		bol = (*eol) ? (eol + 1) : eol;
 	}
 }
diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index cb03d28..b429aff 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -3,6 +3,7 @@
 test_description='git log'
 
 . ./test-lib.sh
+. "$TEST_DIRECTORY/lib-gpg.sh"
 
 test_expect_success setup '
 
@@ -841,4 +842,32 @@ test_expect_success 'dotdot is a parent directory' '
 	test_cmp expect actual
 '
 
+test_expect_success GPG 'log --graph --show-signature' '
+	git checkout -b signed master &&
+	echo foo >foo &&
+	git add foo &&
+	git commit -S -m signed_commit &&
+	git log --graph --show-signature -n1 signed >actual &&
+	grep "^| gpg: Signature made" actual &&
+	grep "^| gpg: Good signature" actual
+'
+
+test_expect_success GPG 'log --graph --show-signature for merged tag' '
+	git checkout -b plain master &&
+	echo aaa >bar &&
+	git add bar &&
+	git commit -m bar_commit
+	git checkout -b tagged master &&
+	echo bbb >baz &&
+	git add baz &&
+	git commit -m baz_commit
+	git tag -s -m signed_tag_msg signed_tag &&
+	git checkout plain &&
+	git merge --no-ff -m msg signed_tag &&
+	git log --graph --show-signature -n1 plain >actual &&
+	grep "^|\\\  merged tag" actual &&
+	grep "^| | gpg: Signature made" actual &&
+	grep "^| | gpg: Good signature" actual
+'
+
 test_done
-- 
2.0.0

```

## Eric Sunshine, 2014-07-08 21:33

Subject: Re: [PATCH] log: fix indentation for --graph --show-signature
Message-ID: <CAPig+cT1xcpH7GzfGO8ZkNsN0=waS34p=Yejd-Mv7che1U0i2Q@mail.gmail.com>
URL: https://gitlist.dev/e/CAPig%2BcT1xcpH7GzfGO8ZkNsN0%3DwaS34p%3DYejd-Mv7che1U0i2Q%40mail.gmail.com
In-Reply-To: <1404817948-7794-1-git-send-email-zoltan.klinger@gmail.com>

```
On Tue, Jul 8, 2014 at 7:12 AM, Zoltan Klinger <zoltan.klinger@gmail.com> wrote:
> The git log --graph --show-signature command incorrectly indents the gpg
> information about signed commits and merged signed tags. It does not
> follow the level of indentation of the current commit.
>
> Reported-by: Jason Pyeron <jpyeron@pdinc.us>
> Signed-off-by: Zoltan Klinger <zoltan.klinger@gmail.com>
> ---
> diff --git a/t/t4202-log.sh b/t/t4202-log.sh
> index cb03d28..b429aff 100755
> --- a/t/t4202-log.sh
> +++ b/t/t4202-log.sh
> @@ -3,6 +3,7 @@
>  test_description='git log'
>
>  . ./test-lib.sh
> +. "$TEST_DIRECTORY/lib-gpg.sh"
>
>  test_expect_success setup '
>
> @@ -841,4 +842,32 @@ test_expect_success 'dotdot is a parent directory' '
>         test_cmp expect actual
>  '
>
> +test_expect_success GPG 'log --graph --show-signature' '
> +       git checkout -b signed master &&

Do you want

    test_when_finished 'git reset --hard && git checkout master' &&

here in case of failure in this test in order to restore sanity for
tests which might be added later?

> +       echo foo >foo &&
> +       git add foo &&
> +       git commit -S -m signed_commit &&
> +       git log --graph --show-signature -n1 signed >actual &&
> +       grep "^| gpg: Signature made" actual &&
> +       grep "^| gpg: Good signature" actual
> +'
> +
> +test_expect_success GPG 'log --graph --show-signature for merged tag' '
> +       git checkout -b plain master &&
> +       echo aaa >bar &&
> +       git add bar &&
> +       git commit -m bar_commit

Broken &&-chain.

> +       git checkout -b tagged master &&

Ditto regarding test_when_finished.

> +       echo bbb >baz &&
> +       git add baz &&
> +       git commit -m baz_commit

Broken &&-chain.

> +       git tag -s -m signed_tag_msg signed_tag &&
> +       git checkout plain &&
> +       git merge --no-ff -m msg signed_tag &&
> +       git log --graph --show-signature -n1 plain >actual &&
> +       grep "^|\\\  merged tag" actual &&
> +       grep "^| | gpg: Signature made" actual &&
> +       grep "^| | gpg: Good signature" actual
> +'
> +
>  test_done
> --
> 2.0.0

```

## Zoltan Klinger, 2014-07-09 02:10

Subject: [PATCH v2] log: fix indentation for --graph --show-signature
Message-ID: <1404871821-12659-1-git-send-email-zoltan.klinger@gmail.com>
URL: https://gitlist.dev/e/1404871821-12659-1-git-send-email-zoltan.klinger%40gmail.com
In-Reply-To: <1404817948-7794-1-git-send-email-zoltan.klinger@gmail.com>

```
The git log --graph --show-signature command incorrectly indents the gpg
information about signed commits and merged signed tags. It does not
follow the level of indentation of the current commit.

Example of garbled output:
$ git log --show-signature --graph
*   commit 258e0a237cb69aaa587b0a4fb528bb0316b1b776
|\  gpg: Signature made Mon, Jun 30, 2014 13:22:33 EDT using RSA key ID DA08
gpg: Good signature from "Jason Pyeron <jpye...@pdinc.us>"
Merge: 727c355 1ca13ed
| | Author: Jason Pyeron <jpye...@pdinc.us>
| | Date:   Mon Jun 30 13:22:29 2014 -0400
| |
| |     Merge of 1ca13ed2271d60ba9 branch - rebranding
| |
| * commit 1ca13ed2271d60ba93d40bcc8db17ced8545f172
| | gpg: Signature made Mon, Jun 23, 2014  9:45:47 EDT using RSA key ID DD37
gpg: Good signature from "Stephen Robert Guglielmo <s...@guglielmo.us>"
gpg:                 aka "Stephen Robert Guglielmo <srguglie...@gmail.com>"
Author: Stephen R Guglielmo <s...@guglielmo.us>
| | Date:   Mon Jun 23 09:45:27 2014 -0400
| |
| |     Minor URL updates

In log-tree.c modify show_sig_lines() function to call graph_show_oneline()
after each line of gpg information it has printed in order to preserve
the level of indentation for the next output line.

Reported-by: Jason Pyeron <jpyeron@pdinc.us>
Signed-off-by: Zoltan Klinger <zoltan.klinger@gmail.com>
---

 Changes since v1:
   t/t4202-log.sh file:
       * fix broken &&-chain in test cases
       * add test_when_finished scripts to  test cases to
         reset things to master branch

 log-tree.c     |  1 +
 t/t4202-log.sh | 31 +++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/log-tree.c b/log-tree.c
index 10e6844..f13b861 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -365,6 +365,7 @@ static void show_sig_lines(struct rev_info *opt, int status, const char *bol)
 		eol = strchrnul(bol, '\n');
 		printf("%s%.*s%s%s", color, (int)(eol - bol), bol, reset,
 		       *eol ? "\n" : "");
+		graph_show_oneline(opt->graph);
 		bol = (*eol) ? (eol + 1) : eol;
 	}
 }
diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index cb03d28..99ab7ca 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -3,6 +3,7 @@
 test_description='git log'
 
 . ./test-lib.sh
+. "$TEST_DIRECTORY/lib-gpg.sh"
 
 test_expect_success setup '
 
@@ -841,4 +842,34 @@ test_expect_success 'dotdot is a parent directory' '
 	test_cmp expect actual
 '
 
+test_expect_success GPG 'log --graph --show-signature' '
+	test_when_finished "git reset --hard && git checkout master" &&
+	git checkout -b signed master &&
+	echo foo >foo &&
+	git add foo &&
+	git commit -S -m signed_commit &&
+	git log --graph --show-signature -n1 signed >actual &&
+	grep "^| gpg: Signature made" actual &&
+	grep "^| gpg: Good signature" actual
+'
+
+test_expect_success GPG 'log --graph --show-signature for merged tag' '
+	test_when_finished "git reset --hard && git checkout master" &&
+	git checkout -b plain master &&
+	echo aaa >bar &&
+	git add bar &&
+	git commit -m bar_commit &&
+	git checkout -b tagged master &&
+	echo bbb >baz &&
+	git add baz &&
+	git commit -m baz_commit &&
+	git tag -s -m signed_tag_msg signed_tag &&
+	git checkout plain &&
+	git merge --no-ff -m msg signed_tag &&
+	git log --graph --show-signature -n1 plain >actual &&
+	grep "^|\\\  merged tag" actual &&
+	grep "^| | gpg: Signature made" actual &&
+	grep "^| | gpg: Good signature" actual
+'
+
 test_done
-- 
2.0.0

```
