{"thread":{"id":"65679","subject":"[PATCH v3 0/4] Add support for an external command for fetching notes","startedAt":"2026-05-23T10:39:19Z","lastAt":"2026-07-29T09:59:00Z","messageCount":12,"participants":["Siddh Raman Pant","Johannes Sixt"],"isPatch":true,"patchVersion":3,"patchTotal":4},"messages":[{"id":"543963","messageId":"cover.1779532562.git.siddh.raman.pant@oracle.com","threadId":"65679","inReplyTo":null,"subject":"[PATCH v3 0/4] Add support for an external command for fetching notes","fromName":"Siddh Raman Pant","fromEmail":"siddh.raman.pant@oracle.com","sentAt":"2026-05-23T10:38:08Z","receivedAt":"2026-05-23T10:39:19Z","isPatch":true,"body":"v2: https://lore.kernel.org/git/cover.1779464886.git.siddh.raman.pant@oracle.com/\nv1: https://lore.kernel.org/git/cover.1779207350.git.siddh.raman.pant@oracle.com/\n\n<...insert text from v1 cover here...>\n\nChanges since v2:\n- Removed stale help text talking about force-killing helper process.\n\nChanges since v1:\n- Removed Documentation commit and sent as a standalone patch.\n- Removed finish_command_with_timeout addition (and thus sleep_nanosec).\n- Squashed the external notes command code, doc, and test commits.\n- Removed horizontal separators from note-external.c.\n- Removed global variables from translation unit and instead store config in\n  a dedicated new struct member in struct display_notes_opt.\n- Reworded the main commit to have better explanation of the motivation.\n\nSiddh Raman Pant (4):\n  notes: convert raw arg in format_display_notes() to bool\n  wrapper: add support for timeout and deadline in read helpers\n  t3301: cover generic displayed notes behavior\n  notes: support an external command to display notes\n\n Documentation/config/notes.adoc             |  59 +++\n Documentation/git-format-patch.adoc         |  11 +-\n Documentation/git-range-diff.adoc           |   6 +\n Documentation/pretty-options.adoc           |   9 +\n Makefile                                    |   2 +\n builtin/log.c                               |  17 +-\n builtin/name-rev.c                          |   9 +-\n builtin/range-diff.c                        |   2 +\n contrib/completion/git-completion.bash      |   4 +-\n log-tree.c                                  |  10 +-\n meson.build                                 |   1 +\n notes-external.c                            | 414 ++++++++++++++++++\n notes-external.h                            |  53 +++\n notes.c                                     | 266 +++++++++---\n notes.h                                     |  33 +-\n revision.c                                  |  36 +-\n strbuf.c                                    |  26 +-\n strbuf.h                                    |   4 +\n t/helper/meson.build                        |   1 +\n t/helper/test-external-notes                |  64 +++\n t/helper/test-notes-external-config-reset.c |  24 ++\n t/helper/test-tool.c                        |   1 +\n t/helper/test-tool.h                        |   1 +\n t/lib-notes.sh                              |  19 +\n t/t3206-range-diff.sh                       |  68 +++\n t/t3301-notes.sh                            | 448 ++++++++++++++++++++\n t/t6120-describe.sh                         |  17 +\n wrapper.c                                   | 139 +++++-\n wrapper.h                                   |  23 +\n 29 files changed, 1691 insertions(+), 76 deletions(-)\n create mode 100644 notes-external.c\n create mode 100644 notes-external.h\n create mode 100755 t/helper/test-external-notes\n create mode 100644 t/helper/test-notes-external-config-reset.c\n create mode 100644 t/lib-notes.sh\n\n-- \n2.53.0\n\n"},{"id":"543964","messageId":"49efc097154be9f7c387ecbaafcf54e612028d9e.1779532562.git.siddh.raman.pant@oracle.com","threadId":"65679","inReplyTo":"cover.1779532562.git.siddh.raman.pant@oracle.com","subject":"[PATCH v3 2/4] wrapper: add support for timeout and deadline in read helpers","fromName":"Siddh Raman Pant","fromEmail":"siddh.raman.pant@oracle.com","sentAt":"2026-05-23T10:38:10Z","receivedAt":"2026-05-23T10:39:30Z","isPatch":true,"body":"Add read helpers which allow a caller to enforce a timeout per read,\nand a deadline for the read in case multiple reads have to be done\nunder a common timeout.\n\nAssisted-by: Codex:gpt-5.5-xhigh-fast\nSigned-off-by: Siddh Raman Pant <siddh.raman.pant@oracle.com>\n---\n strbuf.c  |  26 +++++++++-\n strbuf.h  |   4 ++\n wrapper.c | 139 ++++++++++++++++++++++++++++++++++++++++++++++++++----\n wrapper.h |  23 +++++++++\n 4 files changed, 182 insertions(+), 10 deletions(-)\n\ndiff --git a/strbuf.c b/strbuf.c\nindex 3e04addc22fe..b3fc7c624aa2 100644\n--- a/strbuf.c\n+++ b/strbuf.c\n@@ -749,13 +749,15 @@ int strbuf_getline_nul(struct strbuf *sb, FILE *fp)\n \treturn strbuf_getdelim(sb, fp, '\\0');\n }\n \n-int strbuf_getwholeline_fd(struct strbuf *sb, int fd, int term)\n+static int strbuf_getwholeline_fd_with(struct strbuf *sb, int fd, int term,\n+\t\t\t\t       xread_cb_t xread_cb,\n+\t\t\t\t       void *cb_data)\n {\n \tstrbuf_reset(sb);\n \n \twhile (1) {\n \t\tchar ch;\n-\t\tssize_t len = xread(fd, &ch, 1);\n+\t\tssize_t len = xread_cb(fd, &ch, 1, cb_data);\n \t\tif (len <= 0)\n \t\t\treturn EOF;\n \t\tstrbuf_addch(sb, ch);\n@@ -765,6 +767,26 @@ int strbuf_getwholeline_fd(struct strbuf *sb, int fd, int term)\n \treturn 0;\n }\n \n+int strbuf_getwholeline_fd_deadline(struct strbuf *sb, int fd, int term,\n+\t\t\t\t    uint64_t deadline_ns)\n+{\n+\treturn strbuf_getwholeline_fd_with(sb, fd, term, xread_deadline_fn,\n+\t\t\t\t\t   &deadline_ns);\n+}\n+\n+int strbuf_getwholeline_fd_timeout(struct strbuf *sb, int fd, int term,\n+\t\t\t\t   int timeout_ms)\n+{\n+\treturn strbuf_getwholeline_fd_with(sb, fd, term, xread_timeout_fn,\n+\t\t\t\t\t   &timeout_ms);\n+}\n+\n+/* Non-timeout version for compatibility. */\n+int strbuf_getwholeline_fd(struct strbuf *sb, int fd, int term)\n+{\n+\treturn strbuf_getwholeline_fd_timeout(sb, fd, term, 0);\n+}\n+\n ssize_t strbuf_read_file(struct strbuf *sb, const char *path, size_t hint)\n {\n \tint fd;\ndiff --git a/strbuf.h b/strbuf.h\nindex 06e284f9cca4..f896da1277a6 100644\n--- a/strbuf.h\n+++ b/strbuf.h\n@@ -535,6 +535,10 @@ int strbuf_appendwholeline(struct strbuf *sb, FILE *file, int term);\n  * descriptor.\n  */\n int strbuf_getwholeline_fd(struct strbuf *sb, int fd, int term);\n+int strbuf_getwholeline_fd_timeout(struct strbuf *sb, int fd, int term,\n+\t\t\t\t   int timeout_ms);\n+int strbuf_getwholeline_fd_deadline(struct strbuf *sb, int fd, int term,\n+\t\t\t\t    uint64_t deadline_ns);\n \n /**\n  * Set the buffer to the path of the current working directory.\ndiff --git a/wrapper.c b/wrapper.c\nindex 16f5a63fbb61..1f42845e031e 100644\n--- a/wrapper.c\n+++ b/wrapper.c\n@@ -9,6 +9,7 @@\n #include \"parse.h\"\n #include \"gettext.h\"\n #include \"strbuf.h\"\n+#include \"trace.h\"\n #include \"trace2.h\"\n \n #ifdef HAVE_RTLGENRANDOM\n@@ -220,28 +221,129 @@ static int handle_nonblock(int fd, short poll_events, int err)\n \treturn 1;\n }\n \n-/*\n- * xread() is the same a read(), but it automatically restarts read()\n- * operations with a recoverable error (EAGAIN and EINTR). xread()\n+static int wait_for_fd(int fd, short poll_events, int timeout_ms)\n+{\n+\tstruct pollfd pfd;\n+\n+\tif (timeout_ms < 0) {\n+\t\t/* Negative timeout makes no sense. */\n+\t\terrno = EINVAL;\n+\t\treturn -1;\n+\t}\n+\n+\tpfd.fd = fd;\n+\tpfd.events = poll_events;\n+\n+\twhile(1) {\n+\t\tint ret = poll(&pfd, 1, timeout_ms);\n+\n+\t\tif (ret <= 0) {\n+\t\t\t/* Retry if interrupted. */\n+\t\t\tif (ret < 0 && errno == EINTR)\n+\t\t\t\tcontinue;\n+\n+\t\t\t/* Set errno if timeout happened. */\n+\t\t\tif (ret == 0)\n+\t\t\t\terrno = ETIMEDOUT;\n+\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\t/* Invalid FD passed. */\n+\t\tif (pfd.revents & POLLNVAL) {\n+\t\t\terrno = EBADF;\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\t/* Some error happened. */\n+\t\tif (pfd.revents & POLLERR) {\n+\t\t\terrno = EIO;\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\t/* HangUp => We are ready to consume output till EOF. */\n+\t\tif (pfd.revents & (poll_events | POLLHUP))\n+\t\t\treturn 0;\n+\t}\n+}\n+\n+/**\n+ * xread_timeout() is the same as read(), but it automatically restarts read()\n+ * operations with a recoverable error (EAGAIN and EINTR). xread_timeout()\n  * DOES NOT GUARANTEE that \"len\" bytes is read even if the data is available.\n+ *\n+ * Fails with ETIMEDOUT when no bytes become available within timeout_ms\n+ * milliseconds. A zero timeout disables timeout handling, so reads can\n+ * block until the file descriptor is readable. Negative timeouts are invalid.\n  */\n-ssize_t xread(int fd, void *buf, size_t len)\n+ssize_t xread_timeout(int fd, void *buf, size_t len, int timeout_ms)\n {\n \tssize_t nr;\n+\n \tif (len > MAX_IO_SIZE)\n \t\tlen = MAX_IO_SIZE;\n+\n \twhile (1) {\n+\t\tif (timeout_ms && wait_for_fd(fd, POLLIN, timeout_ms))\n+\t\t\treturn -1;\n+\n \t\tnr = read(fd, buf, len);\n+\n \t\tif (nr < 0) {\n \t\t\tif (errno == EINTR)\n \t\t\t\tcontinue;\n-\t\t\tif (handle_nonblock(fd, POLLIN, errno))\n-\t\t\t\tcontinue;\n+\n+\t\t\tif (timeout_ms) {\n+\t\t\t\tif (errno == EAGAIN || errno == EWOULDBLOCK)\n+\t\t\t\t\tcontinue;\n+\t\t\t} else {\n+\t\t\t\tif (handle_nonblock(fd, POLLIN, errno))\n+\t\t\t\t\tcontinue;\n+\t\t\t}\n \t\t}\n+\n \t\treturn nr;\n \t}\n }\n \n+/* Non-timeout version for compatibility. */\n+ssize_t xread(int fd, void *buf, size_t len)\n+{\n+\treturn xread_timeout(fd, buf, len, 0);\n+}\n+\n+static int remaining_timeout_ms(uint64_t deadline_ns)\n+{\n+\tuint64_t now, remaining_ns;\n+\n+\tif (!deadline_ns)\n+\t\treturn 0;\n+\n+\tnow = getnanotime();\n+\tif (now >= deadline_ns) {\n+\t\terrno = ETIMEDOUT;\n+\t\treturn -1;\n+\t}\n+\n+\tremaining_ns = deadline_ns - now;\n+\treturn (int)((remaining_ns + 999999ULL) / 1000000ULL);\n+}\n+\n+/* (deadline_ns = 0) disables the deadline and short-circuits to xread(). */\n+ssize_t xread_deadline(int fd, void *buf, size_t len, uint64_t deadline_ns)\n+{\n+\tint timeout_ms;\n+\n+\tif (deadline_ns == 0)\n+\t\treturn xread(fd, buf, len);\n+\n+\ttimeout_ms = remaining_timeout_ms(deadline_ns);\n+\tif (timeout_ms < 0)\n+\t\treturn -1;\n+\n+\treturn xread_timeout(fd, buf, len, timeout_ms);\n+}\n+\n /*\n  * xwrite() is the same a write(), but it automatically restarts write()\n  * operations with a recoverable error (EAGAIN and EINTR). xwrite() DOES NOT\n@@ -283,13 +385,15 @@ ssize_t xpread(int fd, void *buf, size_t len, off_t offset)\n \t}\n }\n \n-ssize_t read_in_full(int fd, void *buf, size_t count)\n+static ssize_t read_in_full_with(int fd, void *buf, size_t count,\n+\t\t\t\t xread_cb_t xread_cb,\n+\t\t\t\t void *cb_data)\n {\n \tchar *p = buf;\n \tssize_t total = 0;\n \n \twhile (count > 0) {\n-\t\tssize_t loaded = xread(fd, p, count);\n+\t\tssize_t loaded = xread_cb(fd, p, count, cb_data);\n \t\tif (loaded < 0)\n \t\t\treturn -1;\n \t\tif (loaded == 0)\n@@ -302,6 +406,25 @@ ssize_t read_in_full(int fd, void *buf, size_t count)\n \treturn total;\n }\n \n+ssize_t read_in_full_deadline(int fd, void *buf, size_t count,\n+\t\t\t      uint64_t deadline_ns)\n+{\n+\treturn read_in_full_with(fd, buf, count, xread_deadline_fn,\n+\t\t\t\t &deadline_ns);\n+}\n+\n+ssize_t read_in_full_timeout(int fd, void *buf, size_t count, int timeout_ms)\n+{\n+\treturn read_in_full_with(fd, buf, count, xread_timeout_fn,\n+\t\t\t\t &timeout_ms);\n+}\n+\n+/* Non-timeout version for compatibility. */\n+ssize_t read_in_full(int fd, void *buf, size_t count)\n+{\n+\treturn read_in_full_timeout(fd, buf, count, 0);\n+}\n+\n ssize_t write_in_full(int fd, const void *buf, size_t count)\n {\n \tconst char *p = buf;\ndiff --git a/wrapper.h b/wrapper.h\nindex 15ac3bab6e97..10d85c467b86 100644\n--- a/wrapper.h\n+++ b/wrapper.h\n@@ -15,6 +15,8 @@ const char *mmap_os_err(void);\n void *xmmap_gently(void *start, size_t length, int prot, int flags, int fd, off_t offset);\n int xopen(const char *path, int flags, ...);\n ssize_t xread(int fd, void *buf, size_t len);\n+ssize_t xread_timeout(int fd, void *buf, size_t len, int timeout_ms);\n+ssize_t xread_deadline(int fd, void *buf, size_t len, uint64_t deadline_ns);\n ssize_t xwrite(int fd, const void *buf, size_t len);\n ssize_t xpread(int fd, void *buf, size_t len, off_t offset);\n int xdup(int fd);\n@@ -44,9 +46,30 @@ int git_mkstemps_mode(char *pattern, int suffix_len, int mode);\n int git_mkstemp_mode(char *pattern, int mode);\n \n ssize_t read_in_full(int fd, void *buf, size_t count);\n+ssize_t read_in_full_timeout(int fd, void *buf, size_t count, int timeout_ms);\n+ssize_t read_in_full_deadline(int fd, void *buf, size_t count,\n+\t\t\t      uint64_t deadline_ns);\n ssize_t write_in_full(int fd, const void *buf, size_t count);\n ssize_t pread_in_full(int fd, void *buf, size_t count, off_t offset);\n \n+typedef ssize_t xread_cb_t(int fd, void *buf, size_t len, const void *cb_data);\n+\n+static inline ssize_t xread_timeout_fn(int fd, void *buf, size_t len,\n+\t\t\t\t       const void *cb_data)\n+{\n+\tconst int *timeout_ms = cb_data;\n+\n+\treturn xread_timeout(fd, buf, len, *timeout_ms);\n+}\n+\n+static inline ssize_t xread_deadline_fn(int fd, void *buf, size_t len,\n+\t\t\t\t\tconst void *cb_data)\n+{\n+\tconst uint64_t *deadline_ns = cb_data;\n+\n+\treturn xread_deadline(fd, buf, len, *deadline_ns);\n+}\n+\n static inline ssize_t write_str_in_full(int fd, const char *str)\n {\n \treturn write_in_full(fd, str, strlen(str));\n-- \n2.53.0\n\n"},{"id":"543965","messageId":"f5199e24faddbef3edcc69bd627590c9fccf0db6.1779532562.git.siddh.raman.pant@oracle.com","threadId":"65679","inReplyTo":"cover.1779532562.git.siddh.raman.pant@oracle.com","subject":"[PATCH v3 1/4] notes: convert raw arg in format_display_notes() to bool","fromName":"Siddh Raman Pant","fromEmail":"siddh.raman.pant@oracle.com","sentAt":"2026-05-23T10:38:09Z","receivedAt":"2026-05-23T10:39:30Z","isPatch":true,"body":"It's used as a boolean flag, let's not use an int.\n\nSigned-off-by: Siddh Raman Pant <siddh.raman.pant@oracle.com>\n---\n log-tree.c | 3 +--\n notes.c    | 6 +++---\n notes.h    | 2 +-\n revision.c | 2 +-\n 4 files changed, 6 insertions(+), 7 deletions(-)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex 7e048701d0c5..4503a42dde6b 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -854,10 +854,9 @@ void show_log(struct rev_info *opt)\n \t}\n \n \tif (opt->show_notes) {\n-\t\tint raw;\n \t\tstruct strbuf notebuf = STRBUF_INIT;\n+\t\tbool raw = (opt->commit_format == CMIT_FMT_USERFORMAT);\n \n-\t\traw = (opt->commit_format == CMIT_FMT_USERFORMAT);\n \t\tformat_display_notes(&commit->object.oid, &notebuf,\n \t\t\t\t     get_log_output_encoding(), raw);\n \t\tctx.notes_message = strbuf_detach(&notebuf, NULL);\ndiff --git a/notes.c b/notes.c\nindex 8f315e2a00d2..201f1df3dc29 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -1273,11 +1273,11 @@ void free_notes(struct notes_tree *t)\n  * If the given notes_tree is NULL, the internal/default notes_tree will be\n  * used instead.\n  *\n- * (raw != 0) gives the %N userformat; otherwise, the note message is given\n+ * (raw == true) gives the %N userformat; otherwise, the note message is given\n  * for human consumption.\n  */\n static void format_note(struct notes_tree *t, const struct object_id *object_oid,\n-\t\t\tstruct strbuf *sb, const char *output_encoding, int raw)\n+\t\t\tstruct strbuf *sb, const char *output_encoding, bool raw)\n {\n \tstatic const char utf8[] = \"utf-8\";\n \tconst struct object_id *oid;\n@@ -1338,7 +1338,7 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid\n }\n \n void format_display_notes(const struct object_id *object_oid,\n-\t\t\t  struct strbuf *sb, const char *output_encoding, int raw)\n+\t\t\t  struct strbuf *sb, const char *output_encoding, bool raw)\n {\n \tint i;\n \tassert(display_notes_trees);\ndiff --git a/notes.h b/notes.h\nindex 6dc6d7b26548..f6410b31e1c9 100644\n--- a/notes.h\n+++ b/notes.h\n@@ -313,7 +313,7 @@ void load_display_notes(struct display_notes_opt *opt);\n  * You *must* call load_display_notes() before using this function.\n  */\n void format_display_notes(const struct object_id *object_oid,\n-\t\t\t  struct strbuf *sb, const char *output_encoding, int raw);\n+\t\t\t  struct strbuf *sb, const char *output_encoding, bool raw);\n \n /*\n  * Load the notes tree from each ref listed in 'refs'.  The output is\ndiff --git a/revision.c b/revision.c\nindex 599b3a66c369..cd9fcefa0a88 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -4107,7 +4107,7 @@ static int commit_match(struct commit *commit, struct rev_info *opt)\n \tif (opt->show_notes) {\n \t\tif (!buf.len)\n \t\t\tstrbuf_addstr(&buf, message);\n-\t\tformat_display_notes(&commit->object.oid, &buf, encoding, 1);\n+\t\tformat_display_notes(&commit->object.oid, &buf, encoding, true);\n \t}\n \n \t/*\n-- \n2.53.0\n\n"},{"id":"543966","messageId":"e494bea038262847ea14d223718f6059e52c1f40.1779532562.git.siddh.raman.pant@oracle.com","threadId":"65679","inReplyTo":"cover.1779532562.git.siddh.raman.pant@oracle.com","subject":"[PATCH v3 3/4] t3301: cover generic displayed notes behavior","fromName":"Siddh Raman Pant","fromEmail":"siddh.raman.pant@oracle.com","sentAt":"2026-05-23T10:38:11Z","receivedAt":"2026-05-23T10:39:58Z","isPatch":true,"body":"Displayed notes already participate in common log behavior.\nAdd explicit coverage for raw notes formatting, --no-notes\nsuppression, explicit notes refs, and --grep matching before\nteaching external notes to feed the same display path.\n\nAssisted-by: Codex:gpt-5.5-xhigh-fast\nSigned-off-by: Siddh Raman Pant <siddh.raman.pant@oracle.com>\n---\n t/t3301-notes.sh | 24 ++++++++++++++++++++++++\n 1 file changed, 24 insertions(+)\n\ndiff --git a/t/t3301-notes.sh b/t/t3301-notes.sh\nindex d6c50460d086..27439010dfbc 100755\n--- a/t/t3301-notes.sh\n+++ b/t/t3301-notes.sh\n@@ -885,6 +885,30 @@ test_expect_success '--show-notes=ref accumulates' '\n \ttest_cmp expect-both-reversed actual\n '\n \n+test_expect_success 'displayed notes honor raw notes formatting' '\n+\tgit show -s --format=%N >actual &&\n+\ttest_grep \"^order test$\" actual &&\n+\t! grep \"Notes\" actual\n+'\n+\n+test_expect_success 'displayed notes are suppressed by --no-notes' '\n+\tgit log --no-notes -1 >actual &&\n+\ttest_cmp expect-not-other actual\n+'\n+\n+test_expect_success 'explicit notes ref replaces default displayed notes' '\n+\tgit log --notes=other -1 >actual &&\n+\ttest_cmp expect-other actual\n+'\n+\n+test_expect_success 'displayed notes are used for grep matching' '\n+\tcommit=$(git rev-parse HEAD) &&\n+\tgit log --grep=\"order test\" -1 >actual &&\n+\ttest_grep \"^commit $commit$\" actual &&\n+\tgit log --no-notes --grep=\"order test\" -1 >actual &&\n+\ttest_must_be_empty actual\n+'\n+\n test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '\n \ttest_config core.notesRef refs/notes/other &&\n \techo \"Note on a tree\" >expect &&\n-- \n2.53.0\n\n"},{"id":"543967","messageId":"7284a8bccb6bfb5734adb09f05ae4b61a63da2df.1779532562.git.siddh.raman.pant@oracle.com","threadId":"65679","inReplyTo":"cover.1779532562.git.siddh.raman.pant@oracle.com","subject":"[PATCH v3 4/4] notes: support an external command to display notes","fromName":"Siddh Raman Pant","fromEmail":"siddh.raman.pant@oracle.com","sentAt":"2026-05-23T10:38:12Z","receivedAt":"2026-05-23T10:40:06Z","isPatch":true,"body":"git notes is a very very helpful feature to show user-supplied\ninformation about a commit alongside its message transparently.\n\nFor distributed teams working on large git repos (huge number of\nbranches/refs, files, etc.) and using the notes feature to mark\ninformation on git commits, the problem is often not that two users\nupdate the same note object at the same time. It is that the local\nnotes state used while reading history can be stale.\n\nIn kernel work, the same logical upstream fix can appear as different\ncommit objects across many downstream branches, such as the stable\nbranches and vendor-specific branches (based on which the released\nkernel is actually built). Different developers may be working on those\nbranches in parallel, and a review decision recorded for one backport\nis useful context for the others.\n\nToday, seeing that decision in ordinary history output requires first\nsynchronizing the local notes ref, and then interpreting those notes\nfor the branch being inspected. The latter step is workflow-specific\nand can be cheap, but keeping the local notes state fresh enough can be\nexpensive in a large kernel repository with a large shared notes\nhistory (and if we are to extrapolate, a slow git server conn/ops can\nbe a factor too).\n\nThis TOCTOU problem exacerbates on scale (rapid updates, more devs,\nlarger repos, more git server traffic, etc).\n\nOne solution to this is to move the freshness policy out of git so that\nit is someone else's problem. We can have a realtime fetch or faster\nupdation via external helper means. But unfortunately we lose the\ncoherence in the display of information, and so the user would end up\nreinventing git log in his quest to have same workflow.\n\nLet's add support for notes.externalCommand, a protected-configuration\ncommand that git runs as a long-lived helper when displaying notes. git\nsends commit IDs to the helper and displays any returned text through\nthe existing notes formatting path. This keeps presentation in git\nwhile letting the helper decide how fresh note text is obtained.\n\nWe also add configuration for the displayed notes header name, timeout\nenforcement for the helper so that git doesn't hang waiting on it,\noptional --grep participation, and command-line controls to enable or\ndisable external notes. The new help text should make the usage clear.\n\nAssisted-by: Codex:gpt-5.5-xhigh-fast\nSigned-off-by: Siddh Raman Pant <siddh.raman.pant@oracle.com>\n---\n Documentation/config/notes.adoc             |  59 +++\n Documentation/git-format-patch.adoc         |  11 +-\n Documentation/git-range-diff.adoc           |   6 +\n Documentation/pretty-options.adoc           |   9 +\n Makefile                                    |   2 +\n builtin/log.c                               |  17 +-\n builtin/name-rev.c                          |   9 +-\n builtin/range-diff.c                        |   2 +\n contrib/completion/git-completion.bash      |   4 +-\n log-tree.c                                  |   7 +-\n meson.build                                 |   1 +\n notes-external.c                            | 414 +++++++++++++++++++\n notes-external.h                            |  53 +++\n notes.c                                     | 264 +++++++++---\n notes.h                                     |  33 +-\n revision.c                                  |  36 +-\n t/helper/meson.build                        |   1 +\n t/helper/test-external-notes                |  64 +++\n t/helper/test-notes-external-config-reset.c |  24 ++\n t/helper/test-tool.c                        |   1 +\n t/helper/test-tool.h                        |   1 +\n t/lib-notes.sh                              |  19 +\n t/t3206-range-diff.sh                       |  68 ++++\n t/t3301-notes.sh                            | 424 ++++++++++++++++++++\n t/t6120-describe.sh                         |  17 +\n 25 files changed, 1483 insertions(+), 63 deletions(-)\n create mode 100644 notes-external.c\n create mode 100644 notes-external.h\n create mode 100755 t/helper/test-external-notes\n create mode 100644 t/helper/test-notes-external-config-reset.c\n create mode 100644 t/lib-notes.sh\n\ndiff --git a/Documentation/config/notes.adoc b/Documentation/config/notes.adoc\nindex b7e536496f51..023ec6c5d8d1 100644\n--- a/Documentation/config/notes.adoc\n+++ b/Documentation/config/notes.adoc\n@@ -34,6 +34,65 @@ The effective value of `core.notesRef` (possibly overridden by\n `GIT_NOTES_REF`) is also implicitly added to the list of refs to be\n displayed.\n \n+`notes.externalCommand`::\n+\tCommand to invoke as a long-lived helper when showing commit messages\n+\twith the `git log` family of commands. Git sends one commit object ID\n+\tper request on the command's standard input:\n++\n+------------\n+<hex-commit-id>\n+------------\n++\n+For each request, the helper must respond on its standard output with either\n+`<hex-commit-id> missing` followed by a newline, or `<hex-commit-id> ok <n>`\n+followed by a newline and exactly `<n>` bytes of UTF-8 note text followed by a\n+newline. The helper must respond to each request as it is received; Git does\n+not send all commit object IDs before reading responses. Empty note text is not\n+displayed. External notes are only used while formatting output by default; see\n+`notes.externalCommandForGrep` to include them when matching commits.\n++\n+If Git cannot start or communicate with the helper, or the helper sends an\n+invalid response, Git warns once and disables it for the rest of the Git run.\n+The process is closed using SIGTERM, so the helper should not trap it.\n++\n+This setting is only respected in protected configuration (see\n+linkgit:git-config[1]). This prevents untrusted repositories from running\n+arbitrary commands when notes are displayed.\n++\n+This setting does not take effect when:\n++\n+--\n+* the value is empty;\n+* `--no-notes` is given;\n+* `--no-external-notes` is given; or\n+* `--notes=<ref>` is given by itself without `--external-notes` or `--notes`.\n+--\n+\n+`notes.externalCommandName`::\n+\tName to use in the `Notes (<name>):` header for notes returned by\n+\t`notes.externalCommand`. Defaults to `external`. This setting is only\n+\trespected in protected configuration.\n+\n+`notes.externalCommandTimeoutMs`::\n+\tNumber of milliseconds to wait when reading each response from\n+\t`notes.externalCommand`. Defaults to `100`. If the command does not\n+\tproduce the expected response in time, Git warns once and disables it\n+\tfor the rest of the command. A value of `0` disables timeout handling,\n+\tso reads can block until the command writes output or exits. This\n+\tsetting is only\trespected in protected configuration.\n+\n+`notes.externalCommandForGrep`::\n+\tBoolean indicating whether notes returned by `notes.externalCommand`\n+\tare included when matching commits with `--grep`, wherever notes would\n+\tnormally participate in grep matching. Defaults to false. This does\n+\tnot make hidden notes searchable in formats such as `--oneline` or\n+\t`--pretty=%s`; use `--notes` or `--external-notes` if those formats\n+\tshould search notes too. When enabled, revision traversal may invoke\n+\tthe external command for many commits that are not ultimately\n+\tdisplayed, which can be expensive for slow commands. The note output\n+\tcan also change which commits match. This setting is only respected in\n+\tprotected configuration.\n+\n `notes.rewrite.<command>`::\n \tWhen rewriting commits with _<command>_ (currently `amend` or\n \t`rebase`), if this variable is `false`, git will not copy\ndiff --git a/Documentation/git-format-patch.adoc b/Documentation/git-format-patch.adoc\nindex 566238245028..472b37e5237a 100644\n--- a/Documentation/git-format-patch.adoc\n+++ b/Documentation/git-format-patch.adoc\n@@ -26,7 +26,7 @@ SYNOPSIS\n \t\t   [--[no-]cover-letter] [--quiet]\n \t\t   [--commit-list-format=<format-spec>]\n \t\t   [--[no-]encode-email-headers]\n-\t\t   [--no-notes | --notes[=<ref>]]\n+\t\t   [--no-notes | --notes[=<ref>]] [--[no-]external-notes]\n \t\t   [--interdiff=<previous>]\n \t\t   [--range-diff=<previous> [--creation-factor=<percent>]]\n \t\t   [--filename-max-length=<n>]\n@@ -395,6 +395,15 @@ configuration options in linkgit:git-notes[1] to use this workflow).\n The default is `--no-notes`, unless the `format.notes` configuration is\n set.\n \n+--external-notes::\n+--no-external-notes::\n+\tInvoke or do not invoke `notes.externalCommand` to obtain external\n+\tnotes. Like `--notes=<ref>`, `--external-notes` names an explicit\n+\tnote source and by itself does not include the default notes refs.\n+\tUse `--external-notes --notes` to include the default notes refs\n+\ttoo, or combine `--external-notes` with `--notes=<ref>` to include\n+\texternal notes with specific notes refs.\n+\n --signature=<signature>::\n --no-signature::\n \tAdd a signature to each message produced. Per RFC 3676 the signature\ndiff --git a/Documentation/git-range-diff.adoc b/Documentation/git-range-diff.adoc\nindex 5cc5e2ed5673..1de23f300517 100644\n--- a/Documentation/git-range-diff.adoc\n+++ b/Documentation/git-range-diff.adoc\n@@ -12,6 +12,7 @@ git range-diff [--color=[<when>]] [--no-color] [<diff-options>]\n \t[--no-dual-color] [--creation-factor=<factor>]\n \t[--left-only | --right-only] [--diff-merges=<format>]\n \t[--remerge-diff] [--no-notes | --notes[=<ref>]]\n+\t[--[no-]external-notes]\n \t( <range1> <range2> | <rev1>...<rev2> | <base> <rev1> <rev2> )\n \t[[--] <path>...]\n \n@@ -101,6 +102,11 @@ diff.\n \tThis flag is passed to the `git log` program\n \t(see linkgit:git-log[1]) that generates the patches.\n \n+`--external-notes`::\n+`--no-external-notes`::\n+\tThis flag is passed to the `git log` program\n+\t(see linkgit:git-log[1]) that generates the patches.\n+\n `<range1> <range2>`::\n \tCompare the commits specified by the two ranges, where\n \t_<range1>_ is considered an older version of _<range2>_.\ndiff --git a/Documentation/pretty-options.adoc b/Documentation/pretty-options.adoc\nindex 658e462b2533..aad851c92cfd 100644\n--- a/Documentation/pretty-options.adoc\n+++ b/Documentation/pretty-options.adoc\n@@ -93,6 +93,15 @@ being displayed. Examples: \"`--notes=foo`\" will show only notes from\n \t\"`--notes --notes=foo --no-notes --notes=bar`\" will only show notes\n \tfrom `refs/notes/bar`.\n \n+`--external-notes`::\n+`--no-external-notes`::\n+\tInvoke or do not invoke `notes.externalCommand` to obtain external\n+\tnotes. Like `--notes=<ref>`, `--external-notes` names an explicit\n+\tnote source and by itself does not include the default notes refs.\n+\tUse `--external-notes --notes` to include the default notes refs\n+\ttoo, or combine `--external-notes` with `--notes=<ref>` to include\n+\texternal notes with specific notes refs.\n+\n `--show-notes-by-default`::\n \tShow the default notes unless options for displaying specific\n \tnotes are given.\ndiff --git a/Makefile b/Makefile\nindex fb50c57e4f25..898da8936e84 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -834,6 +834,7 @@ TEST_BUILTINS_OBJS += test-match-trees.o\n TEST_BUILTINS_OBJS += test-mergesort.o\n TEST_BUILTINS_OBJS += test-mktemp.o\n TEST_BUILTINS_OBJS += test-name-hash.o\n+TEST_BUILTINS_OBJS += test-notes-external-config-reset.o\n TEST_BUILTINS_OBJS += test-online-cpus.o\n TEST_BUILTINS_OBJS += test-pack-deltas.o\n TEST_BUILTINS_OBJS += test-pack-mtimes.o\n@@ -1206,6 +1207,7 @@ LIB_OBJS += negotiator/default.o\n LIB_OBJS += negotiator/noop.o\n LIB_OBJS += negotiator/skipping.o\n LIB_OBJS += notes-cache.o\n+LIB_OBJS += notes-external.o\n LIB_OBJS += notes-merge.o\n LIB_OBJS += notes-utils.o\n LIB_OBJS += notes.o\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 8c0939dd42ad..bed4c1576f2d 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1337,9 +1337,24 @@ static void get_notes_args(struct strvec *arg, struct rev_info *rev)\n \t\t   (rev->notes_opt.use_default_notes == -1 &&\n \t\t    !rev->notes_opt.extra_notes_refs.nr)) {\n \t\tstrvec_push(arg, \"--notes\");\n-\t} else {\n+\t} else if (rev->notes_opt.extra_notes_refs.nr) {\n \t\tfor_each_string_list(&rev->notes_opt.extra_notes_refs, get_notes_refs, arg);\n+\t} else if (rev->notes_opt.use_external_notes <= 0) {\n+\t\t/*\n+\t\t * rev->show_notes can stay set after\n+\t\t * --external-notes --no-external-notes.\n+\t\t *\n+\t\t * Since range-diff's child log starts with\n+\t\t * --show-notes-by-default, explicitly suppress\n+\t\t * notes when no notes source remains.\n+\t\t */\n+\t\tstrvec_push(arg, \"--no-notes\");\n \t}\n+\n+\tif (rev->notes_opt.use_external_notes > 0)\n+\t\tstrvec_push(arg, \"--external-notes\");\n+\telse if (rev->notes_opt.use_external_notes == 0)\n+\t\tstrvec_push(arg, \"--no-external-notes\");\n }\n \n static void generate_shortlog_cover_letter(struct shortlog *log,\ndiff --git a/builtin/name-rev.c b/builtin/name-rev.c\nindex 60cbbfb4b7d1..5a0e7daac803 100644\n--- a/builtin/name-rev.c\n+++ b/builtin/name-rev.c\n@@ -277,6 +277,7 @@ struct name_ref_data {\n struct pretty_format {\n \tstruct pretty_print_context ctx;\n \tstruct userformat_want want;\n+\tstruct external_notes_state *external_notes_state;\n };\n \n enum command_type {\n@@ -525,9 +526,9 @@ static const char *get_format_rev(const struct commit *c,\n \tif (format_ctx->want.notes) {\n \t\tstruct strbuf notebuf = STRBUF_INIT;\n \n-\t\tformat_display_notes(&c->object.oid, &notebuf,\n-\t\t\t\t     get_log_output_encoding(),\n-\t\t\t\t     format_ctx->ctx.fmt == CMIT_FMT_USERFORMAT);\n+\t\tformat_display_notes(c, &notebuf, get_log_output_encoding(),\n+\t\t\t\t     format_ctx->ctx.fmt == CMIT_FMT_USERFORMAT,\n+\t\t\t\t     format_ctx->external_notes_state);\n \t\tformat_ctx->ctx.notes_message = strbuf_detach(&notebuf, NULL);\n \t}\n \n@@ -879,6 +880,8 @@ int cmd_format_rev(int argc,\n \t\t\t\t\t\t &ignore_show_notes,\n \t\t\t\t\t\t n->string);\n \t\tload_display_notes(&format_notes_opt);\n+\t\tformat_pp.external_notes_state =\n+\t\t\tformat_notes_opt.external_notes_state;\n \t}\n \n \tinit_format_rev_command(&cmd, &format_pp);\ndiff --git a/builtin/range-diff.c b/builtin/range-diff.c\nindex e54c0f7fe156..41c27250404a 100644\n--- a/builtin/range-diff.c\n+++ b/builtin/range-diff.c\n@@ -56,6 +56,8 @@ int cmd_range_diff(int argc,\n \t\tOPT_PASSTHRU_ARGV(0, \"notes\", &log_arg,\n \t\t\t\t  N_(\"notes\"), N_(\"passed to 'git log'\"),\n \t\t\t\t  PARSE_OPT_OPTARG),\n+\t\tOPT_PASSTHRU_ARGV(0, \"external-notes\", &log_arg, NULL,\n+\t\t\t\t  N_(\"passed to 'git log'\"), PARSE_OPT_NOARG),\n \t\tOPT_PASSTHRU_ARGV(0, \"diff-merges\", &diff_merges_arg,\n \t\t\t\t  N_(\"style\"), N_(\"passed to 'git log'\"), 0),\n \t\tOPT_CALLBACK(0, \"max-memory\", &range_diff_opts.max_memory,\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex a8e7c6ddbfb2..146444e65860 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -2023,7 +2023,7 @@ _git_fetch ()\n \n __git_format_patch_extra_options=\"\n \t--full-index --not --all --no-prefix --src-prefix=\n-\t--dst-prefix= --notes\n+\t--dst-prefix= --notes --external-notes --no-external-notes\n \"\n \n _git_format_patch ()\n@@ -2215,7 +2215,7 @@ __git_log_common_options=\"\n __git_log_gitk_options=\"\n \t--dense --sparse --full-history\n \t--simplify-merges --simplify-by-decoration\n-\t--left-right --notes --no-notes\n+\t--left-right --notes --no-notes --external-notes --no-external-notes\n \"\n # Options that go well for log and shortlog (not gitk)\n __git_log_shortlog_options=\"\ndiff --git a/log-tree.c b/log-tree.c\nindex 4503a42dde6b..f37c8b14e9a1 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -856,9 +856,12 @@ void show_log(struct rev_info *opt)\n \tif (opt->show_notes) {\n \t\tstruct strbuf notebuf = STRBUF_INIT;\n \t\tbool raw = (opt->commit_format == CMIT_FMT_USERFORMAT);\n+\t\tconst struct display_notes_opt *notes_opt = &opt->notes_opt;\n+\n+\t\tformat_display_notes(commit, &notebuf,\n+\t\t\t\t     get_log_output_encoding(), raw,\n+\t\t\t\t     notes_opt->external_notes_state);\n \n-\t\tformat_display_notes(&commit->object.oid, &notebuf,\n-\t\t\t\t     get_log_output_encoding(), raw);\n \t\tctx.notes_message = strbuf_detach(&notebuf, NULL);\n \t}\n \ndiff --git a/meson.build b/meson.build\nindex 052c81f2887b..83845f84fed0 100644\n--- a/meson.build\n+++ b/meson.build\n@@ -397,6 +397,7 @@ libgit_sources = [\n   'notes-merge.c',\n   'notes-utils.c',\n   'notes.c',\n+  'notes-external.c',\n   'object-file-convert.c',\n   'object-file.c',\n   'object-name.c',\ndiff --git a/notes-external.c b/notes-external.c\nnew file mode 100644\nindex 000000000000..09da102a7901\n--- /dev/null\n+++ b/notes-external.c\n@@ -0,0 +1,414 @@\n+#include \"git-compat-util.h\"\n+#include \"gettext.h\"\n+#include \"hex.h\"\n+#include \"notes-external.h\"\n+#include \"run-command.h\"\n+#include \"sigchain.h\"\n+#include \"strbuf.h\"\n+#include \"trace.h\"\n+\n+#define convert_ms_to_ns(ms) (uint64_t)(ms) * 1000000ULL\n+#define convert_ns_to_ms(ns) (uint64_t)(ns) / 1000000ULL\n+#define EXTERNAL_NOTES_DEFAULT_TIMEOUT_MS 100\n+#define EXTERNAL_NOTES_READ_CHUNK_SIZE 16384\t/* (16 * 1024) bytes */\n+\n+/* Configuration helpers. */\n+\n+static void init_external_notes_config(struct external_notes_config *config)\n+{\n+\tif (!config)\n+\t\treturn;\n+\n+\tmemset(config, 0, sizeof(*config));\n+\tconfig->read_timeout_ns =\n+\t\tconvert_ms_to_ns(EXTERNAL_NOTES_DEFAULT_TIMEOUT_MS);\n+}\n+\n+static void release_external_notes_config(struct external_notes_config *config)\n+{\n+\tif (!config)\n+\t\treturn;\n+\n+\tFREE_AND_NULL(config->command);\n+\tFREE_AND_NULL(config->command_name_value);\n+}\n+\n+struct external_notes_state *external_notes_new(void)\n+{\n+\tstruct external_notes_state *state = xcalloc(1, sizeof(*state));\n+\n+\tinit_external_notes_config(&state->config);\n+\tchild_process_init(&state->process.process);\n+\tstate->process.out_fd = -1;\n+\n+\treturn state;\n+}\n+\n+void set_external_notes_command(struct external_notes_state *state,\n+\t\t\t\tconst char *command)\n+{\n+\tstruct external_notes_config *config;\n+\n+\tif (!state)\n+\t\treturn;\n+\n+\tconfig = &state->config;\n+\tFREE_AND_NULL(config->command);\n+\n+\tif (command && *command)\n+\t\tconfig->command = xstrdup(command);\n+}\n+\n+bool external_notes_command_configured(const struct external_notes_state *state)\n+{\n+\treturn state && state->config.command && !state->process.failed;\n+}\n+\n+void external_notes_reset(struct external_notes_state *state)\n+{\n+\tif (!state)\n+\t\treturn;\n+\n+\tif (state->process.started)\n+\t\tBUG(\"cannot reset external notes config while cmd is running\");\n+\n+\trelease_external_notes_config(&state->config);\n+\tinit_external_notes_config(&state->config);\n+\tstate->process.failed = false;\n+}\n+\n+void set_external_notes_command_name(struct external_notes_state *state,\n+\t\t\t\t     const char *name)\n+{\n+\tstruct external_notes_config *config;\n+\n+\tif (!state)\n+\t\treturn;\n+\n+\tconfig = &state->config;\n+\tFREE_AND_NULL(config->command_name_value);\n+\n+\tif (name && *name)\n+\t\tconfig->command_name_value = xstrdup(name);\n+}\n+\n+const char *external_notes_command_name(const struct external_notes_state *state)\n+{\n+\tif (state && state->config.command_name_value)\n+\t\treturn state->config.command_name_value;\n+\n+\treturn \"external\";\n+}\n+\n+void set_external_notes_command_timeout_ms(struct external_notes_state *state,\n+\t\t\t\t\t   int timeout_ms)\n+{\n+\tif (!state)\n+\t\treturn;\n+\n+\tif (timeout_ms < 0)\n+\t\tBUG(\"negative notes.externalCommandTimeoutMs\");\n+\n+\tstate->config.read_timeout_ns = convert_ms_to_ns(timeout_ms);\n+}\n+\n+int external_notes_command_timeout_ms(const struct external_notes_state *state)\n+{\n+\tif (!state)\n+\t\treturn -1;\n+\n+\treturn (int)convert_ns_to_ms(state->config.read_timeout_ns);\n+}\n+\n+void set_external_notes_for_grep(struct external_notes_state *state,\n+\t\t\t\t int enabled)\n+{\n+\tif (!state)\n+\t\treturn;\n+\n+\tstate->config.for_grep = (bool)enabled;\n+}\n+\n+bool external_notes_for_grep_enabled(const struct external_notes_state *state)\n+{\n+\treturn state && state->config.for_grep;\n+}\n+\n+/* Process management helpers. */\n+\n+static void mute_routine(const char *msg UNUSED, va_list params UNUSED)\n+{\n+\t/* do nothing */\n+}\n+\n+static void close_external_notes_pipes(struct external_notes_process *state)\n+{\n+\tstruct child_process *process;\n+\n+\tif (!state)\n+\t\treturn;\n+\n+\tprocess = &state->process;\n+\n+\tsigchain_push(SIGPIPE, SIG_IGN);\n+\n+\tif (state->in) {\n+\t\tfclose(state->in);\n+\t\tstate->in = NULL;\n+\t} else {\n+\t\tclose(process->in);\n+\t}\n+\n+\tif (state->out_fd >= 0) {\n+\t\tclose(state->out_fd);\n+\t\tstate->out_fd = -1;\n+\t} else {\n+\t\tclose(process->out);\n+\t}\n+\n+\tsigchain_pop(SIGPIPE);\n+}\n+\n+/* We set this as callback later, so can't have void argument. */\n+static void cleanup_external_notes_process(struct child_process *process)\n+{\n+\treport_fn old_error = NULL;\n+\tstruct external_notes_process *state;\n+\n+\tif (!process)\n+\t\treturn;\n+\n+\tstate = container_of(process, struct external_notes_process, process);\n+\n+\tkill(process->pid, SIGTERM);\n+\told_error = get_error_routine();\n+\tset_error_routine(mute_routine);\n+\n+\tclose_external_notes_pipes(state);\n+\tfinish_command(process);\n+\n+\tif (old_error)\n+\t\tset_error_routine(old_error);\n+\n+\tstate->started = false;\n+}\n+\n+static void stop_external_notes_process(struct external_notes_process *state)\n+{\n+\tif (!state)\n+\t\treturn;\n+\n+\tif (!state->started)\n+\t\treturn;\n+\n+\tstate->process.clean_on_exit = 0;\n+\tcleanup_external_notes_process(&state->process);\n+\tchild_process_init(&state->process);\n+\tstate->out_fd = -1;\n+}\n+\n+static int fail_external_notes_command(struct external_notes_state *state)\n+{\n+\tconst struct external_notes_config *config;\n+\tstruct external_notes_process *process;\n+\n+\tif (!state)\n+\t\treturn -1;\n+\n+\tconfig = &state->config;\n+\tprocess = &state->process;\n+\tif (!process->failed)\n+\t\twarning(_(\"notes.externalCommand failed: %s\"),\n+\t\t\tconfig->command);\n+\n+\tprocess->failed = true;\n+\tstop_external_notes_process(process);\n+\treturn -1;\n+}\n+\n+static int start_external_notes_command(struct external_notes_state *state)\n+{\n+\tconst struct external_notes_config *config;\n+\tstruct external_notes_process *process;\n+\tstruct child_process *cmd;\n+\n+\tif (!state)\n+\t\treturn -1;\n+\n+\tconfig = &state->config;\n+\tprocess = &state->process;\n+\tcmd = &process->process;\n+\n+\tif (process->started)\n+\t\treturn 0;\n+\n+\tif (!config->command || process->failed)\n+\t\treturn -1;\n+\n+\tchild_process_init(cmd);\n+\tstrvec_push(&cmd->args, config->command);\n+\tcmd->use_shell = 1;\n+\tcmd->in = -1;\n+\tcmd->out = -1;\n+\tcmd->clean_on_exit = 1;\n+\tcmd->clean_on_exit_handler = cleanup_external_notes_process;\n+\tcmd->trace2_child_class = \"notes-external\";\n+\n+\tif (start_command(cmd))\n+\t\treturn fail_external_notes_command(state);\n+\n+\tprocess->in = xfdopen(cmd->in, \"wb\");\n+\tprocess->out_fd = cmd->out;\n+\tprocess->started = true;\n+\n+\treturn 0;\n+}\n+\n+void external_notes_free(struct external_notes_state *state)\n+{\n+\tif (!state)\n+\t\treturn;\n+\n+\tstop_external_notes_process(&state->process);\n+\trelease_external_notes_config(&state->config);\n+\tfree(state);\n+}\n+\n+/* Command parser. Essentially the main() function of this file. */\n+int format_external_note(struct external_notes_state *state,\n+\t\t\t const struct object_id *object_oid,\n+\t\t\t struct strbuf *note_buf)\n+{\n+\tstruct strbuf status = STRBUF_INIT;\n+\tchar commit_id_hex_str[GIT_MAX_HEXSZ + 1];\n+\tconst char *arg;\n+\tchar *end;\n+\tchar ch;\n+\tunsigned long len;\n+\tuint64_t deadline_ns;\n+\tbool input_fail;\n+\tint ret = 0;\n+\tconst struct external_notes_config *config;\n+\tstruct external_notes_process *process;\n+\n+\tif (!state)\n+\t\treturn -1;\n+\n+\t/* Exit early if starting the command fails. */\n+\tif (start_external_notes_command(state) != 0)\n+\t\treturn -1;\n+\n+\tconfig = &state->config;\n+\tprocess = &state->process;\n+\n+\t/* Fetch the commit ID hex. */\n+\toid_to_hex_r(commit_id_hex_str, object_oid);\n+\n+\t/* Pass the input to the external command. */\n+\tsigchain_push(SIGPIPE, SIG_IGN);\n+\tinput_fail = fprintf(process->in, \"%s\\n\", commit_id_hex_str) < 0\n+\t\t     || fflush(process->in) != 0;\n+\tsigchain_pop(SIGPIPE);\n+\n+\tif (input_fail)\n+\t\tgoto out_fail;\n+\n+\tif (config->read_timeout_ns == 0)\n+\t\tdeadline_ns = 0;\n+\telse\n+\t\tdeadline_ns = getnanotime() + config->read_timeout_ns;\n+\n+\t/**\n+\t * The output for each commit is either of the two:\n+\t * \t\"{commit id} missing\\n\"\n+\t * \t\"{commit id} ok {num_bytes}\\n{str_of_num_bytes}\\n\"\n+\t *\n+\t * We can have \"\\r\\n\" instead of \"\\n\" due to Windows.\n+\t */\n+\n+\t/* Read the first line with its delimiter. */\n+\tif (strbuf_getwholeline_fd_deadline(&status, process->out_fd, '\\n',\n+\t\t\t\t\t    deadline_ns) == EOF)\n+\t\tgoto out_fail;\n+\n+\t/* Reject EOF-terminated partial lines. */\n+\tif (!status.len || status.buf[status.len - 1] != '\\n')\n+\t\tgoto out_fail;\n+\n+\t/**\n+\t * Strip LF and then optional CR so both LF and CRLF protocol lines\n+\t * are accepted.\n+\t */\n+\tstrbuf_setlen(&status, status.len - 1);\n+\tstrbuf_strip_suffix(&status, \"\\r\");\n+\n+\t/* Check if line starts with the commit ID. */\n+\tif (!skip_prefix(status.buf, commit_id_hex_str, &arg))\n+\t\tgoto out_fail;\n+\n+\tif (*arg++ != ' ')  /* After commit ID there should be a space. */\n+\t\tgoto out_fail;\n+\n+\tif (strcmp(arg, \"missing\") == 0)  /* No note available. */\n+\t\tgoto out_success;  /* Ending newline is already ensured. */\n+\n+\tif (!skip_prefix(arg, \"ok \", &arg))  /* Neither missing nor ok. */\n+\t\tgoto out_fail;\n+\n+\t/* We are in \"ok\" case. */\n+\n+\t/* The next thing is length of the note. It must be unsigned digits. */\n+\tif (!isdigit(*arg))\n+\t\tgoto out_fail;\n+\n+\t/* Get the length of note. */\n+\terrno = 0;\n+\tlen = strtoul(arg, &end, 10);\n+\tif (errno != 0 || *end != '\\0' || end == arg)\n+\t\tgoto out_fail;\n+\n+\t/* Ending newline is already ensured. */\n+\n+\t/* Read the trailing note in bounded-chunks. */\n+\twhile (note_buf->len < len) {\n+\t\tssize_t got;\n+\t\tsize_t remaining = len - note_buf->len;\n+\t\tsize_t want = remaining < EXTERNAL_NOTES_READ_CHUNK_SIZE ?\n+\t\t\t      remaining : EXTERNAL_NOTES_READ_CHUNK_SIZE;\n+\n+\t\tstrbuf_grow(note_buf, want);\n+\n+\t\tgot = read_in_full_deadline(process->out_fd,\n+\t\t\t\t\t    note_buf->buf + note_buf->len,\n+\t\t\t\t\t    want, deadline_ns);\n+\t\tif (got < 0 || (size_t)got != want)\n+\t\t\tgoto out_fail;\n+\n+\t\tstrbuf_setlen(note_buf, note_buf->len + (size_t)got);\n+\t}\n+\n+\t/* Ensure the ending newline (LF/CRLF) after the note. */\n+\tif (xread_deadline(process->out_fd, &ch, 1, deadline_ns) != 1)\n+\t\tgoto out_fail;\n+\n+\tif (ch != '\\n') {  /* Not a LF. */\n+\t\tif (ch != '\\r')  /* Not a CRLF. */\n+\t\t\tgoto out_fail;\n+\n+\t\t/* We have '\\r', let's read the next char. */\n+\t\tif (xread_deadline(process->out_fd, &ch, 1,\n+\t\t\t\t   deadline_ns) != 1)\n+\t\t\tgoto out_fail;\n+\n+\t\tif (ch != '\\n')  /* Not a CRLF. */\n+\t\t\tgoto out_fail;\n+\t}\n+\n+\tgoto out_success;\n+\n+out_fail:\n+\tret = fail_external_notes_command(state);\n+out_success:\n+\tstrbuf_release(&status);\n+\treturn ret;\n+}\ndiff --git a/notes-external.h b/notes-external.h\nnew file mode 100644\nindex 000000000000..1b5c2d3919a2\n--- /dev/null\n+++ b/notes-external.h\n@@ -0,0 +1,53 @@\n+#ifndef NOTES_EXTERNAL_H\n+#define NOTES_EXTERNAL_H\n+\n+#include \"run-command.h\"\n+\n+struct object_id;\n+struct strbuf;\n+\n+struct external_notes_config {\n+\tchar *command;\n+\tchar *command_name_value;\n+\tuint64_t read_timeout_ns;\n+\tbool for_grep;\n+};\n+\n+struct external_notes_process {\n+\tstruct child_process process;\n+\tFILE *in;\n+\tint out_fd;\n+\tbool started;\n+\tbool failed;\n+};\n+\n+struct external_notes_state {\n+\tstruct external_notes_config config;\n+\tstruct external_notes_process process;\n+};\n+\n+struct external_notes_state *external_notes_new(void);\n+void external_notes_free(struct external_notes_state *state);\n+void external_notes_reset(struct external_notes_state *state);\n+\n+void set_external_notes_command(struct external_notes_state *state,\n+\t\t\t\tconst char *command);\n+bool external_notes_command_configured(const struct external_notes_state *state);\n+\n+void set_external_notes_command_name(struct external_notes_state *state,\n+\t\t\t\t     const char *name);\n+const char *external_notes_command_name(const struct external_notes_state *state);\n+\n+void set_external_notes_command_timeout_ms(struct external_notes_state *state,\n+\t\t\t\t\t   int timeout_ms);\n+int external_notes_command_timeout_ms(const struct external_notes_state *state);\n+\n+void set_external_notes_for_grep(struct external_notes_state *state,\n+\t\t\t\t int enabled);\n+bool external_notes_for_grep_enabled(const struct external_notes_state *state);\n+\n+int format_external_note(struct external_notes_state *state,\n+\t\t\t const struct object_id *object_oid,\n+\t\t\t struct strbuf *out);\n+\n+#endif  /* NOTES_EXTERNAL_H */\ndiff --git a/notes.c b/notes.c\nindex 201f1df3dc29..624d4aba223d 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -3,9 +3,12 @@\n \n #include \"git-compat-util.h\"\n #include \"config.h\"\n+#include \"commit.h\"\n #include \"environment.h\"\n+#include \"gettext.h\"\n #include \"hex.h\"\n #include \"notes.h\"\n+#include \"notes-external.h\"\n #include \"object-file.h\"\n #include \"object-name.h\"\n #include \"odb.h\"\n@@ -983,18 +986,59 @@ void string_list_add_refs_from_colon_sep(struct string_list *list,\n \tfree(globs_copy);\n }\n \n+struct notes_display_config_data {\n+\tint load_refs;\n+\tint load_command;\n+\tstruct external_notes_state *external_notes_state;\n+};\n+\n static int notes_display_config(const char *k, const char *v,\n-\t\t\t\tconst struct config_context *ctx UNUSED,\n+\t\t\t\tconst struct config_context *ctx,\n \t\t\t\tvoid *cb)\n {\n-\tint *load_refs = cb;\n+\tstruct notes_display_config_data *data = cb;\n \n-\tif (*load_refs && !strcmp(k, \"notes.displayref\")) {\n+\tif (data->load_refs && !strcmp(k, \"notes.displayref\")) {\n \t\tif (!v)\n \t\t\treturn config_error_nonbool(k);\n \t\tstring_list_add_refs_by_glob(&display_notes_refs, v);\n \t}\n \n+\tif (data->load_command && !strcmp(k, \"notes.externalcommand\")) {\n+\t\tif (!v)\n+\t\t\treturn config_error_nonbool(k);\n+\n+\t\tset_external_notes_command(data->external_notes_state, v);\n+\t}\n+\n+\tif (data->load_command && !strcmp(k, \"notes.externalcommandname\")) {\n+\t\tif (!v)\n+\t\t\treturn config_error_nonbool(k);\n+\n+\t\tif (strchr(v, '\\n') || strchr(v, '\\r'))\n+\t\t\treturn error(_(\"notes.externalCommandName must not contain a newline\"));\n+\n+\t\tset_external_notes_command_name(data->external_notes_state, v);\n+\t}\n+\n+\tif (data->load_command && !strcmp(k, \"notes.externalcommandtimeoutms\")) {\n+\t\tint timeout_ms;\n+\n+\t\tif (!v)\n+\t\t\treturn config_error_nonbool(k);\n+\n+\t\ttimeout_ms = git_config_int(k, v, ctx->kvi);\n+\t\tif (timeout_ms < 0)\n+\t\t\treturn error(_(\"notes.externalCommandTimeoutMs must be non-negative\"));\n+\n+\t\tset_external_notes_command_timeout_ms(data->external_notes_state,\n+\t\t\t\t\t\t      timeout_ms);\n+\t}\n+\n+\tif (data->load_command && !strcmp(k, \"notes.externalcommandforgrep\"))\n+\t\tset_external_notes_for_grep(data->external_notes_state,\n+\t\t\t\t\t    git_config_bool(k, v));\n+\n \treturn 0;\n }\n \n@@ -1075,17 +1119,21 @@ void init_display_notes(struct display_notes_opt *opt)\n {\n \tmemset(opt, 0, sizeof(*opt));\n \topt->use_default_notes = -1;\n+\topt->use_external_notes = -1;\n \tstring_list_init_dup(&opt->extra_notes_refs);\n }\n \n void release_display_notes(struct display_notes_opt *opt)\n {\n \tstring_list_clear(&opt->extra_notes_refs, 0);\n+\texternal_notes_free(opt->external_notes_state);\n+\topt->external_notes_state = NULL;\n }\n \n void enable_default_display_notes(struct display_notes_opt *opt, int *show_notes)\n {\n \topt->use_default_notes = 1;\n+\topt->default_notes_suppressed_by_external = 0;\n \t*show_notes = 1;\n }\n \n@@ -1102,31 +1150,96 @@ void enable_ref_display_notes(struct display_notes_opt *opt, int *show_notes,\n void disable_display_notes(struct display_notes_opt *opt, int *show_notes)\n {\n \topt->use_default_notes = -1;\n+\topt->use_external_notes = -1;\n+\topt->default_notes_suppressed_by_external = 0;\n \tstring_list_clear(&opt->extra_notes_refs, 0);\n \t*show_notes = 0;\n }\n \n+/*\n+ * Resolve the default-notes tri-state in one place. Callers must not test\n+ * use_default_notes directly unless they specifically need the unresolved\n+ * command-line state.\n+ */\n+static bool display_notes_use_default(const struct display_notes_opt *opt)\n+{\n+\t/* Options aren't specified, default to true. */\n+\tif (!opt)\n+\t\treturn true;\n+\n+\t/* Explicitly enabled. */\n+\tif (opt->use_default_notes > 0)\n+\t\treturn true;\n+\n+\t/* Undefined and no explicit notes-ref specified, default to true. */\n+\tif (opt->use_default_notes == -1 && !opt->extra_notes_refs.nr)\n+\t\treturn true;\n+\n+\treturn false;\n+}\n+\n+/*\n+ * Resolve the external-notes tri-state. The unset value follows the resolved\n+ * default-notes decision, which means \"git log\" runs the helper by default\n+ * but \"git log --notes=<ref>\" does not.\n+ */\n+static bool display_notes_use_external(const struct display_notes_opt *opt)\n+{\n+\t/* Options aren't specified, default to false. */\n+\tif (!opt)\n+\t\treturn false;\n+\n+\t/* Explicitly enabled. */\n+\tif (opt->use_external_notes > 0)\n+\t\treturn true;\n+\n+\t/* Undefined and to use default notes set, default to true. */\n+\tif (opt->use_external_notes < 0 && display_notes_use_default(opt))\n+\t\treturn true;\n+\n+\treturn false;\n+}\n+\n void load_display_notes(struct display_notes_opt *opt)\n {\n \tchar *display_ref_env;\n-\tint load_config_refs = 0;\n+\tstruct notes_display_config_data config = { 0, 0 };\n+\tstruct notes_display_config_data protected_config = { 0, 0 };\n+\tbool use_default_notes = display_notes_use_default(opt);\n+\tbool use_external_notes = display_notes_use_external(opt);\n+\n \tdisplay_notes_refs.strdup_strings = 1;\n \n+\tif (use_external_notes && opt->external_notes_state) {\n+\t\texternal_notes_reset(opt->external_notes_state);\n+\t} else if (opt) {\n+\t\texternal_notes_free(opt->external_notes_state);\n+\t\topt->external_notes_state = NULL;\n+\t}\n+\n \tassert(!display_notes_trees);\n \n-\tif (!opt || opt->use_default_notes > 0 ||\n-\t    (opt->use_default_notes == -1 && !opt->extra_notes_refs.nr)) {\n+\tif (use_default_notes) {\n \t\tstring_list_append_nodup(&display_notes_refs, default_notes_ref(the_repository));\n \t\tdisplay_ref_env = getenv(GIT_NOTES_DISPLAY_REF_ENVIRONMENT);\n \t\tif (display_ref_env) {\n \t\t\tstring_list_add_refs_from_colon_sep(&display_notes_refs,\n \t\t\t\t\t\t\t    display_ref_env);\n-\t\t\tload_config_refs = 0;\n+\t\t\tconfig.load_refs = 0;\n \t\t} else\n-\t\t\tload_config_refs = 1;\n+\t\t\tconfig.load_refs = 1;\n \t}\n \n-\trepo_config(the_repository, notes_display_config, &load_config_refs);\n+\tif (use_external_notes) {\n+\t\tif (!opt->external_notes_state)\n+\t\t\topt->external_notes_state = external_notes_new();\n+\n+\t\tprotected_config.load_command = 1;\n+\t\tprotected_config.external_notes_state = opt->external_notes_state;\n+\t}\n+\n+\trepo_config(the_repository, notes_display_config, &config);\n+\tgit_protected_config(notes_display_config, &protected_config);\n \n \tif (opt) {\n \t\tstruct string_list_item *item;\n@@ -1266,47 +1379,31 @@ void free_notes(struct notes_tree *t)\n }\n \n /*\n- * Fill the given strbuf with the notes associated with the given object.\n+ * Append one already-loaded note message to the given strbuf.\n  *\n- * If the given notes_tree structure is not initialized, it will be auto-\n- * initialized to the default value (see documentation for init_notes() above).\n- * If the given notes_tree is NULL, the internal/default notes_tree will be\n- * used instead.\n+ * Notes read from refs and notes obtained from notes.externalCommand both use\n+ * this helper so they share the same encoding, header, and indentation rules.\n  *\n  * (raw == true) gives the %N userformat; otherwise, the note message is given\n  * for human consumption.\n  */\n-static void format_note(struct notes_tree *t, const struct object_id *object_oid,\n-\t\t\tstruct strbuf *sb, const char *output_encoding, bool raw)\n+static void format_note_data(const char *ref, const char *msg, size_t msglen,\n+\t\t\t     struct strbuf *sb, const char *output_encoding,\n+\t\t\t     bool raw, bool literal_ref)\n {\n \tstatic const char utf8[] = \"utf-8\";\n-\tconst struct object_id *oid;\n-\tchar *msg, *msg_p;\n-\tunsigned long linelen, msglen;\n-\tenum object_type type;\n-\n-\tif (!t)\n-\t\tt = &default_notes_tree;\n-\tif (!t->initialized)\n-\t\tinit_notes(t, NULL, NULL, 0);\n-\n-\toid = get_note(t, object_oid);\n-\tif (!oid)\n-\t\treturn;\n-\n-\tif (!(msg = odb_read_object(the_repository->objects, oid, &type, &msglen)) ||\n-\t    type != OBJ_BLOB) {\n-\t\tfree(msg);\n-\t\treturn;\n-\t}\n+\tchar *reencoded = NULL;\n+\tconst char *msg_p, *msg_end;\n \n+\t/* Convert the note text from UTF-8 to the requested output encoding. */\n \tif (output_encoding && *output_encoding &&\n \t    !is_encoding_utf8(output_encoding)) {\n-\t\tchar *reencoded = reencode_string(msg, output_encoding, utf8);\n+\t\tsize_t reencoded_len;\n+\t\treencoded = reencode_string_len(msg, msglen, output_encoding,\n+\t\t\t\t\t\t utf8, &reencoded_len);\n \t\tif (reencoded) {\n-\t\t\tfree(msg);\n \t\t\tmsg = reencoded;\n-\t\t\tmsglen = strlen(msg);\n+\t\t\tmsglen = reencoded_len;\n \t\t}\n \t}\n \n@@ -1314,37 +1411,106 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid\n \tif (msglen && msg[msglen - 1] == '\\n')\n \t\tmsglen--;\n \n+\t/* Raw mode is the %N userformat, so it omits the \"Notes\" header. */\n \tif (!raw) {\n-\t\tconst char *ref = t->ref;\n-\t\tif (!ref || !strcmp(ref, GIT_NOTES_DEFAULT_REF)) {\n+\t\tif (!ref)\n \t\t\tstrbuf_addstr(sb, \"\\nNotes:\\n\");\n-\t\t} else {\n-\t\t\tskip_prefix(ref, \"refs/\", &ref);\n-\t\t\tskip_prefix(ref, \"notes/\", &ref);\n+\t\telse if (!literal_ref && !strcmp(ref, GIT_NOTES_DEFAULT_REF))\n+\t\t\tstrbuf_addstr(sb, \"\\nNotes:\\n\");\n+\t\telse {\n+\t\t\tif (!literal_ref) {\n+\t\t\t\tskip_prefix(ref, \"refs/\", &ref);\n+\t\t\t\tskip_prefix(ref, \"notes/\", &ref);\n+\t\t\t}\n \t\t\tstrbuf_addf(sb, \"\\nNotes (%s):\\n\", ref);\n \t\t}\n \t}\n \n-\tfor (msg_p = msg; msg_p < msg + msglen; msg_p += linelen + 1) {\n-\t\tlinelen = strchrnul(msg_p, '\\n') - msg_p;\n+\tmsg_end = msg + msglen;\n+\tfor (msg_p = msg; msg_p < msg_end; ) {\n+\t\tconst char *eol = memchr(msg_p, '\\n', msg_end - msg_p);\n+\t\tsize_t linelen = eol ? eol - msg_p : msg_end - msg_p;\n \n+\t\t/* Human output indents note body lines under the header. */\n \t\tif (!raw)\n \t\t\tstrbuf_addstr(sb, \"    \");\n+\n \t\tstrbuf_add(sb, msg_p, linelen);\n \t\tstrbuf_addch(sb, '\\n');\n+\n+\t\tmsg_p += linelen;\n+\t\tif (msg_p < msg_end)\n+\t\t\tmsg_p++;\n+\t}\n+\n+\tfree(reencoded);\n+}\n+\n+/*\n+ * Fill the given strbuf with the notes associated with the given object.\n+ *\n+ * If the given notes_tree structure is not initialized, it will be auto-\n+ * initialized to the default value (see documentation for init_notes() above).\n+ * If the given notes_tree is NULL, the internal/default notes_tree will be\n+ * used instead.\n+ */\n+static void format_note_from_tree(struct notes_tree *t,\n+\t\t\t\t  const struct object_id *object_oid,\n+\t\t\t\t  struct strbuf *sb,\n+\t\t\t\t  const char *output_encoding, bool raw)\n+{\n+\tconst struct object_id *oid;\n+\tchar *msg;\n+\tunsigned long msglen;\n+\tenum object_type type;\n+\n+\tif (!t)\n+\t\tt = &default_notes_tree;\n+\tif (!t->initialized)\n+\t\tinit_notes(t, NULL, NULL, 0);\n+\n+\toid = get_note(t, object_oid);\n+\tif (!oid)\n+\t\treturn;\n+\n+\tif (!(msg = odb_read_object(the_repository->objects, oid, &type, &msglen)) ||\n+\t    type != OBJ_BLOB) {\n+\t\tfree(msg);\n+\t\treturn;\n \t}\n \n+\tformat_note_data(t->ref, msg, msglen, sb, output_encoding, raw, false);\n+\n \tfree(msg);\n }\n \n-void format_display_notes(const struct object_id *object_oid,\n-\t\t\t  struct strbuf *sb, const char *output_encoding, bool raw)\n+void format_display_notes(const struct commit *commit,\n+\t\t\t  struct strbuf *sb, const char *output_encoding,\n+\t\t\t  bool raw,\n+\t\t\t  struct external_notes_state *external_state)\n {\n \tint i;\n+\tconst struct object_id *commit_oid = &commit->object.oid;\n+\n \tassert(display_notes_trees);\n \tfor (i = 0; display_notes_trees[i]; i++)\n-\t\tformat_note(display_notes_trees[i], object_oid, sb,\n-\t\t\t    output_encoding, raw);\n+\t\tformat_note_from_tree(display_notes_trees[i], commit_oid, sb,\n+\t\t\t\t      output_encoding, raw);\n+\n+\tif (external_notes_command_configured(external_state)) {\n+\t\tstruct strbuf out = STRBUF_INIT;\n+\n+\t\tif (format_external_note(external_state, commit_oid, &out) == 0\n+\t\t    && out.len) {\n+\t\t\tconst char *label =\n+\t\t\t\texternal_notes_command_name(external_state);\n+\n+\t\t\tformat_note_data(label, out.buf, out.len, sb,\n+\t\t\t\t\t output_encoding, raw, true);\n+\t\t}\n+\n+\t\tstrbuf_release(&out);\n+\t}\n }\n \n int copy_note(struct notes_tree *t,\ndiff --git a/notes.h b/notes.h\nindex f6410b31e1c9..5ac6a7e01dfb 100644\n--- a/notes.h\n+++ b/notes.h\n@@ -6,6 +6,8 @@\n struct object_id;\n struct repository;\n struct strbuf;\n+struct commit;\n+struct external_notes_state;\n \n /*\n  * Function type for combining two notes annotating the same object.\n@@ -264,11 +266,31 @@ struct display_notes_opt {\n \t */\n \tint use_default_notes;\n \n+\t/*\n+\t * Less than `0` is \"unset\", which means external notes are shown iff\n+\t * the default notes are shown. Otherwise, treat it like a boolean.\n+\t */\n+\tint use_external_notes;\n+\n+\t/*\n+\t * Tracks the synthetic \"default notes off\" state introduced by\n+\t * `--external-notes`, so a later deprecated `--show-notes=<ref>`\n+\t * can still preserve its historical additive behavior without\n+\t * overriding an explicit `--no-standard-notes`.\n+\t */\n+\tint default_notes_suppressed_by_external;\n+\n \t/*\n \t * A list of globs (in the same style as notes.displayRef) where\n \t * notes should be loaded from.\n \t */\n \tstruct string_list extra_notes_refs;\n+\n+\t/*\n+\t * State for notes.externalCommand. This is initialized lazily by\n+\t * load_display_notes() when external notes may be used.\n+\t */\n+\tstruct external_notes_state *external_notes_state;\n };\n \n /*\n@@ -304,16 +326,21 @@ void disable_display_notes(struct display_notes_opt *opt, int *show_notes);\n void load_display_notes(struct display_notes_opt *opt);\n \n /*\n- * Append notes for the given 'object_sha1' from all trees set up by\n+ * Append notes for the given commit from all trees set up by\n  * load_display_notes() to 'sb'.\n  *\n  * If 'raw' is false the note will be indented by 4 places and\n  * a 'Notes (refname):' header added.\n  *\n+ * If 'external_state' is not NULL, notes.externalCommand will be used to\n+ * append the note from an external source.\n+ *\n  * You *must* call load_display_notes() before using this function.\n  */\n-void format_display_notes(const struct object_id *object_oid,\n-\t\t\t  struct strbuf *sb, const char *output_encoding, bool raw);\n+void format_display_notes(const struct commit *commit,\n+\t\t\t  struct strbuf *sb, const char *output_encoding,\n+\t\t\t  bool raw,\n+\t\t\t  struct external_notes_state *external_state);\n \n /*\n  * Load the notes tree from each ref listed in 'refs'.  The output is\ndiff --git a/revision.c b/revision.c\nindex cd9fcefa0a88..f9581fa82f95 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -6,6 +6,7 @@\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\n+#include \"notes-external.h\"\n #include \"object-name.h\"\n #include \"object-file.h\"\n #include \"odb.h\"\n@@ -2583,18 +2584,40 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg\n \t} else if (skip_prefix(arg, \"--show-notes=\", &optarg) ||\n \t\t   skip_prefix(arg, \"--notes=\", &optarg)) {\n \t\tif (starts_with(arg, \"--show-notes=\") &&\n-\t\t    revs->notes_opt.use_default_notes < 0)\n+\t\t    (revs->notes_opt.use_default_notes < 0 ||\n+\t\t     revs->notes_opt.default_notes_suppressed_by_external)) {\n \t\t\trevs->notes_opt.use_default_notes = 1;\n+\t\t\trevs->notes_opt.default_notes_suppressed_by_external = 0;\n+\t\t}\n \t\tenable_ref_display_notes(&revs->notes_opt, &revs->show_notes, optarg);\n \t\trevs->show_notes_given = 1;\n \t} else if (!strcmp(arg, \"--no-notes\")) {\n \t\tdisable_display_notes(&revs->notes_opt, &revs->show_notes);\n \t\trevs->show_notes_given = 1;\n+\t} else if (!strcmp(arg, \"--external-notes\")) {\n+\t\trevs->notes_opt.use_external_notes = 1;\n+\t\trevs->show_notes = 1;\n+\t\trevs->show_notes_given = 1;\n+\t\t/*\n+\t\t * `--external-notes` names a note source on its own. If the\n+\t\t * default notes ref is still undecided, settle it to \"off\" so\n+\t\t * this option does not also trigger the \"no explicit notes\n+\t\t * refs\" fallback. A later use of `--notes` or the deprecated\n+\t\t * `--show-notes=<ref>` can still turn the default ref on.\n+\t\t */\n+\t\tif (revs->notes_opt.use_default_notes < 0) {\n+\t\t\trevs->notes_opt.use_default_notes = 0;\n+\t\t\trevs->notes_opt.default_notes_suppressed_by_external = 1;\n+\t\t}\n+\t} else if (!strcmp(arg, \"--no-external-notes\")) {\n+\t\trevs->notes_opt.use_external_notes = 0;\n \t} else if (!strcmp(arg, \"--standard-notes\")) {\n \t\trevs->show_notes_given = 1;\n \t\trevs->notes_opt.use_default_notes = 1;\n+\t\trevs->notes_opt.default_notes_suppressed_by_external = 0;\n \t} else if (!strcmp(arg, \"--no-standard-notes\")) {\n \t\trevs->notes_opt.use_default_notes = 0;\n+\t\trevs->notes_opt.default_notes_suppressed_by_external = 0;\n \t} else if (!strcmp(arg, \"--oneline\")) {\n \t\trevs->verbose_header = 1;\n \t\tget_commit_format(\"oneline\", revs);\n@@ -4105,9 +4128,18 @@ static int commit_match(struct commit *commit, struct rev_info *opt)\n \n \t/* Append \"fake\" message parts as needed */\n \tif (opt->show_notes) {\n+\t\tconst struct display_notes_opt *notes_opt = &opt->notes_opt;\n+\t\tstruct external_notes_state *external_notes_state =\n+\t\t\tnotes_opt->external_notes_state;\n+\n \t\tif (!buf.len)\n \t\t\tstrbuf_addstr(&buf, message);\n-\t\tformat_display_notes(&commit->object.oid, &buf, encoding, true);\n+\n+\t\tif (!external_notes_for_grep_enabled(external_notes_state))\n+\t\t\texternal_notes_state = NULL;\n+\n+\t\tformat_display_notes(commit, &buf, encoding, true,\n+\t\t\t\t     external_notes_state);\n \t}\n \n \t/*\ndiff --git a/t/helper/meson.build b/t/helper/meson.build\nindex 3235f10ab8aa..15b6198c19fe 100644\n--- a/t/helper/meson.build\n+++ b/t/helper/meson.build\n@@ -35,6 +35,7 @@ test_tool_sources = [\n   'test-mergesort.c',\n   'test-mktemp.c',\n   'test-name-hash.c',\n+  'test-notes-external-config-reset.c',\n   'test-online-cpus.c',\n   'test-pack-deltas.c',\n   'test-pack-mtimes.c',\ndiff --git a/t/helper/test-external-notes b/t/helper/test-external-notes\nnew file mode 100755\nindex 000000000000..5e9dde3977ab\n--- /dev/null\n+++ b/t/helper/test-external-notes\n@@ -0,0 +1,64 @@\n+#!/bin/sh\n+\n+prefix=${TEST_EXTERNAL_NOTES_PREFIX:-external-notes}\n+response=${TEST_EXTERNAL_NOTES_RESPONSE:-ok}\n+line_ending=${TEST_EXTERNAL_NOTES_LINE_ENDING:-lf}\n+exit_after_response=${TEST_EXTERNAL_NOTES_EXIT_AFTER_RESPONSE:-}\n+exit_delay=${TEST_EXTERNAL_NOTES_EXIT_DELAY:-}\n+delay=${TEST_EXTERNAL_NOTES_DELAY:-}\n+char_delay=${TEST_EXTERNAL_NOTES_CHAR_DELAY:-}\n+ignore_term=${TEST_EXTERNAL_NOTES_IGNORE_TERM:-}\n+\n+newline='\\n'\n+case \"$line_ending\" in\n+crlf)\n+\tnewline='\\r\\n'\n+\t;;\n+none)\n+\tnewline=\n+\t;;\n+esac\n+\n+echo start >>\"$prefix-starts\"\n+\n+test \"$ignore_term\" = true && trap '' TERM\n+\n+emit_output() {\n+\tif test -n \"$char_delay\"\n+\tthen\n+\t\tLC_ALL=C\n+\t\tpayload=$(printf \"$@\"; printf .)\n+\t\tpayload=${payload%.}\n+\n+\t\twhile test -n \"$payload\"\n+\t\tdo\n+\t\t\tchar=${payload%\"${payload#?}\"}\n+\t\t\tprintf '%s' \"$char\" || return 1\n+\t\t\tpayload=${payload#?}\n+\t\t\tsleep \"$char_delay\" || return 1\n+\t\tdone\n+\telse\n+\t\tprintf \"$@\"\n+\tfi\n+}\n+\n+while IFS= read -r commit; do\n+\tif test \"${TEST_EXTERNAL_NOTES_BODY+x}\" = x\n+\tthen\n+\t\tnote=$TEST_EXTERNAL_NOTES_BODY\n+\telse\n+\t\tnote=$commit\n+\tfi\n+\tprintf \"%s\\n\" \"$commit\" >>\"$prefix-requests\"\n+\ttest -z \"$delay\" || sleep \"$delay\"\n+\tif test \"$response\" = missing\n+\tthen\n+\t\temit_output \"%s missing%b\" \"$commit\" \"$newline\"\n+\telse\n+\t\temit_output \"%s ok %d%b%s%b\" \\\n+\t\t\t\"$commit\" \"${#note}\" \"$newline\" \"$note\" \"$newline\"\n+\tfi\n+\ttest \"$exit_after_response\" = true && break\n+done\n+\n+test -z \"$exit_delay\" || sleep \"$exit_delay\"\ndiff --git a/t/helper/test-notes-external-config-reset.c b/t/helper/test-notes-external-config-reset.c\nnew file mode 100644\nindex 000000000000..a64d03346fb9\n--- /dev/null\n+++ b/t/helper/test-notes-external-config-reset.c\n@@ -0,0 +1,24 @@\n+#include \"test-tool.h\"\n+#include \"notes-external.h\"\n+\n+int cmd__notes_external_config_reset(int argc, const char **argv UNUSED)\n+{\n+\tstruct external_notes_state *state;\n+\n+\tif (argc != 1)\n+\t\tdie(\"usage: test-tool notes-external-config-reset\");\n+\n+\tstate = external_notes_new();\n+\tset_external_notes_command(state, \"helper\");\n+\tset_external_notes_command_name(state, \"label\");\n+\tset_external_notes_command_timeout_ms(state, 250);\n+\tset_external_notes_for_grep(state, 1);\n+\texternal_notes_reset(state);\n+\n+\tprintf(\"configured=%d\\n\", external_notes_command_configured(state));\n+\tprintf(\"name=%s\\n\", external_notes_command_name(state));\n+\tprintf(\"timeout_ms=%d\\n\", external_notes_command_timeout_ms(state));\n+\tprintf(\"grep=%d\\n\", external_notes_for_grep_enabled(state));\n+\texternal_notes_free(state);\n+\treturn 0;\n+}\ndiff --git a/t/helper/test-tool.c b/t/helper/test-tool.c\nindex b71a22b43bbc..b4de5a2f5c06 100644\n--- a/t/helper/test-tool.c\n+++ b/t/helper/test-tool.c\n@@ -45,6 +45,7 @@ static struct test_cmd cmds[] = {\n \t{ \"mergesort\", cmd__mergesort },\n \t{ \"mktemp\", cmd__mktemp },\n \t{ \"name-hash\", cmd__name_hash },\n+\t{ \"notes-external-config-reset\", cmd__notes_external_config_reset },\n \t{ \"online-cpus\", cmd__online_cpus },\n \t{ \"pack-deltas\", cmd__pack_deltas },\n \t{ \"pack-mtimes\", cmd__pack_mtimes },\ndiff --git a/t/helper/test-tool.h b/t/helper/test-tool.h\nindex f2885b33d58a..e74d4d934b14 100644\n--- a/t/helper/test-tool.h\n+++ b/t/helper/test-tool.h\n@@ -38,6 +38,7 @@ int cmd__match_trees(int argc, const char **argv);\n int cmd__mergesort(int argc, const char **argv);\n int cmd__mktemp(int argc, const char **argv);\n int cmd__name_hash(int argc, const char **argv);\n+int cmd__notes_external_config_reset(int argc, const char **argv);\n int cmd__online_cpus(int argc, const char **argv);\n int cmd__pack_deltas(int argc, const char **argv);\n int cmd__pack_mtimes(int argc, const char **argv);\ndiff --git a/t/lib-notes.sh b/t/lib-notes.sh\nnew file mode 100644\nindex 000000000000..07422540d58f\n--- /dev/null\n+++ b/t/lib-notes.sh\n@@ -0,0 +1,19 @@\n+# Helpers for scripts testing notes behavior.\n+\n+# notes.externalCommand is run through a shell, so quote the path.\n+external_notes_command=$(\n+\tprintf \"%s\\n\" \"$TEST_DIRECTORY/helper/test-external-notes\" |\n+\tsed \"s/'/'\\\\\\\\''/g; s/^/'/; s/$/'/\"\n+)\n+\n+# The helper above is a shell script. Few Windows CI tests (3 out of 10\n+# in matrix) are spending more than the production default timeout just\n+# starting the shell and exchanging the first response, so tests that\n+# are not about timeout behavior fail. So let us opt into a wider 1s\n+# deadline for Windows instead of 100ms.\n+external_notes_command_timeout_config=\n+if test_have_prereq MINGW\n+then\n+\t_timeout_config=\"notes.externalCommandTimeoutMs=1000\"\n+\texternal_notes_command_timeout_config=\"-c $_timeout_config\"\n+fi\ndiff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh\nindex 1e812df806bb..96adeb9bc4fe 100755\n--- a/t/t3206-range-diff.sh\n+++ b/t/t3206-range-diff.sh\n@@ -6,6 +6,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main\n export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n \n . ./test-lib.sh\n+. \"$TEST_DIRECTORY\"/lib-notes.sh\n \n # Note that because of the range-diff's heuristics, test_commit does more\n # harm than good.  We need some real history.\n@@ -690,6 +691,37 @@ test_expect_success 'range-diff with --notes=custom does not show default notes'\n \tgrep \"## Notes (custom) ##\" actual\n '\n \n+test_expect_success 'range-diff with --external-notes' '\n+\ttopic_oid=$(git rev-parse topic) &&\n+\tunmodified_oid=$(git rev-parse unmodified) &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t$external_notes_command_timeout_config \\\n+\t\trange-diff --no-color --external-notes \\\n+\t\tmain..topic main..unmodified >actual &&\n+\ttest_grep \"## Notes (external) ##\" actual &&\n+\ttest_grep \"^    -    $topic_oid$\" actual &&\n+\ttest_grep \"^    +    $unmodified_oid$\" actual &&\n+\t! grep \"## Notes ##\" actual\n+'\n+\n+test_expect_success 'range-diff with disabled external notes' '\n+\ttest_when_finished \"git notes remove topic unmodified || :\" &&\n+\tgit notes add -m \"topic note\" topic &&\n+\tgit notes add -m \"unmodified note\" unmodified &&\n+\tTEST_EXTERNAL_NOTES_PREFIX=range-diff-external-notes \\\n+\t\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\trange-diff --no-color --external-notes --no-external-notes \\\n+\t\tmain..topic main..unmodified >actual &&\n+\tcat >expect <<-EOF &&\n+\t1:  $(test_oid t1) = 1:  $(test_oid u1) s/5/A/\n+\t2:  $(test_oid t2) = 2:  $(test_oid u2) s/4/A/\n+\t3:  $(test_oid t3) = 3:  $(test_oid u3) s/11/B/\n+\t4:  $(test_oid t4) = 4:  $(test_oid u4) s/12/B/\n+\tEOF\n+\ttest_cmp expect actual &&\n+\ttest_path_is_missing range-diff-external-notes-starts\n+'\n+\n test_expect_success 'format-patch --range-diff does not compare notes by default' '\n \ttest_when_finished \"git notes remove topic unmodified || :\" &&\n \tgit notes add -m \"topic note\" topic &&\n@@ -780,6 +812,42 @@ test_expect_success 'format-patch --range-diff with --notes' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'format-patch --range-diff with --external-notes' '\n+\ttopic_oid=$(git rev-parse topic) &&\n+\tunmodified_oid=$(git rev-parse unmodified) &&\n+\ttest_when_finished \"rm -f 000?-*\" &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t$external_notes_command_timeout_config \\\n+\t\tformat-patch --external-notes --cover-letter --range-diff=$prev \\\n+\t\tmain..unmodified >actual &&\n+\ttest_line_count = 5 actual &&\n+\ttest_grep \"^Range-diff:$\" 0000-* &&\n+\ttest_grep \"## Notes (external) ##\" 0000-* &&\n+\ttest_grep \"^    -    $topic_oid$\" 0000-* &&\n+\ttest_grep \"^    +    $unmodified_oid$\" 0000-* &&\n+\t! grep \"## Notes ##\" 0000-*\n+'\n+\n+test_expect_success 'format-patch --range-diff with disabled external notes' '\n+\ttest_when_finished \"git notes remove topic unmodified || :\" &&\n+\tgit notes add -m \"topic note\" topic &&\n+\tgit notes add -m \"unmodified note\" unmodified &&\n+\ttest_when_finished \"rm -f 000?-*\" &&\n+\tTEST_EXTERNAL_NOTES_PREFIX=range-diff-external-notes \\\n+\t\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\tformat-patch --external-notes --no-external-notes \\\n+\t\t--cover-letter --range-diff=$prev main..unmodified >actual &&\n+\ttest_line_count = 5 actual &&\n+\ttest_grep \"^Range-diff:$\" 0000-* &&\n+\tgrep \"= 1: .* s/5/A\" 0000-* &&\n+\tgrep \"= 2: .* s/4/A\" 0000-* &&\n+\tgrep \"= 3: .* s/11/B\" 0000-* &&\n+\tgrep \"= 4: .* s/12/B\" 0000-* &&\n+\t! grep \"Notes\" 0000-* &&\n+\t! grep \"note\" 0000-* &&\n+\ttest_path_is_missing range-diff-external-notes-starts\n+'\n+\n test_expect_success 'format-patch --range-diff with format.notes config' '\n \ttest_when_finished \"git notes remove topic unmodified || :\" &&\n \tgit notes add -m \"topic note\" topic &&\ndiff --git a/t/t3301-notes.sh b/t/t3301-notes.sh\nindex 27439010dfbc..7fd82767c1f1 100755\n--- a/t/t3301-notes.sh\n+++ b/t/t3301-notes.sh\n@@ -6,6 +6,7 @@\n test_description='Test commit notes'\n \n . ./test-lib.sh\n+. \"$TEST_DIRECTORY\"/lib-notes.sh\n \n write_script fake_editor <<\\EOF\n echo \"$MSG\" >\"$1\"\n@@ -16,6 +17,11 @@ export GIT_EDITOR\n \n indent=\"    \"\n \n+run_with_limited_time () (\n+\t{ set +x; } 2>/dev/null\n+\t\"$PERL_PATH\" -e 'alarm shift; exec @ARGV' -- \"$@\"\n+)\n+\n test_expect_success 'cannot annotate non-existing HEAD' '\n \ttest_must_fail env MSG=3 git notes add\n '\n@@ -909,6 +915,424 @@ test_expect_success 'displayed notes are used for grep matching' '\n \ttest_must_be_empty actual\n '\n \n+test_expect_success 'notes.externalCommand shows external notes from protected config' '\n+\tcommit=$(git rev-parse HEAD) &&\n+\tparent=$(git rev-parse HEAD^) &&\n+\trm -f external-notes-starts external-notes-requests &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t$external_notes_command_timeout_config \\\n+\t\tlog -2 >actual &&\n+\ttest_line_count = 1 external-notes-starts &&\n+\t{\n+\t\tprintf \"%s\\n\" \"$commit\" &&\n+\t\tprintf \"%s\\n\" \"$parent\"\n+\t} >expect-requests &&\n+\ttest_cmp expect-requests external-notes-requests &&\n+\ttest_grep \"Notes (external):\" actual &&\n+\ttest_grep \"^    $commit$\" actual &&\n+\ttest_grep \"^    $parent$\" actual\n+'\n+\n+test_expect_success PERL,EXECKEEPSPID 'notes.externalCommand terminates helper during exit cleanup' '\n+\tcommit=$(git rev-parse HEAD) &&\n+\ttest_env TEST_EXTERNAL_NOTES_EXIT_DELAY=10 \\\n+\t\trun_with_limited_time 2 \\\n+\t\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t$external_notes_command_timeout_config \\\n+\t\tlog --external-notes -1 >actual &&\n+\ttest_grep \"^Notes (external):$\" actual &&\n+\ttest_grep \"^    $commit$\" actual\n+'\n+\n+test_expect_success 'notes.externalCommandName labels external notes' '\n+\tcommit=$(git rev-parse HEAD) &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t$external_notes_command_timeout_config \\\n+\t\t-c notes.externalCommandName=commit-id log -1 >actual &&\n+\ttest_grep \"Notes (commit-id):\" actual &&\n+\ttest_grep \"^    $commit$\" actual\n+'\n+\n+test_expect_success 'notes.externalCommandName is rendered literally' '\n+\tcommit=$(git rev-parse HEAD) &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t$external_notes_command_timeout_config \\\n+\t\t-c notes.externalCommandName=refs/notes/commits \\\n+\t\tlog --external-notes -1 >actual &&\n+\ttest_grep \"^Notes (refs/notes/commits):$\" actual &&\n+\t! grep \"^Notes:$\" actual &&\n+\ttest_grep \"^    $commit$\" actual\n+'\n+\n+test_expect_success 'notes.externalCommandTimeoutMs rejects negative values' '\n+\ttest_must_fail git -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t-c notes.externalCommandTimeoutMs=-1 log -1 2>err &&\n+\ttest_grep \"notes.externalCommandTimeoutMs must be non-negative\" err\n+'\n+\n+test_expect_success 'notes.externalCommandTimeoutMs times out delayed response' '\n+\tgit log -1 >expect &&\n+\ttest_env TEST_EXTERNAL_NOTES_DELAY=1 \\\n+\t\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t-c notes.externalCommandTimeoutMs=1 \\\n+\t\tlog -1 >actual 2>err &&\n+\ttest_cmp expect actual &&\n+\ttest_grep \"notes.externalCommand failed\" err &&\n+\ttest_line_count = 1 err\n+'\n+\n+test_expect_success 'notes.externalCommandTimeoutMs applies to whole response' '\n+\tgit log -1 >expect &&\n+\ttest_env TEST_EXTERNAL_NOTES_BODY=x \\\n+\t\t TEST_EXTERNAL_NOTES_CHAR_DELAY=0.02 \\\n+\t\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t-c notes.externalCommandTimeoutMs=50 \\\n+\t\tlog -1 >actual 2>err &&\n+\ttest_cmp expect actual &&\n+\ttest_grep \"notes.externalCommand failed\" err &&\n+\ttest_line_count = 1 err\n+'\n+\n+test_expect_success PERL,EXECKEEPSPID 'notes.externalCommandTimeoutMs terminates timed-out helper' '\n+\tgit log -1 >expect &&\n+\ttest_env TEST_EXTERNAL_NOTES_DELAY=10 \\\n+\t\trun_with_limited_time 2 \\\n+\t\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t-c notes.externalCommandTimeoutMs=1 \\\n+\t\tlog -1 >actual 2>err &&\n+\ttest_cmp expect actual &&\n+\ttest_grep \"notes.externalCommand failed\" err &&\n+\ttest_line_count = 1 err\n+'\n+\n+test_expect_success 'notes.externalCommandTimeoutMs=0 disables timeout' '\n+\tcommit=$(git rev-parse HEAD) &&\n+\ttest_env TEST_EXTERNAL_NOTES_DELAY=1 \\\n+\t\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t-c notes.externalCommandTimeoutMs=0 \\\n+\t\tlog --external-notes -1 >actual &&\n+\ttest_grep \"^Notes (external):$\" actual &&\n+\ttest_grep \"^    $commit$\" actual\n+'\n+\n+test_expect_success 'notes.externalCommand handles CRLF note bodies' '\n+\tbody=$(printf \"A\\r\\nB\") &&\n+\ttest_env TEST_EXTERNAL_NOTES_BODY=\"$body\" \\\n+\t\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t$external_notes_command_timeout_config \\\n+\t\tlog --external-notes -1 >actual &&\n+\ttest_grep \"^Notes (external):$\" actual &&\n+\ttest_grep \"^    B$\" actual\n+'\n+\n+test_expect_success 'notes.externalCommand accepts CRLF missing response' '\n+\tgit log -1 >expect &&\n+\ttest_env TEST_EXTERNAL_NOTES_RESPONSE=missing \\\n+\t\t TEST_EXTERNAL_NOTES_LINE_ENDING=crlf \\\n+\t\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t$external_notes_command_timeout_config \\\n+\t\tlog -1 >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'notes.externalCommand rejects unterminated missing response' '\n+\tgit log -1 >expect &&\n+\ttest_env TEST_EXTERNAL_NOTES_RESPONSE=missing \\\n+\t\t TEST_EXTERNAL_NOTES_LINE_ENDING=none \\\n+\t\t TEST_EXTERNAL_NOTES_EXIT_AFTER_RESPONSE=true \\\n+\t\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\tlog -1 >actual 2>err &&\n+\ttest_cmp expect actual &&\n+\ttest_grep \"notes.externalCommand failed\" err &&\n+\ttest_line_count = 1 err\n+'\n+\n+test_expect_success PERL,EXECKEEPSPID 'notes.externalCommand rejects unterminated live response without deadlock' '\n+\tgit log -1 >expect &&\n+\ttest_env TEST_EXTERNAL_NOTES_RESPONSE=missing \\\n+\t\t TEST_EXTERNAL_NOTES_LINE_ENDING=none \\\n+\t\trun_with_limited_time 2 \\\n+\t\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\tlog -1 >actual 2>err &&\n+\ttest_cmp expect actual &&\n+\ttest_grep \"notes.externalCommand failed\" err &&\n+\ttest_line_count = 1 err\n+'\n+\n+test_expect_success 'notes.externalCommand accepts CRLF protocol lines' '\n+\tcommit=$(git rev-parse HEAD) &&\n+\ttest_env TEST_EXTERNAL_NOTES_LINE_ENDING=crlf \\\n+\t\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t$external_notes_command_timeout_config \\\n+\t\tlog --external-notes -1 >actual &&\n+\ttest_grep \"^Notes (external):$\" actual &&\n+\ttest_grep \"^    $commit$\" actual\n+'\n+\n+test_expect_success 'notes.externalCommand missing response shows no external notes' '\n+\twrite_script external-notes-missing <<-\\EOF &&\n+\twhile IFS= read -r commit\n+\tdo\n+\t\tprintf \"%s missing\\n\" \"$commit\"\n+\tdone\n+\tEOF\n+\tgit log -1 >expect &&\n+\tgit -c notes.externalCommand=./external-notes-missing log -1 >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'notes.externalCommand empty note shows no external notes' '\n+\twrite_script external-notes-empty <<-\\EOF &&\n+\twhile IFS= read -r commit\n+\tdo\n+\t\tprintf \"%s ok 0\\n\\n\" \"$commit\"\n+\tdone\n+\tEOF\n+\tgit log -1 >expect &&\n+\tgit -c notes.externalCommand=./external-notes-empty log -1 >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'notes.externalCommand rejects invalid note lengths' '\n+\twrite_script external-notes-invalid-length <<-\\EOF &&\n+\twhile IFS= read -r commit\n+\tdo\n+\t\tprintf \"%s ok %s\\n\" \"$commit\" \"$1\"\n+\tdone\n+\tEOF\n+\tgit log -2 >expect &&\n+\tfor bad_length in -1 +1 1x x\n+\tdo\n+\t\tgit -c notes.externalCommand=\"./external-notes-invalid-length $bad_length\" \\\n+\t\t\tlog -2 >actual 2>err &&\n+\t\ttest_cmp expect actual &&\n+\t\ttest_grep \"notes.externalCommand failed\" err &&\n+\t\ttest_line_count = 1 err || return 1\n+\tdone\n+'\n+\n+test_expect_success 'notes.externalCommand is suppressed by --no-notes' '\n+\trm -f external-notes-starts &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" log --no-notes -1 >actual &&\n+\ttest_path_is_missing external-notes-starts &&\n+\t! grep \"Notes (external):\" actual\n+'\n+\n+test_expect_success 'notes.externalCommand is suppressed by --no-external-notes' '\n+\trm -f external-notes-starts &&\n+\tgit log -1 >expect &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\tlog --no-external-notes -1 >actual &&\n+\ttest_cmp expect actual &&\n+\ttest_path_is_missing external-notes-starts\n+'\n+\n+test_expect_success 'notes.externalCommand combines with explicit notes ref' '\n+\tcommit=$(git rev-parse HEAD) &&\n+\trm -f external-notes-starts &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t$external_notes_command_timeout_config \\\n+\t\tlog --notes=other --external-notes -1 >actual &&\n+\ttest_line_count = 1 external-notes-starts &&\n+\ttest_grep \"Notes (other):\" actual &&\n+\ttest_grep \"^    other note$\" actual &&\n+\ttest_grep \"Notes (external):\" actual &&\n+\ttest_grep \"^    $commit$\" actual &&\n+\t! grep \"^    order test$\" actual\n+'\n+\n+test_expect_success '--show-notes=ref remains additive after --external-notes' '\n+\tcommit=$(git rev-parse HEAD) &&\n+\trm -f external-notes-starts &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t$external_notes_command_timeout_config \\\n+\t\tlog --external-notes --show-notes=other -1 >actual &&\n+\ttest_line_count = 1 external-notes-starts &&\n+\ttest_grep \"^Notes:$\" actual &&\n+\ttest_grep \"^    order test$\" actual &&\n+\ttest_grep \"^Notes (other):$\" actual &&\n+\ttest_grep \"^    other note$\" actual &&\n+\ttest_grep \"^Notes (external):$\" actual &&\n+\ttest_grep \"^    $commit$\" actual\n+'\n+\n+test_expect_success 'notes.externalCommand can be enabled without default notes refs' '\n+\tcommit=$(git rev-parse HEAD) &&\n+\trm -f external-notes-starts &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t$external_notes_command_timeout_config \\\n+\t\tlog --external-notes -1 >actual &&\n+\ttest_line_count = 1 external-notes-starts &&\n+\ttest_grep \"Notes (external):\" actual &&\n+\ttest_grep \"^    $commit$\" actual &&\n+\t! grep \"^    order test$\" actual &&\n+\t! grep \"^    other note$\" actual\n+'\n+\n+test_expect_success 'notes.externalCommand combines with default notes refs' '\n+\tcommit=$(git rev-parse HEAD) &&\n+\trm -f external-notes-starts &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t$external_notes_command_timeout_config \\\n+\t\tlog --external-notes --notes -1 >actual &&\n+\ttest_line_count = 1 external-notes-starts &&\n+\ttest_grep \"Notes:\" actual &&\n+\ttest_grep \"^    order test$\" actual &&\n+\ttest_grep \"Notes (external):\" actual &&\n+\ttest_grep \"^    $commit$\" actual &&\n+\t! grep \"^    other note$\" actual\n+'\n+\n+test_expect_success 'notes.externalCommand obeys last --external-notes option' '\n+\tcommit=$(git rev-parse HEAD) &&\n+\trm -f external-notes-starts &&\n+\tgit log --no-notes -1 >expect &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\tlog --external-notes --no-external-notes -1 >actual &&\n+\ttest_cmp expect actual &&\n+\ttest_path_is_missing external-notes-starts &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t$external_notes_command_timeout_config \\\n+\t\tlog --notes=other --no-external-notes --external-notes -1 >actual &&\n+\ttest_line_count = 1 external-notes-starts &&\n+\ttest_grep \"Notes (other):\" actual &&\n+\ttest_grep \"^    other note$\" actual &&\n+\ttest_grep \"Notes (external):\" actual &&\n+\ttest_grep \"^    $commit$\" actual &&\n+\t! grep \"^    order test$\" actual\n+'\n+\n+test_expect_success 'notes.externalCommand honors raw notes formatting' '\n+\tcommit=$(git rev-parse HEAD) &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t$external_notes_command_timeout_config \\\n+\t\tshow -s --format=%N >actual &&\n+\ttest_grep \"^$commit$\" actual &&\n+\t! grep \"Notes (external):\" actual\n+'\n+\n+test_expect_success 'format-patch --external-notes includes external notes only' '\n+\tcommit=$(git rev-parse HEAD) &&\n+\trm -f external-notes-starts &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t$external_notes_command_timeout_config \\\n+\t\tformat-patch --external-notes -1 --stdout >actual &&\n+\ttest_line_count = 1 external-notes-starts &&\n+\ttest_grep \"^Notes (external):\" actual &&\n+\ttest_grep \"^    $commit$\" actual &&\n+\t! grep \"^    order test$\" actual\n+'\n+\n+test_expect_success 'notes.externalCommand is not used for grep matching' '\n+\tcommit=$(git rev-parse HEAD) &&\n+\trm -f external-notes-starts &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\tlog --grep=\"$commit\" >actual &&\n+\ttest_must_be_empty actual &&\n+\ttest_path_is_missing external-notes-starts\n+'\n+\n+test_expect_success 'notes.externalCommandForGrep includes external notes in grep matching' '\n+\tcommit=$(git rev-parse HEAD) &&\n+\trm -f external-notes-starts &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t$external_notes_command_timeout_config \\\n+\t\t-c notes.externalCommandForGrep=true \\\n+\t\tlog --grep=\"$commit\" -1 >actual &&\n+\ttest_line_count = 1 external-notes-starts &&\n+\ttest_grep \"Notes (external):\" actual\n+'\n+\n+test_expect_success 'notes.externalCommandForGrep does not search hidden notes' '\n+\tcommit=$(git rev-parse HEAD) &&\n+\trm -f external-notes-starts &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t-c notes.externalCommandForGrep=true \\\n+\t\tlog --oneline --grep=\"$commit\" -1 >actual &&\n+\ttest_must_be_empty actual &&\n+\ttest_path_is_missing external-notes-starts\n+'\n+\n+test_expect_success 'notes.externalCommandForGrep honors --no-external-notes' '\n+\tcommit=$(git rev-parse HEAD) &&\n+\trm -f external-notes-starts &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t-c notes.externalCommandForGrep=true \\\n+\t\tlog --no-external-notes --grep=\"$commit\" -1 >actual &&\n+\ttest_must_be_empty actual &&\n+\ttest_path_is_missing external-notes-starts\n+'\n+\n+test_expect_success 'notes.externalCommandForGrep combines with explicit notes ref' '\n+\tcommit=$(git rev-parse HEAD) &&\n+\trm -f external-notes-starts &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t$external_notes_command_timeout_config \\\n+\t\t-c notes.externalCommandForGrep=true \\\n+\t\tlog --notes=other --external-notes --grep=\"$commit\" -1 >actual &&\n+\ttest_line_count = 1 external-notes-starts &&\n+\ttest_grep \"Notes (external):\" actual &&\n+\ttest_grep \"Notes (other):\" actual &&\n+\t! grep \"^    order test$\" actual\n+'\n+\n+test_expect_success 'notes.externalCommandForGrep is ignored from local config' '\n+\tcommit=$(git rev-parse HEAD) &&\n+\trm -f external-notes-starts &&\n+\ttest_config notes.externalCommandForGrep true &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\tlog --grep=\"$commit\" >actual &&\n+\ttest_must_be_empty actual &&\n+\ttest_path_is_missing external-notes-starts\n+'\n+\n+test_expect_success 'notes.externalCommand is not used with explicit notes ref' '\n+\trm -f external-notes-starts &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" log --notes=other -1 >actual &&\n+\ttest_path_is_missing external-notes-starts &&\n+\t! grep \"Notes (external):\" actual\n+'\n+\n+test_expect_success 'notes.externalCommand is ignored from local config' '\n+\trm -f external-notes-starts &&\n+\ttest_config notes.externalCommand \"$external_notes_command\" &&\n+\tgit log -1 >actual &&\n+\ttest_path_is_missing external-notes-starts &&\n+\t! grep \"Notes (external):\" actual\n+'\n+\n+test_expect_success 'notes.externalCommandName is ignored from local config' '\n+\ttest_config notes.externalCommandName local &&\n+\tgit -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t$external_notes_command_timeout_config \\\n+\t\tlog -1 >actual &&\n+\ttest_grep \"Notes (external):\" actual &&\n+\t! grep \"Notes (local):\" actual\n+'\n+\n+test_expect_success 'external_notes_reset clears cached helper config' '\n+\ttest-tool notes-external-config-reset >actual &&\n+\tcat >expect <<-\\EOF &&\n+\tconfigured=0\n+\tname=external\n+\ttimeout_ms=100\n+\tgrep=0\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'notes.externalCommand warning is shown once' '\n+\twrite_script external-notes-fail <<-\\EOF &&\n+\twhile IFS= read -r commit\n+\tdo\n+\t\tprintf \"%s-mismatch missing\\n\" \"$commit\"\n+\tdone\n+\tEOF\n+\tgit -c notes.externalCommand=./external-notes-fail log -2 >actual 2>err &&\n+\ttest_grep \"notes.externalCommand failed\" err &&\n+\ttest_line_count = 1 err\n+'\n+\n test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '\n \ttest_config core.notesRef refs/notes/other &&\n \techo \"Note on a tree\" >expect &&\ndiff --git a/t/t6120-describe.sh b/t/t6120-describe.sh\nindex 8ee3d2c37d02..abbdb42dc9f7 100755\n--- a/t/t6120-describe.sh\n+++ b/t/t6120-describe.sh\n@@ -15,6 +15,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main\n export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n \n . ./test-lib.sh\n+. \"$TEST_DIRECTORY\"/lib-notes.sh\n \n check_describe () {\n \tindir= &&\n@@ -867,6 +868,22 @@ test_expect_success 'format-rev with %N (note)' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'format-rev with %N uses external notes' '\n+\tcommit=$(git -C repo-format rev-parse HEAD) &&\n+\trm -f repo-format/format-rev-external-notes-starts \\\n+\t\trepo-format/format-rev-external-notes-requests &&\n+\tprintf \"%s\\n\" \"$commit\" >input &&\n+\tprintf \"%s\\n\\n\" \"$commit\" >expect &&\n+\tTEST_EXTERNAL_NOTES_PREFIX=format-rev-external-notes \\\n+\tgit -C repo-format -c notes.externalCommand=\"$external_notes_command\" \\\n+\t\t$external_notes_command_timeout_config \\\n+\t\tformat-rev --stdin-mode=text --format=\"tformat:%N\" \\\n+\t\t<input >actual &&\n+\ttest_line_count = 1 repo-format/format-rev-external-notes-starts &&\n+\ttest_cmp input repo-format/format-rev-external-notes-requests &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'format-rev --notes<ref> (custom notes ref)' '\n \t# One custom notes ref\n \ttest_when_finished \"git -C repo-format notes remove\" &&\n-- \n2.53.0\n\n"},{"id":"544214","messageId":"963cf0c8667a2f3cc286988a4ca01284c14a90be.camel@oracle.com","threadId":"65679","inReplyTo":"cover.1779532562.git.siddh.raman.pant@oracle.com","subject":"Re: [PATCH v3 0/4] Add support for an external command for fetching notes","fromName":"Siddh Raman Pant","fromEmail":"siddh.raman.pant@oracle.com","sentAt":"2026-05-28T05:59:02Z","receivedAt":"2026-05-28T05:59:26Z","isPatch":true,"body":"Hi,\n\nPinging since it's been almost a week (v2 was sent on Fri)... \nI sent close/during the weekend, so I think this fell through.\n\nSorry if this bothers. Just curious as I haven't heard back like the\nlast time.\n\nThanks,\nSiddh\n\nOn Sat, May 23 2026 at 16:08:08 +0530, Siddh Raman Pant wrote:\n> v2: https://lore.kernel.org/git/cover.1779464886.git.siddh.raman.pant@oracle.com/\n> v1: https://lore.kernel.org/git/cover.1779207350.git.siddh.raman.pant@oracle.com/\n> \n> <...insert text from v1 cover here...>\n> \n> Changes since v2:\n> - Removed stale help text talking about force-killing helper process.\n> \n> Changes since v1:\n> - Removed Documentation commit and sent as a standalone patch.\n> - Removed finish_command_with_timeout addition (and thus sleep_nanosec).\n> - Squashed the external notes command code, doc, and test commits.\n> - Removed horizontal separators from note-external.c.\n> - Removed global variables from translation unit and instead store config in\n>   a dedicated new struct member in struct display_notes_opt.\n> - Reworded the main commit to have better explanation of the motivation.\n> \n> Siddh Raman Pant (4):\n>   notes: convert raw arg in format_display_notes() to bool\n>   wrapper: add support for timeout and deadline in read helpers\n>   t3301: cover generic displayed notes behavior\n>   notes: support an external command to display notes\n> \n>  Documentation/config/notes.adoc             |  59 +++\n>  Documentation/git-format-patch.adoc         |  11 +-\n>  Documentation/git-range-diff.adoc           |   6 +\n>  Documentation/pretty-options.adoc           |   9 +\n>  Makefile                                    |   2 +\n>  builtin/log.c                               |  17 +-\n>  builtin/name-rev.c                          |   9 +-\n>  builtin/range-diff.c                        |   2 +\n>  contrib/completion/git-completion.bash      |   4 +-\n>  log-tree.c                                  |  10 +-\n>  meson.build                                 |   1 +\n>  notes-external.c                            | 414 ++++++++++++++++++\n>  notes-external.h                            |  53 +++\n>  notes.c                                     | 266 +++++++++---\n>  notes.h                                     |  33 +-\n>  revision.c                                  |  36 +-\n>  strbuf.c                                    |  26 +-\n>  strbuf.h                                    |   4 +\n>  t/helper/meson.build                        |   1 +\n>  t/helper/test-external-notes                |  64 +++\n>  t/helper/test-notes-external-config-reset.c |  24 ++\n>  t/helper/test-tool.c                        |   1 +\n>  t/helper/test-tool.h                        |   1 +\n>  t/lib-notes.sh                              |  19 +\n>  t/t3206-range-diff.sh                       |  68 +++\n>  t/t3301-notes.sh                            | 448 ++++++++++++++++++++\n>  t/t6120-describe.sh                         |  17 +\n>  wrapper.c                                   | 139 +++++-\n>  wrapper.h                                   |  23 +\n>  29 files changed, 1691 insertions(+), 76 deletions(-)\n>  create mode 100644 notes-external.c\n>  create mode 100644 notes-external.h\n>  create mode 100755 t/helper/test-external-notes\n>  create mode 100644 t/helper/test-notes-external-config-reset.c\n>  create mode 100644 t/lib-notes.sh\n"},{"id":"545646","messageId":"d266c22f90d7140d14fe5dd84d91601d8fad7d73.camel@oracle.com","threadId":"65679","inReplyTo":"cover.1779532562.git.siddh.raman.pant@oracle.com","subject":"Re: [PATCH v3 0/4] Add support for an external command for fetching notes","fromName":"Siddh Raman Pant","fromEmail":"siddh.raman.pant@oracle.com","sentAt":"2026-06-16T10:59:42Z","receivedAt":"2026-06-16T11:00:08Z","isPatch":true,"body":"Ping...\n\nThread link:\nhttps://lore.kernel.org/git/cover.1779532562.git.siddh.raman.pant@oracle.com/\n\nThanks,\nSiddh\n\nOn Sat, May 23 2026 at 16:08:08 +0530, Siddh Raman Pant wrote:\n> v2: https://lore.kernel.org/git/cover.1779464886.git.siddh.raman.pant@oracle.com/\n> v1: https://lore.kernel.org/git/cover.1779207350.git.siddh.raman.pant@oracle.com/\n> \n> <...insert text from v1 cover here...>\n> \n> Changes since v2:\n> - Removed stale help text talking about force-killing helper process.\n> \n> Changes since v1:\n> - Removed Documentation commit and sent as a standalone patch.\n> - Removed finish_command_with_timeout addition (and thus sleep_nanosec).\n> - Squashed the external notes command code, doc, and test commits.\n> - Removed horizontal separators from note-external.c.\n> - Removed global variables from translation unit and instead store config in\n>   a dedicated new struct member in struct display_notes_opt.\n> - Reworded the main commit to have better explanation of the motivation.\n> \n> Siddh Raman Pant (4):\n>   notes: convert raw arg in format_display_notes() to bool\n>   wrapper: add support for timeout and deadline in read helpers\n>   t3301: cover generic displayed notes behavior\n>   notes: support an external command to display notes\n> \n>  Documentation/config/notes.adoc             |  59 +++\n>  Documentation/git-format-patch.adoc         |  11 +-\n>  Documentation/git-range-diff.adoc           |   6 +\n>  Documentation/pretty-options.adoc           |   9 +\n>  Makefile                                    |   2 +\n>  builtin/log.c                               |  17 +-\n>  builtin/name-rev.c                          |   9 +-\n>  builtin/range-diff.c                        |   2 +\n>  contrib/completion/git-completion.bash      |   4 +-\n>  log-tree.c                                  |  10 +-\n>  meson.build                                 |   1 +\n>  notes-external.c                            | 414 ++++++++++++++++++\n>  notes-external.h                            |  53 +++\n>  notes.c                                     | 266 +++++++++---\n>  notes.h                                     |  33 +-\n>  revision.c                                  |  36 +-\n>  strbuf.c                                    |  26 +-\n>  strbuf.h                                    |   4 +\n>  t/helper/meson.build                        |   1 +\n>  t/helper/test-external-notes                |  64 +++\n>  t/helper/test-notes-external-config-reset.c |  24 ++\n>  t/helper/test-tool.c                        |   1 +\n>  t/helper/test-tool.h                        |   1 +\n>  t/lib-notes.sh                              |  19 +\n>  t/t3206-range-diff.sh                       |  68 +++\n>  t/t3301-notes.sh                            | 448 ++++++++++++++++++++\n>  t/t6120-describe.sh                         |  17 +\n>  wrapper.c                                   | 139 +++++-\n>  wrapper.h                                   |  23 +\n>  29 files changed, 1691 insertions(+), 76 deletions(-)\n>  create mode 100644 notes-external.c\n>  create mode 100644 notes-external.h\n>  create mode 100755 t/helper/test-external-notes\n>  create mode 100644 t/helper/test-notes-external-config-reset.c\n>  create mode 100644 t/lib-notes.sh\n"},{"id":"546103","messageId":"770c0163b9958e703faf6d9e4f2d47df6c93c37f.camel@oracle.com","threadId":"65679","inReplyTo":"d266c22f90d7140d14fe5dd84d91601d8fad7d73.camel@oracle.com","subject":"Re: [PATCH v3 0/4] Add support for an external command for fetching notes","fromName":"Siddh Raman Pant","fromEmail":"siddh.raman.pant@oracle.com","sentAt":"2026-06-22T04:45:26Z","receivedAt":"2026-06-22T04:45:50Z","isPatch":true,"body":"Pinging again...\n\nThanks,\nSiddh\n\nOn Tue, Jun 16 2026 at 16:29:36 +0530, Siddh Raman Pant wrote:\n> Ping...\n> \n> Thread link:\n> https://lore.kernel.org/git/cover.1779532562.git.siddh.raman.pant@oracle.com/\n> \n> Thanks,\n> Siddh\n"},{"id":"546264","messageId":"3a2ba6c0-4ced-4d2c-820e-401c2dff1dd1@kdbg.org","threadId":"65679","inReplyTo":"7284a8bccb6bfb5734adb09f05ae4b61a63da2df.1779532562.git.siddh.raman.pant@oracle.com","subject":"Re: [PATCH v3 4/4] notes: support an external command to display notes","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2026-06-24T07:49:26Z","receivedAt":"2026-06-24T07:49:37Z","isPatch":true,"body":"Am 23.05.26 um 12:38 schrieb Siddh Raman Pant:\n> git notes is a very very helpful feature to show user-supplied\n> information about a commit alongside its message transparently.\n> \n> For distributed teams working on large git repos (huge number of\n> branches/refs, files, etc.) and using the notes feature to mark\n> information on git commits, the problem is often not that two users\n> update the same note object at the same time. It is that the local\n> notes state used while reading history can be stale.\n> \n> In kernel work, the same logical upstream fix can appear as different\n> commit objects across many downstream branches, such as the stable\n> branches and vendor-specific branches (based on which the released\n> kernel is actually built). Different developers may be working on those\n> branches in parallel, and a review decision recorded for one backport\n> is useful context for the others.\n> \n> Today, seeing that decision in ordinary history output requires first\n> synchronizing the local notes ref, and then interpreting those notes\n> for the branch being inspected. The latter step is workflow-specific\n> and can be cheap, but keeping the local notes state fresh enough can be\n> expensive in a large kernel repository with a large shared notes\n> history (and if we are to extrapolate, a slow git server conn/ops can\n> be a factor too).\n> \n> This TOCTOU problem exacerbates on scale (rapid updates, more devs,\n> larger repos, more git server traffic, etc).\n> \n> One solution to this is to move the freshness policy out of git so that\n> it is someone else's problem. We can have a realtime fetch or faster\n> updation via external helper means. But unfortunately we lose the\n> coherence in the display of information, and so the user would end up\n> reinventing git log in his quest to have same workflow.\n\nYou are presenting one solution here. But a more obvious solution would\nhave been to make Git's notes implementation capable enough to keep up\nwith the volume of notes that are produced by your team.\n\nAnother solution would be to track the information outside of Git notes\nentirely, similar to how pull requests, issues, reviews, and\nconversations are tracked by Git hosters in databases outside of Git.\n\n> Let's add support for notes.externalCommand, a protected-configuration\n> command that git runs as a long-lived helper when displaying notes. git\n> sends commit IDs to the helper and displays any returned text through\n> the existing notes formatting path. This keeps presentation in git\n> while letting the helper decide how fresh note text is obtained.\n\nTo my eyes, this looks like an overengineered solution that helps one\nuser of a niche feature of Git.\n\n-- Hannes\n\n"},{"id":"546281","messageId":"76cc093d2835a7b3ed110e20f1480dbe5fc2ecbb.camel@oracle.com","threadId":"65679","inReplyTo":"3a2ba6c0-4ced-4d2c-820e-401c2dff1dd1@kdbg.org","subject":"Re: [PATCH v3 4/4] notes: support an external command to display notes","fromName":"Siddh Raman Pant","fromEmail":"siddh.raman.pant@oracle.com","sentAt":"2026-06-24T09:53:28Z","receivedAt":"2026-06-24T09:53:51Z","isPatch":true,"body":"On Wed, Jun 24 2026 at 13:19:26 +0530, Johannes Sixt wrote:\n> > One solution to this is to move the freshness policy out of git so that\n> > it is someone else's problem. We can have a realtime fetch or faster\n> > updation via external helper means. But unfortunately we lose the\n> > coherence in the display of information, and so the user would end up\n> > reinventing git log in his quest to have same workflow.\n> \n> You are presenting one solution here. But a more obvious solution would\n> have been to make Git's notes implementation capable enough to keep up\n> with the volume of notes that are produced by your team.\n\nGit storage is inherently based on refs, so that would require massive\nchanges IMO. The actual fundamental problem here is that only the\nlatest state is useful at any given point of time, and not the past\nhistory.\n\n> Another solution would be to track the information outside of Git notes\n> entirely, similar to how pull requests, issues, reviews, and\n> conversations are tracked by Git hosters in databases outside of Git.\n\nThis is precisely what this allows for. The information is tracked\noutside of Git, and the notes path just shows it along with the commit.\n\nA developer works on the code using Git. An external website doesn't\nallow the same level of coherence in display of information as a note.\nThe commit is a fundamental unit of change. IMO it makes sense for Git\nto be able to show a note about it from a provided external medium.\n\n> > Let's add support for notes.externalCommand, a protected-configuration\n> > command that git runs as a long-lived helper when displaying notes. git\n> > sends commit IDs to the helper and displays any returned text through\n> > the existing notes formatting path. This keeps presentation in git\n> > while letting the helper decide how fresh note text is obtained.\n> \n> To my eyes, this looks like an overengineered solution that helps one\n> user of a niche feature of Git.\n\nThis can also allow for other uses too. For example, searching lore I\njust found out that a colleague in Oracle Linux (Vegard) was trying to\nsolve a related problem in 2022:\n\nhttps://lore.kernel.org/git/20220802075401.2393-1-vegard.nossum@oracle.com/\n\nI think it was for achieving something like this more generally:\nhttps://git.kernel.org/pub/scm/linux/kernel/git/vegard/linux.git/commit/?id=339f83612f3a569b194680768b22bf113c26a29d\n\nAn external notes command can be a solution for it.\n\nThanks,\nSiddh\n"},{"id":"547601","messageId":"65e2e9f6f30b74725ca4516424e8d7116383e368.camel@oracle.com","threadId":"65679","inReplyTo":"76cc093d2835a7b3ed110e20f1480dbe5fc2ecbb.camel@oracle.com","subject":"Re: [PATCH v3 4/4] notes: support an external command to display notes","fromName":"Siddh Raman Pant","fromEmail":"siddh.raman.pant@oracle.com","sentAt":"2026-07-09T11:10:35Z","receivedAt":"2026-07-09T11:11:01Z","isPatch":true,"body":"Going by no response, I assume this is NACK'd then?\n\nThanks,\nSiddh\n\nOn Wed, Jun 24 2026 at 15:23:23 +0530, Siddh Raman Pant wrote:\n> On Wed, Jun 24 2026 at 13:19:26 +0530, Johannes Sixt wrote:\n> > > One solution to this is to move the freshness policy out of git so that\n> > > it is someone else's problem. We can have a realtime fetch or faster\n> > > updation via external helper means. But unfortunately we lose the\n> > > coherence in the display of information, and so the user would end up\n> > > reinventing git log in his quest to have same workflow.\n> > \n> > You are presenting one solution here. But a more obvious solution would\n> > have been to make Git's notes implementation capable enough to keep up\n> > with the volume of notes that are produced by your team.\n> \n> Git storage is inherently based on refs, so that would require massive\n> changes IMO. The actual fundamental problem here is that only the\n> latest state is useful at any given point of time, and not the past\n> history.\n> \n> > Another solution would be to track the information outside of Git notes\n> > entirely, similar to how pull requests, issues, reviews, and\n> > conversations are tracked by Git hosters in databases outside of Git.\n> \n> This is precisely what this allows for. The information is tracked\n> outside of Git, and the notes path just shows it along with the commit.\n> \n> A developer works on the code using Git. An external website doesn't\n> allow the same level of coherence in display of information as a note.\n> The commit is a fundamental unit of change. IMO it makes sense for Git\n> to be able to show a note about it from a provided external medium.\n> \n> > > Let's add support for notes.externalCommand, a protected-configuration\n> > > command that git runs as a long-lived helper when displaying notes. git\n> > > sends commit IDs to the helper and displays any returned text through\n> > > the existing notes formatting path. This keeps presentation in git\n> > > while letting the helper decide how fresh note text is obtained.\n> > \n> > To my eyes, this looks like an overengineered solution that helps one\n> > user of a niche feature of Git.\n> \n> This can also allow for other uses too. For example, searching lore I\n> just found out that a colleague in Oracle Linux (Vegard) was trying to\n> solve a related problem in 2022:\n> \n> https://lore.kernel.org/git/20220802075401.2393-1-vegard.nossum@oracle.com/\n> \n> I think it was for achieving something like this more generally:\n> https://git.kernel.org/pub/scm/linux/kernel/git/vegard/linux.git/commit/?id=339f83612f3a569b194680768b22bf113c26a29d\n> \n> An external notes command can be a solution for it.\n> \n> Thanks,\n> Siddh\n"},{"id":"549194","messageId":"60e92e7331e64d13eff2aabd91fe8baf3a761ef7.camel@oracle.com","threadId":"65679","inReplyTo":"65e2e9f6f30b74725ca4516424e8d7116383e368.camel@oracle.com","subject":"Re: [PATCH v3 4/4] notes: support an external command to display notes","fromName":"Siddh Raman Pant","fromEmail":"siddh.raman.pant@oracle.com","sentAt":"2026-07-29T09:58:39Z","receivedAt":"2026-07-29T09:59:00Z","isPatch":true,"body":"On Thu, Jul 09 2026 at 16:40:21 +0530, Siddh Raman Pant wrote:\n> Going by no response, I assume this is NACK'd then?\n\nAssuming a NACK then.\n\nWould have preferred if maintainer was explicit about why.\n\n--\nSiddh\n"}]}