Git fork

diff-tree.c: load notes machinery when required

Since its introduction in 7249e91 (revision.c: support --notes
command-line option, 2011-03-29), combining '--notes' with any option
that causes us to format notes (e.g., '--pretty', '--format="%N"', etc)
results in a failed assertion at runtime.

$ git rev-list HEAD | git diff-tree --stdin --pretty=medium --notes
commit 8f3d9f354286745c751374f5f1fcafee6b3f3136
git: notes.c:1308: format_display_notes: Assertion `display_notes_trees' failed.
Aborted

This failure is due to diff-tree not calling 'load_display_notes' to
initialize the notes machinery.

Ordinarily, this failure isn't triggered, because it requires passing
both '--notes' and another of the above mentioned options. In the case
of '--pretty', for example, we set 'opt->verbose_header', causing
'show_log()' to eventually call 'format_display_notes()', which expects
a non-NULL 'display_note_trees'.

Without initializing the notes machinery, 'display_note_trees' remains
NULL, and thus triggers an assertion failure.

Fix this by initializing the notes machinery after parsing our options,
and harden this behavior against regression with a test in t4013. (Note
that the added ref in this test requires updating two unrelated tests
which use 'log --all', and thus need to learn about the new refs).

Reported-by: Jeff King <peff@peff.net>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Taylor Blau and committed by
Junio C Hamano
5778b22b d0654dc3

+78
+9
builtin/diff-tree.c
··· 109 109 struct object *tree1, *tree2; 110 110 static struct rev_info *opt = &log_tree_opt; 111 111 struct setup_revision_opt s_r_opt; 112 + struct userformat_want w; 112 113 int read_stdin = 0; 113 114 114 115 if (argc == 2 && !strcmp(argv[1], "-h")) ··· 126 127 127 128 precompose_argv(argc, argv); 128 129 argc = setup_revisions(argc, argv, opt, &s_r_opt); 130 + 131 + memset(&w, 0, sizeof(w)); 132 + userformat_find_requirements(NULL, &w); 133 + 134 + if (!opt->show_notes_given && w.notes) 135 + opt->show_notes = 1; 136 + if (opt->show_notes) 137 + load_display_notes(&opt->notes_opt); 129 138 130 139 while (--argc > 0) { 131 140 const char *arg = *++argv;
+12
t/t4013-diff-various.sh
··· 95 95 git commit -m "update mode" && 96 96 git checkout -f master && 97 97 98 + GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" && 99 + GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" && 100 + export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && 101 + git checkout -b note initial && 102 + git update-index --chmod=+x file2 && 103 + git commit -m "update mode (file2)" && 104 + git notes add -m "note" && 105 + git checkout -f master && 106 + 98 107 # Same merge as master, but with parents reversed. Hide it in a 99 108 # pseudo-ref to avoid impacting tests with --all. 100 109 commit=$(echo reverse | ··· 372 381 373 382 diff-tree --pretty --root --stat --compact-summary initial 374 383 diff-tree --pretty -R --root --stat --compact-summary initial 384 + diff-tree --pretty note 385 + diff-tree --pretty --notes note 386 + diff-tree --format=%N note 375 387 diff-tree --stat --compact-summary initial mode 376 388 diff-tree -R --stat --compact-summary initial mode 377 389 EOF
+6
t/t4013/diff.diff-tree_--format=%N_note
··· 1 + $ git diff-tree --format=%N note 2 + note 3 + 4 + 5 + :100644 100755 01e79c32a8c99c557f0757da7cb6d65b3414466d 01e79c32a8c99c557f0757da7cb6d65b3414466d M file2 6 + $
+12
t/t4013/diff.diff-tree_--pretty_--notes_note
··· 1 + $ git diff-tree --pretty --notes note 2 + commit a6f364368ca320bc5a92e18912e16fa6b3dff598 3 + Author: A U Thor <author@example.com> 4 + Date: Mon Jun 26 00:06:00 2006 +0000 5 + 6 + update mode (file2) 7 + 8 + Notes: 9 + note 10 + 11 + :100644 100755 01e79c32a8c99c557f0757da7cb6d65b3414466d 01e79c32a8c99c557f0757da7cb6d65b3414466d M file2 12 + $
+9
t/t4013/diff.diff-tree_--pretty_note
··· 1 + $ git diff-tree --pretty note 2 + commit a6f364368ca320bc5a92e18912e16fa6b3dff598 3 + Author: A U Thor <author@example.com> 4 + Date: Mon Jun 26 00:06:00 2006 +0000 5 + 6 + update mode (file2) 7 + 8 + :100644 100755 01e79c32a8c99c557f0757da7cb6d65b3414466d 01e79c32a8c99c557f0757da7cb6d65b3414466d M file2 9 + $
+15
t/t4013/diff.log_--decorate=full_--all
··· 5 5 6 6 update mode 7 7 8 + commit a6f364368ca320bc5a92e18912e16fa6b3dff598 (refs/heads/note) 9 + Author: A U Thor <author@example.com> 10 + Date: Mon Jun 26 00:06:00 2006 +0000 11 + 12 + update mode (file2) 13 + 14 + Notes: 15 + note 16 + 8 17 commit cd4e72fd96faed3f0ba949dc42967430374e2290 (refs/heads/rearrange) 9 18 Author: A U Thor <author@example.com> 10 19 Date: Mon Jun 26 00:06:00 2006 +0000 11 20 12 21 Rearranged lines in dir/sub 22 + 23 + commit cbacedd14cb8b89255a2c02b59e77a2e9a8021a0 (refs/notes/commits) 24 + Author: A U Thor <author@example.com> 25 + Date: Mon Jun 26 00:06:00 2006 +0000 26 + 27 + Notes added by 'git notes add' 13 28 14 29 commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (HEAD -> refs/heads/master) 15 30 Merge: 9a6d494 c7a2ab9
+15
t/t4013/diff.log_--decorate_--all
··· 5 5 6 6 update mode 7 7 8 + commit a6f364368ca320bc5a92e18912e16fa6b3dff598 (note) 9 + Author: A U Thor <author@example.com> 10 + Date: Mon Jun 26 00:06:00 2006 +0000 11 + 12 + update mode (file2) 13 + 14 + Notes: 15 + note 16 + 8 17 commit cd4e72fd96faed3f0ba949dc42967430374e2290 (rearrange) 9 18 Author: A U Thor <author@example.com> 10 19 Date: Mon Jun 26 00:06:00 2006 +0000 11 20 12 21 Rearranged lines in dir/sub 22 + 23 + commit cbacedd14cb8b89255a2c02b59e77a2e9a8021a0 (refs/notes/commits) 24 + Author: A U Thor <author@example.com> 25 + Date: Mon Jun 26 00:06:00 2006 +0000 26 + 27 + Notes added by 'git notes add' 13 28 14 29 commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (HEAD -> master) 15 30 Merge: 9a6d494 c7a2ab9