git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Fix `git rev-list --show-notes HEAD` when there are no notes

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Aug 22, 2015, 15:14 UTC
Message-ID
<0LZlZ2-1Z1Zyn1mzk-00lZ3Z@mail.gmx.com>

The `format_display_notes()` function clearly assumes that the data structure holding the notes has been initialized already, i.e. that the `display_notes_trees` variable is no longer `NULL`.

However, when there are no notes whatsoever, this variable is still `NULL`, even after initialization.

So let's be graceful and just return if that data structure is `NULL`.
Reported in https://github.com/msysgit/git/issues/363.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 notes.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/notes.c b/notes.c
index df08209..24a335a 100644
--- a/notes.c
+++ b/notes.c
@@ -1266,7 +1266,10 @@ void format_display_notes(const unsigned char *object_sha1,
 			  struct strbuf *sb, const char *output_encoding, int raw)
 {
 	int i;
-	assert(display_notes_trees);
+
+	if (!display_notes_trees)
+		return;
+
 	for (i = 0; display_notes_trees[i]; i++)
 		format_note(display_notes_trees[i], object_sha1, sb,
 			    output_encoding, raw);
-- 
2.3.1.windows.1.9.g8c01ab4
Next: Johan Herland
Message 1 of 7 in “Fix `git rev-list --show-notes HEAD` when there are no notes”
  1. Fix `git rev-list --show-notes HEAD` when there are no notesJohannes Schindelin, Aug 22, 2015
  2. Johan HerlandAug 22, 2015
  3. Jeff KingAug 23, 2015
  4. rev-list: make it obvious that we do not support notesJeff King, Aug 23, 2015
  5. Johannes SchindelinAug 24, 2015
  6. Jeff KingAug 24, 2015
  7. Johannes SchindelinAug 24, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.