Robert Siemer
Robert Siemer

Reputation: 34667

How to get any output from “git diff-tree --stdin”?

The man-page of git diff-tree suggests that I can do a combined diff (--cc) with a bunch of tree-objects of my choosing. You have to use the --stdin option for this. But I can’t get --stdin to output anything at all.

Example:

$ git diff-tree --stdin
a b
a b
$

Here I typed a<Space>b<Enter>Ctrl-D: It doesn’t even complain that a and b is bad input... But even with valid commit hashes and/or further options I never get any output at all.

What am I doing wrong?

Upvotes: 1

Views: 1312

Answers (2)

VonC
VonC

Reputation: 1323263

Another way:

git rev-list HEAD | git diff-tree --stdin 

But, before Git 2.27 (Q2 2020), "git diff-tree --pretty --notes" used to hit an assertion failure, as it forgot to initialize the notes subsystem.

See commit 5778b22 (21 Apr 2020) by Taylor Blau (ttaylorr).
(Merged by Junio C Hamano -- gitster -- in commit 5a96715, 28 Apr 2020)

diff-tree.c: load notes machinery when required

Reported-by: Jeff King
Signed-off-by: Taylor Blau
Acked-by: Jeff King

Since its introduction in 7249e91 ("[revision.c](https://github.com/git/git/blob/5778b22b3d690495e724276663c36ccd5329da4d/revision.c): support --notes command-line option", 2011-03-29, Git v1.7.6-rc0 -- merge listed in batch #0), 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.

Upvotes: -1

Leon
Leon

Reputation: 32444

You must provide full hashes of commit or tree objects to git diff-tree --stdin:

  $ git log -3 --pretty=%H
  a30ec5de57bbfa0c19045f3c094ec6eb4d808eb4
  f0939d956ad9ef2a00360139a6f1d1ad66accbe5
  fcdb73de293b2442231e5d8ce19f9c7d1640d186

  $ # lines typed on stdin are marked by ->
  $ git diff-tree --stdin
->fcdb73de293b2442231e5d8ce19f9c7d1640d186 a30ec5de57bbfa0c19045f3c094ec6eb4d808eb4
  fcdb73de293b2442231e5d8ce19f9c7d1640d186
  :040000 040000 e2aed2af18fb5293903a0d0b78c23e00a893394d c56666f973b77d92d52b68a14c5a26ac3508571a M    example
  :040000 000000 7cc3373fd5cad3bfe6ec261e9dcc3a9e97efe488 0000000000000000000000000000000000000000 D    prc
  :000000 040000 0000000000000000000000000000000000000000 275872c00a9f51016d2273419345b3b1d7535630 A    src
->275872c00a9f51016d2273419345b3b1d7535630 7cc3373fd5cad3bfe6ec261e9dcc3a9e97efe488
  275872c00a9f51016d2273419345b3b1d7535630 7cc3373fd5cad3bfe6ec261e9dcc3a9e97efe488
  :100644 100644 f26b2198fd9a0103f57a5bd828e58043507ea7b7 c52116f6d185548061058099dfe4c9e50d523aff M    chord.cpp
  :100644 100644 fcbfcdc036fb53733176ed30fd82eb261a990d5b 403e323f332a18b45dfdebfd3a8bfb1a62158bb4 M    chord.hpp
  :100644 100644 11a931f795b44cd916e1607d819eed4d5342edba 333b596faf596d73758bce949e6d86e596153126 M    polyphonic_track.cpp
  :100644 100644 7196835de2385d3f1e0b20073d327cb432ed436c f9fbbac93ef6fc19ae99113ff39a06f4df50720e M    polyphonic_track.hpp

Upvotes: 1

Related Questions