Skip to contentSkip to conversation

Add support for an external command for fetching notes

PATCH Superseded Siddh Raman Pant 6 participants 29 messages May 19 – May 22

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Add support for an external command for fetching notes

Hi,

This series teaches the notes display machinery to obtain note text from a long-lived external helper configured by notes.externalCommand.

The motivation is mentioned in the main commit message (PATCH 7/9).

The helper protocol is intentionally narrow. Git starts the command once, sends one commit object ID per request, and expects either:

	<object-id> missing
	<object-id> ok <n>
	<n bytes of UTF-8 note text>

with the documented trailing newlines. The command is read only from protected configuration, so an untrusted repository cannot make ordinary note display run arbitrary commands. If the helper cannot be started, times out, exits, or sends an invalid response, Git warns once, disables it for the rest of the process, and continues without external notes.

Users can control from command line too with --external-notes and --no-external-notes. The semantics are close to --notes=<ref>:
--external-notes implies naming an explicit notes source by itself, while --external-notes --notes combines it with the default notes refs, and --external-notes --notes=<ref> combines it with specific notes refs. The series also adds notes.externalCommandName, notes.externalCommandTimeoutMs, and the opt-in notes.externalCommandForGrep knob for installations that want external notes to participate in --grep matching.

Because this puts an external process on the log-formatting path, the series also adds the small support pieces needed to keep that boundary bounded:
timeout/deadline variants of the read helpers, a timeout-aware command finisher, and cleanup that escalates if the helper does not exit promptly.

Testing: https://github.com/siddhpant/git/actions/runs/26107938855

Thanks,
Siddh

Siddh Raman Pant (9):
Documentation/git-range-diff: add missing notes options in synopsis
notes: convert raw arg in format_display_notes() to bool
wrapper: add sleep_nanosec
run-command: add support for timeout in command finisher
wrapper: add support for timeout and deadline in read helpers
t3301: cover generic displayed notes behavior
notes: support an external command to display notes
Documentation: document external notes command options
t: add tests for external notes command

 Documentation/config/notes.adoc             |  57 +++
 Documentation/git-format-patch.adoc         |  11 +-
 Documentation/git-range-diff.adoc           |   8 +-
 Documentation/pretty-options.adoc           |   9 +
 Makefile                                    |   2 +
 builtin/log.c                               |  17 +-
 builtin/name-rev.c                          |   9 +-
 builtin/range-diff.c                        |   2 +
 contrib/completion/git-completion.bash      |   4 +-
 log-tree.c                                  |  10 +-
 meson.build                                 |   1 +
 notes-external.c                            | 330 ++++++++++++++
 notes-external.h                            |  19 +
 notes.c                                     | 244 ++++++++---
 notes.h                                     |  32 +-
 revision.c                                  |  32 +-
 run-command.c                               |  92 +++-
 run-command.h                               |  13 +
 strbuf.c                                    |  26 +-
 strbuf.h                                    |   4 +
 t/helper/meson.build                        |   1 +
 t/helper/test-external-notes                |  64 +++
 t/helper/test-notes-external-config-reset.c |  20 +
 t/helper/test-tool.c                        |   1 +
 t/helper/test-tool.h                        |   1 +
 t/lib-notes.sh                              |  19 +
 t/t3206-range-diff.sh                       |  68 +++
 t/t3301-notes.sh                            | 461 ++++++++++++++++++++
 t/t6120-describe.sh                         |  17 +
 wrapper.c                                   | 188 +++++++-
 wrapper.h                                   |  24 +
 31 files changed, 1702 insertions(+), 84 deletions(-)
 create mode 100644 notes-external.c
 create mode 100644 notes-external.h
 create mode 100755 t/helper/test-external-notes
 create mode 100644 t/helper/test-notes-external-config-reset.c
 create mode 100644 t/lib-notes.sh
Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/9 Documentation/git-range-diff: add missing notes options in synopsis

---
 Documentation/git-range-diff.adoc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/git-range-diff.adoc +1 -1
index 880557084533..5cc5e2ed5673 100644
@@ -11,7 +11,7 @@ SYNOPSIS
 git range-diff [--color=[<when>]] [--no-color] [<diff-options>]
 	[--no-dual-color] [--creation-factor=<factor>]
 	[--left-only | --right-only] [--diff-merges=<format>]
-	[--remerge-diff]
+	[--remerge-diff] [--no-notes | --notes[=<ref>]]
 	( <range1> <range2> | <rev1>...<rev2> | <base> <rev1> <rev2> )
 	[[--] <path>...]
 
Signature · 1 line
2.53.0
#10 lore raw

PATCH 4/9 run-command: add support for timeout in command finisher

In reply to Siddh Raman Pant

A called command may not respond to the initial signal and will get stuck in finish_command() -> wait_or_whine().

So let's add timeout support into the finisher so that if a deadline occurs, we can send a force-kill signal.

The force-kill signal is in the argument because a program may trap a signal, so it is the responsibility of caller to pass the correct kill signal.

Assisted-by Codex:gpt-5.5-xhigh-fast
---
 run-command.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++----
 run-command.h | 13 ++++++++
 2 files changed, 98 insertions(+), 7 deletions(-)
run-command.c +85 -7
index c146a56532a1..60b84610d1f0 100644
@@ -554,16 +554,63 @@ static inline void set_cloexec(int fd)
 		fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
 }
 
-static int wait_or_whine(pid_t pid, const char *argv0, int in_signal)
+#define NS_IN_10MS 10000000ULL	/* 10 ms = 10^-2 s = 10^(9-2) ns = 10^7 ns */
+
+/* If timeout_ns == 0, no timeout happens (the timeout path is not taken). */
+static int wait_or_whine_timeout(pid_t pid, const char *argv0, int in_signal,
+				 uint64_t timeout_ns)
 {
 	int status, code = -1;
 	pid_t waiting;
 	int failed_errno = 0;
+	int flags = timeout_ns ? WNOHANG : 0;
+	bool timed_out = false;
+	uint64_t deadline_ns = getnanotime() + timeout_ns;
+
+	while(1) {
+		uint64_t current_time_ns, remaining_ns;
+		waiting = waitpid(pid, &status, flags);
+
+		/* Retry if interrupted. */
+		if (waiting < 0 && errno == EINTR)
+			continue;
+
+		/* Break if exited. */
+		if (waiting)
+			break;
+
+		/* If no timeout is specified, retry till it exits. */
+		if (!timeout_ns)
+			continue;
 
-	while ((waiting = waitpid(pid, &status, 0)) < 0 && errno == EINTR)
-		;	/* nothing */
+		current_time_ns = getnanotime();
+
+		/* If we are past the deadline, set errno and break. */
+		if (deadline_ns <= current_time_ns) {
+			errno = ETIMEDOUT;
+			timed_out = true;
+			break;
+		}
+
+		/**
+		 * Retry after a sleep(min(remaining, default_chunk)).
+		 *
+		 * We don't blindly sleep for the entire remaining time because
+		 * the process can exit early.
+		 *
+		 * The subtraction of uint64_t is safe here since we have
+		 * already established that deadline_ns > current_time_ns.
+		 */
+		remaining_ns = deadline_ns - current_time_ns;
+		sleep_nanosec(remaining_ns < NS_IN_10MS ?
+			      remaining_ns : NS_IN_10MS);
+	}
 
-	if (waiting < 0) {
+	if (timed_out) {
+		failed_errno = errno;
+		if (!in_signal)
+			error_errno("waitpid for %s timed out", argv0);
+	} else if (waiting < 0) {
 		failed_errno = errno;
 		if (!in_signal)
 			error_errno("waitpid for %s failed", argv0);
@@ -587,13 +634,28 @@ static int wait_or_whine(pid_t pid, const char *argv0, int in_signal)
 			error("waitpid is confused (%s)", argv0);
 	}
 
-	if (!in_signal)
+	/**
+	 * Signal handlers use the cleanup list while reaping children, so only
+	 * non-signal waiters (in_signal != 0) should update it.
+	 *
+	 * In case of a timeout, we keep the child registered since it is
+	 * actually not reaped so removing would be wrong. It is the
+	 * responsibility of the caller to detect the timeout and do cleanup,
+	 * like sending a kill signal using this function without a timeout.
+	 */
+	if (!in_signal && !timed_out)
 		clear_child_for_cleanup(pid);
 
 	errno = failed_errno;
 	return code;
 }
 
+/* Non-timeout wrapper for compatibility. */
+static int wait_or_whine(pid_t pid, const char *argv0, int in_signal)
+{
+	return wait_or_whine_timeout(pid, argv0, in_signal, 0);
+}
+
 static void trace_add_env(struct strbuf *dst, const char *const *deltaenv)
 {
 	struct string_list envs = STRING_LIST_INIT_DUP;
@@ -989,15 +1051,31 @@ int start_command(struct child_process *cmd)
 	return 0;
 }
 
-int finish_command(struct child_process *cmd)
+/* See comment in the header file for executive summary. */
+int finish_command_with_timeout(struct child_process *cmd, uint64_t timeout_ns,
+				int signal_on_timeout)
 {
-	int ret = wait_or_whine(cmd->pid, cmd->args.v[0], 0);
+	int ret = wait_or_whine_timeout(cmd->pid, cmd->args.v[0], 0,
+					timeout_ns);
+
+	if (timeout_ns && ret < 0 && errno == ETIMEDOUT) {
+		kill(cmd->pid, signal_on_timeout);
+		ret = wait_or_whine(cmd->pid, cmd->args.v[0], 0);
+	}
+
 	trace2_child_exit(cmd, ret);
 	child_process_clear(cmd);
 	invalidate_lstat_cache();
 	return ret;
 }
 
+/* Non-timeout wrapper for compatibility. */
+int finish_command(struct child_process *cmd)
+{
+	return finish_command_with_timeout(cmd, 0, 0);
+}
+
+
 int finish_command_in_signal(struct child_process *cmd)
 {
 	int ret = wait_or_whine(cmd->pid, cmd->args.v[0], 1);
run-command.h +13 -0
index 8ca496d7bdeb..cb1c8ba4ec01 100644
@@ -215,6 +215,19 @@ int start_command(struct child_process *);
  */
 int finish_command(struct child_process *);
 
+/**
+ * Wait for the completion of a sub-process that was started with
+ * start_command(), but uptil a given timeout duration timeout_ns.
+ *
+ * If it has not exited after timeout_ns, signal_on_timeout is sent to the
+ * process. We don't enforce a timeout for the second wait after sending
+ * the signal (as the process cleanup needs to happen), so it will block there.
+ *
+ * If timeout_ns == 0, no timeout happens and signal_on_timeout is ignored.
+ */
+int finish_command_with_timeout(struct child_process *cmd, uint64_t timeout_ns,
+				int signal_on_timeout);
+
 int finish_command_in_signal(struct child_process *);
 
 /**
Signature · 1 line
2.53.0
#19 lore raw

PATCH 5/9 wrapper: add support for timeout and deadline in read helpers

In reply to Siddh Raman Pant

Add read helpers which allow a caller to enforce a timeout per read, and a deadline for the read in case multiple reads have to be done under a common timeout.

Assisted-by Codex:gpt-5.5-xhigh-fast
---
 strbuf.c  |  26 +++++++++-
 strbuf.h  |   4 ++
 wrapper.c | 139 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 wrapper.h |  23 +++++++++
 4 files changed, 182 insertions(+), 10 deletions(-)
strbuf.c +24 -2
index 3e04addc22fe..b3fc7c624aa2 100644
@@ -749,13 +749,15 @@ int strbuf_getline_nul(struct strbuf *sb, FILE *fp)
 	return strbuf_getdelim(sb, fp, '\0');
 }
 
-int strbuf_getwholeline_fd(struct strbuf *sb, int fd, int term)
+static int strbuf_getwholeline_fd_with(struct strbuf *sb, int fd, int term,
+				       xread_cb_t xread_cb,
+				       void *cb_data)
 {
 	strbuf_reset(sb);
 
 	while (1) {
 		char ch;
-		ssize_t len = xread(fd, &ch, 1);
+		ssize_t len = xread_cb(fd, &ch, 1, cb_data);
 		if (len <= 0)
 			return EOF;
 		strbuf_addch(sb, ch);
@@ -765,6 +767,26 @@ int strbuf_getwholeline_fd(struct strbuf *sb, int fd, int term)
 	return 0;
 }
 
+int strbuf_getwholeline_fd_deadline(struct strbuf *sb, int fd, int term,
+				    uint64_t deadline_ns)
+{
+	return strbuf_getwholeline_fd_with(sb, fd, term, xread_deadline_fn,
+					   &deadline_ns);
+}
+
+int strbuf_getwholeline_fd_timeout(struct strbuf *sb, int fd, int term,
+				   int timeout_ms)
+{
+	return strbuf_getwholeline_fd_with(sb, fd, term, xread_timeout_fn,
+					   &timeout_ms);
+}
+
+/* Non-timeout version for compatibility. */
+int strbuf_getwholeline_fd(struct strbuf *sb, int fd, int term)
+{
+	return strbuf_getwholeline_fd_timeout(sb, fd, term, 0);
+}
+
 ssize_t strbuf_read_file(struct strbuf *sb, const char *path, size_t hint)
 {
 	int fd;
strbuf.h +4 -0
index 06e284f9cca4..f896da1277a6 100644
@@ -535,6 +535,10 @@ int strbuf_appendwholeline(struct strbuf *sb, FILE *file, int term);
  * descriptor.
  */
 int strbuf_getwholeline_fd(struct strbuf *sb, int fd, int term);
+int strbuf_getwholeline_fd_timeout(struct strbuf *sb, int fd, int term,
+				   int timeout_ms);
+int strbuf_getwholeline_fd_deadline(struct strbuf *sb, int fd, int term,
+				    uint64_t deadline_ns);
 
 /**
  * Set the buffer to the path of the current working directory.
wrapper.c +131 -8

184 lines not on this page · raw message

wrapper.h +23 -0
index c39992893a81..f8592599216a 100644
@@ -15,6 +15,8 @@ const char *mmap_os_err(void);
 void *xmmap_gently(void *start, size_t length, int prot, int flags, int fd, off_t offset);
 int xopen(const char *path, int flags, ...);
 ssize_t xread(int fd, void *buf, size_t len);
+ssize_t xread_timeout(int fd, void *buf, size_t len, int timeout_ms);
+ssize_t xread_deadline(int fd, void *buf, size_t len, uint64_t deadline_ns);
 ssize_t xwrite(int fd, const void *buf, size_t len);
 ssize_t xpread(int fd, void *buf, size_t len, off_t offset);
 int xdup(int fd);
@@ -44,9 +46,30 @@ int git_mkstemps_mode(char *pattern, int suffix_len, int mode);
 int git_mkstemp_mode(char *pattern, int mode);
 
 ssize_t read_in_full(int fd, void *buf, size_t count);
+ssize_t read_in_full_timeout(int fd, void *buf, size_t count, int timeout_ms);
+ssize_t read_in_full_deadline(int fd, void *buf, size_t count,
+			      uint64_t deadline_ns);
 ssize_t write_in_full(int fd, const void *buf, size_t count);
 ssize_t pread_in_full(int fd, void *buf, size_t count, off_t offset);
 
+typedef ssize_t xread_cb_t(int fd, void *buf, size_t len, const void *cb_data);
+
+static inline ssize_t xread_timeout_fn(int fd, void *buf, size_t len,
+				       const void *cb_data)
+{
+	const int *timeout_ms = cb_data;
+
+	return xread_timeout(fd, buf, len, *timeout_ms);
+}
+
+static inline ssize_t xread_deadline_fn(int fd, void *buf, size_t len,
+					const void *cb_data)
+{
+	const uint64_t *deadline_ns = cb_data;
+
+	return xread_deadline(fd, buf, len, *deadline_ns);
+}
+
 static inline ssize_t write_str_in_full(int fd, const char *str)
 {
 	return write_in_full(fd, str, strlen(str));
Signature · 1 line
2.53.0
#20 lore raw

PATCH 6/9 t3301: cover generic displayed notes behavior

In reply to Siddh Raman Pant

Displayed notes already participate in common log behavior. Add explicit coverage for raw notes formatting, --no-notes suppression, explicit notes refs, and --grep matching before teaching external notes to feed the same display path.

Assisted-by Codex:gpt-5.5-xhigh-fast
---
 t/t3301-notes.sh | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
t/t3301-notes.sh +24 -0
index d6c50460d086..27439010dfbc 100755
@@ -885,6 +885,30 @@ test_expect_success '--show-notes=ref accumulates' '
 	test_cmp expect-both-reversed actual
 '
 
+test_expect_success 'displayed notes honor raw notes formatting' '
+	git show -s --format=%N >actual &&
+	test_grep "^order test$" actual &&
+	! grep "Notes" actual
+'
+
+test_expect_success 'displayed notes are suppressed by --no-notes' '
+	git log --no-notes -1 >actual &&
+	test_cmp expect-not-other actual
+'
+
+test_expect_success 'explicit notes ref replaces default displayed notes' '
+	git log --notes=other -1 >actual &&
+	test_cmp expect-other actual
+'
+
+test_expect_success 'displayed notes are used for grep matching' '
+	commit=$(git rev-parse HEAD) &&
+	git log --grep="order test" -1 >actual &&
+	test_grep "^commit $commit$" actual &&
+	git log --no-notes --grep="order test" -1 >actual &&
+	test_must_be_empty actual
+'
+
 test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
 	test_config core.notesRef refs/notes/other &&
 	echo "Note on a tree" >expect &&
Signature · 1 line
2.53.0
#21 lore raw

PATCH 7/9 notes: support an external command to display notes

In reply to Siddh Raman Pant

git notes is a very very helpful feature to show user-supplied information about a commit alongside its message transparently.

For distributed teams working on large git repos (huge number of branches/refs, files, etc.) and using the notes feature to mark information on git commits, a TOCTOU race can happen due to very large size of the repo and notes ref:
- Person A updates a note for commit X.
- Person A pushes the notes but it takes some time.
- Person B fetches notes and doesn't find the updated note.
- Person B can come to know of it only when he overwrites it and encounters a push failure.

This problem excaberates on scale.

One solution to this is a realtime fetch or faster updation via external means, but unfortunately we lose the coherence in the display of information, and the user would end up reinventing git log.

So let's add support for an external command to display the notes.

We split the addition of documentation and tests from this commit for easier review. The new help text added in Documentation/ in the next commit should make the usage clear.

Assisted-by Codex:gpt-5.5-xhigh-fast
---
 Makefile             |   2 +
 builtin/log.c        |  17 ++-
 builtin/name-rev.c   |   9 +-
 builtin/range-diff.c |   2 +
 log-tree.c           |   7 +-
 meson.build          |   1 +
 notes-external.c     | 330 +++++++++++++++++++++++++++++++++++++++++++
 notes-external.h     |  19 +++
 notes.c              | 242 ++++++++++++++++++++++++-------
 notes.h              |  32 ++++-
 revision.c           |  32 ++++-
 11 files changed, 633 insertions(+), 60 deletions(-)
 create mode 100644 notes-external.c
 create mode 100644 notes-external.h
Makefile +2 -0
index c739ae78d0ef..a919bdd75f01 100644
@@ -838,6 +838,7 @@ TEST_BUILTINS_OBJS += test-match-trees.o
 TEST_BUILTINS_OBJS += test-mergesort.o
 TEST_BUILTINS_OBJS += test-mktemp.o
 TEST_BUILTINS_OBJS += test-name-hash.o
+TEST_BUILTINS_OBJS += test-notes-external-config-reset.o
 TEST_BUILTINS_OBJS += test-online-cpus.o
 TEST_BUILTINS_OBJS += test-pack-deltas.o
 TEST_BUILTINS_OBJS += test-pack-mtimes.o
@@ -1209,6 +1210,7 @@ LIB_OBJS += negotiator/default.o
 LIB_OBJS += negotiator/noop.o
 LIB_OBJS += negotiator/skipping.o
 LIB_OBJS += notes-cache.o
+LIB_OBJS += notes-external.o
 LIB_OBJS += notes-merge.o
 LIB_OBJS += notes-utils.o
 LIB_OBJS += notes.o
builtin/log.c +16 -1
index 8c0939dd42ad..bed4c1576f2d 100644
@@ -1337,9 +1337,24 @@ static void get_notes_args(struct strvec *arg, struct rev_info *rev)
 		   (rev->notes_opt.use_default_notes == -1 &&
 		    !rev->notes_opt.extra_notes_refs.nr)) {
 		strvec_push(arg, "--notes");
-	} else {
+	} else if (rev->notes_opt.extra_notes_refs.nr) {
 		for_each_string_list(&rev->notes_opt.extra_notes_refs, get_notes_refs, arg);
+	} else if (rev->notes_opt.use_external_notes <= 0) {
+		/*
+		 * rev->show_notes can stay set after
+		 * --external-notes --no-external-notes.
+		 *
+		 * Since range-diff's child log starts with
+		 * --show-notes-by-default, explicitly suppress
+		 * notes when no notes source remains.
+		 */
+		strvec_push(arg, "--no-notes");
 	}
+
+	if (rev->notes_opt.use_external_notes > 0)
+		strvec_push(arg, "--external-notes");
+	else if (rev->notes_opt.use_external_notes == 0)
+		strvec_push(arg, "--no-external-notes");
 }
 
 static void generate_shortlog_cover_letter(struct shortlog *log,
builtin/name-rev.c +6 -3
index 60cbbfb4b7d1..95d5e076e24b 100644
@@ -277,6 +277,7 @@ struct name_ref_data {
 struct pretty_format {
 	struct pretty_print_context ctx;
 	struct userformat_want want;
+	bool show_external_notes;
 };
 
 enum command_type {
@@ -525,9 +526,9 @@ static const char *get_format_rev(const struct commit *c,
 	if (format_ctx->want.notes) {
 		struct strbuf notebuf = STRBUF_INIT;
 
-		format_display_notes(&c->object.oid, &notebuf,
-				     get_log_output_encoding(),
-				     format_ctx->ctx.fmt == CMIT_FMT_USERFORMAT);
+		format_display_notes(c, &notebuf, get_log_output_encoding(),
+				     format_ctx->ctx.fmt == CMIT_FMT_USERFORMAT,
+				     format_ctx->show_external_notes);
 		format_ctx->ctx.notes_message = strbuf_detach(&notebuf, NULL);
 	}
 
@@ -878,6 +879,8 @@ int cmd_format_rev(int argc,
 			enable_ref_display_notes(&format_notes_opt,
 						 &ignore_show_notes,
 						 n->string);
+		format_pp.show_external_notes =
+			display_notes_use_external(&format_notes_opt);
 		load_display_notes(&format_notes_opt);
 	}
 
builtin/range-diff.c +2 -0
index e54c0f7fe156..41c27250404a 100644
@@ -56,6 +56,8 @@ int cmd_range_diff(int argc,
 		OPT_PASSTHRU_ARGV(0, "notes", &log_arg,
 				  N_("notes"), N_("passed to 'git log'"),
 				  PARSE_OPT_OPTARG),
+		OPT_PASSTHRU_ARGV(0, "external-notes", &log_arg, NULL,
+				  N_("passed to 'git log'"), PARSE_OPT_NOARG),
 		OPT_PASSTHRU_ARGV(0, "diff-merges", &diff_merges_arg,
 				  N_("style"), N_("passed to 'git log'"), 0),
 		OPT_CALLBACK(0, "max-memory", &range_diff_opts.max_memory,
log-tree.c +5 -2
index 4503a42dde6b..3289a085f66b 100644
@@ -856,9 +856,12 @@ void show_log(struct rev_info *opt)
 	if (opt->show_notes) {
 		struct strbuf notebuf = STRBUF_INIT;
 		bool raw = (opt->commit_format == CMIT_FMT_USERFORMAT);
+		const struct display_notes_opt *notes_opt = &opt->notes_opt;
+
+		format_display_notes(commit, &notebuf,
+				     get_log_output_encoding(), raw,
+				     display_notes_use_external(notes_opt));
 
-		format_display_notes(&commit->object.oid, &notebuf,
-				     get_log_output_encoding(), raw);
 		ctx.notes_message = strbuf_detach(&notebuf, NULL);
 	}
 
meson.build +1 -0
index de917bcf1146..21cdbc15aa18 100644
@@ -397,6 +397,7 @@ libgit_sources = [
   'notes-merge.c',
   'notes-utils.c',
   'notes.c',
+  'notes-external.c',
   'object-file-convert.c',
   'object-file.c',
   'object-name.c',
notes-external.c new file +330 -0

330 lines not on this page · raw message

notes-external.h new file +19 -0
new file mode 100644
index 000000000000..e49a50b09063
@@ -0,0 +1,19 @@
+#ifndef NOTES_EXTERNAL_H
+#define NOTES_EXTERNAL_H
+
+struct object_id;
+struct strbuf;
+
+void set_external_notes_command(const char *command);
+void set_external_notes_command_name(const char *name);
+void set_external_notes_command_timeout_ms(int timeout_ms);
+void set_external_notes_for_grep(int enabled);
+void reset_external_notes_command(void);
+int external_notes_command_configured(void);
+const char *external_notes_command_name(void);
+int external_notes_command_timeout_ms(void);
+int external_notes_for_grep_enabled(void);
+int format_external_note(const struct object_id *object_oid,
+			 struct strbuf *out);
+
+#endif  /* NOTES_EXTERNAL_H */
notes.c +193 -49

347 lines not on this page · raw message

notes.h +29 -3
index f6410b31e1c9..748af70e34af 100644
@@ -6,6 +6,7 @@
 struct object_id;
 struct repository;
 struct strbuf;
+struct commit;
 
 /*
  * Function type for combining two notes annotating the same object.
@@ -264,6 +265,20 @@ struct display_notes_opt {
 	 */
 	int use_default_notes;
 
+	/*
+	 * Less than `0` is "unset", which means external notes are shown iff
+	 * the default notes are shown. Otherwise, treat it like a boolean.
+	 */
+	int use_external_notes;
+
+	/*
+	 * Tracks the synthetic "default notes off" state introduced by
+	 * `--external-notes`, so a later deprecated `--show-notes=<ref>`
+	 * can still preserve its historical additive behavior without
+	 * overriding an explicit `--no-standard-notes`.
+	 */
+	int default_notes_suppressed_by_external;
+
 	/*
 	 * A list of globs (in the same style as notes.displayRef) where
 	 * notes should be loaded from.
@@ -304,16 +319,27 @@ void disable_display_notes(struct display_notes_opt *opt, int *show_notes);
 void load_display_notes(struct display_notes_opt *opt);
 
 /*
- * Append notes for the given 'object_sha1' from all trees set up by
+ * Return true if notes.externalCommand should be used for 'opt'.
+ *
+ * 'opt' may be NULL.
+ */
+bool display_notes_use_external(const struct display_notes_opt *opt);
+
+/*
+ * Append notes for the given commit from all trees set up by
  * load_display_notes() to 'sb'.
  *
  * If 'raw' is false the note will be indented by 4 places and
  * a 'Notes (refname):' header added.
  *
+ * If 'show_external' is true then notes.externalCommand will be used to append
+ * the note from external source.
+ *
  * You *must* call load_display_notes() before using this function.
  */
-void format_display_notes(const struct object_id *object_oid,
-			  struct strbuf *sb, const char *output_encoding, bool raw);
+void format_display_notes(const struct commit *commit,
+			  struct strbuf *sb, const char *output_encoding,
+			  bool raw, bool show_external);
 
 /*
  * Load the notes tree from each ref listed in 'refs'.  The output is
revision.c +30 -2
index cd9fcefa0a88..84d9af961988 100644
@@ -6,6 +6,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "hex.h"
+#include "notes-external.h"
 #include "object-name.h"
 #include "object-file.h"
 #include "odb.h"
@@ -2583,18 +2584,40 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 	} else if (skip_prefix(arg, "--show-notes=", &optarg) ||
 		   skip_prefix(arg, "--notes=", &optarg)) {
 		if (starts_with(arg, "--show-notes=") &&
-		    revs->notes_opt.use_default_notes < 0)
+		    (revs->notes_opt.use_default_notes < 0 ||
+		     revs->notes_opt.default_notes_suppressed_by_external)) {
 			revs->notes_opt.use_default_notes = 1;
+			revs->notes_opt.default_notes_suppressed_by_external = 0;
+		}
 		enable_ref_display_notes(&revs->notes_opt, &revs->show_notes, optarg);
 		revs->show_notes_given = 1;
 	} else if (!strcmp(arg, "--no-notes")) {
 		disable_display_notes(&revs->notes_opt, &revs->show_notes);
 		revs->show_notes_given = 1;
+	} else if (!strcmp(arg, "--external-notes")) {
+		revs->notes_opt.use_external_notes = 1;
+		revs->show_notes = 1;
+		revs->show_notes_given = 1;
+		/*
+		 * `--external-notes` names a note source on its own. If the
+		 * default notes ref is still undecided, settle it to "off" so
+		 * this option does not also trigger the "no explicit notes
+		 * refs" fallback. A later use of `--notes` or the deprecated
+		 * `--show-notes=<ref>` can still turn the default ref on.
+		 */
+		if (revs->notes_opt.use_default_notes < 0) {
+			revs->notes_opt.use_default_notes = 0;
+			revs->notes_opt.default_notes_suppressed_by_external = 1;
+		}
+	} else if (!strcmp(arg, "--no-external-notes")) {
+		revs->notes_opt.use_external_notes = 0;
 	} else if (!strcmp(arg, "--standard-notes")) {
 		revs->show_notes_given = 1;
 		revs->notes_opt.use_default_notes = 1;
+		revs->notes_opt.default_notes_suppressed_by_external = 0;
 	} else if (!strcmp(arg, "--no-standard-notes")) {
 		revs->notes_opt.use_default_notes = 0;
+		revs->notes_opt.default_notes_suppressed_by_external = 0;
 	} else if (!strcmp(arg, "--oneline")) {
 		revs->verbose_header = 1;
 		get_commit_format("oneline", revs);
@@ -4105,9 +4128,14 @@ static int commit_match(struct commit *commit, struct rev_info *opt)
 
 	/* Append "fake" message parts as needed */
 	if (opt->show_notes) {
+		const struct display_notes_opt *notes_opt = &opt->notes_opt;
+
 		if (!buf.len)
 			strbuf_addstr(&buf, message);
-		format_display_notes(&commit->object.oid, &buf, encoding, true);
+
+		format_display_notes(commit, &buf, encoding, true,
+				     (display_notes_use_external(notes_opt)
+				      && external_notes_for_grep_enabled()));
 	}
 
 	/*
Signature · 1 line
2.53.0
#6 lore raw

PATCH 2/9 notes: convert raw arg in format_display_notes() to bool

In reply to Siddh Raman Pant

It's used as a boolean flag, let's not use an int.

---
 log-tree.c | 3 +--
 notes.c    | 6 +++---
 notes.h    | 2 +-
 revision.c | 2 +-
 4 files changed, 6 insertions(+), 7 deletions(-)
log-tree.c +1 -2
index 7e048701d0c5..4503a42dde6b 100644
@@ -854,10 +854,9 @@ void show_log(struct rev_info *opt)
 	}
 
 	if (opt->show_notes) {
-		int raw;
 		struct strbuf notebuf = STRBUF_INIT;
+		bool raw = (opt->commit_format == CMIT_FMT_USERFORMAT);
 
-		raw = (opt->commit_format == CMIT_FMT_USERFORMAT);
 		format_display_notes(&commit->object.oid, &notebuf,
 				     get_log_output_encoding(), raw);
 		ctx.notes_message = strbuf_detach(&notebuf, NULL);
notes.c +3 -3
index 8f315e2a00d2..201f1df3dc29 100644
@@ -1273,11 +1273,11 @@ void free_notes(struct notes_tree *t)
  * If the given notes_tree is NULL, the internal/default notes_tree will be
  * used instead.
  *
- * (raw != 0) gives the %N userformat; otherwise, the note message is given
+ * (raw == true) gives the %N userformat; otherwise, the note message is given
  * for human consumption.
  */
 static void format_note(struct notes_tree *t, const struct object_id *object_oid,
-			struct strbuf *sb, const char *output_encoding, int raw)
+			struct strbuf *sb, const char *output_encoding, bool raw)
 {
 	static const char utf8[] = "utf-8";
 	const struct object_id *oid;
@@ -1338,7 +1338,7 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
 }
 
 void format_display_notes(const struct object_id *object_oid,
-			  struct strbuf *sb, const char *output_encoding, int raw)
+			  struct strbuf *sb, const char *output_encoding, bool raw)
 {
 	int i;
 	assert(display_notes_trees);
notes.h +1 -1
index 6dc6d7b26548..f6410b31e1c9 100644
@@ -313,7 +313,7 @@ void load_display_notes(struct display_notes_opt *opt);
  * You *must* call load_display_notes() before using this function.
  */
 void format_display_notes(const struct object_id *object_oid,
-			  struct strbuf *sb, const char *output_encoding, int raw);
+			  struct strbuf *sb, const char *output_encoding, bool raw);
 
 /*
  * Load the notes tree from each ref listed in 'refs'.  The output is
revision.c +1 -1
index 599b3a66c369..cd9fcefa0a88 100644
@@ -4107,7 +4107,7 @@ static int commit_match(struct commit *commit, struct rev_info *opt)
 	if (opt->show_notes) {
 		if (!buf.len)
 			strbuf_addstr(&buf, message);
-		format_display_notes(&commit->object.oid, &buf, encoding, 1);
+		format_display_notes(&commit->object.oid, &buf, encoding, true);
 	}
 
 	/*
Signature · 1 line
2.53.0
#7 lore raw

PATCH 3/9 wrapper: add sleep_nanosec

In reply to Siddh Raman Pant
---
 wrapper.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 wrapper.h |  1 +
 2 files changed, 50 insertions(+)
wrapper.c +49 -0
index 16f5a63fbb61..1349255f1eb4 100644
@@ -10,6 +10,7 @@
 #include "gettext.h"
 #include "strbuf.h"
 #include "trace2.h"
+#include <time.h>
 
 #ifdef HAVE_RTLGENRANDOM
 /* This is required to get access to RtlGenRandom. */
@@ -708,6 +709,54 @@ void sleep_millisec(int millisec)
 	poll(NULL, 0, millisec);
 }
 
+#ifdef GIT_WINDOWS_NATIVE
+/* No nanosleep() on Windows, so fall-back to using sleep_millisec(). */
+int sleep_nanosec(uint64_t nanosec)
+{
+	uint64_t ns_in_1ms = 1000000ULL;	/* 1 ms = 10^6 ns */
+
+	uint64_t millisec = nanosec / ns_in_1ms;
+	if (nanosec % ns_in_1ms)
+		millisec++;
+
+	/* Chunked sleep if we can't represent in integer. */
+	while (millisec > INT_MAX) {
+		sleep_millisec(INT_MAX);
+		millisec -= INT_MAX;
+	}
+
+	sleep_millisec((int)millisec);
+
+	return 0;
+}
+#else
+/* Not Windows, so use the more exact nanosleep(). */
+int sleep_nanosec(uint64_t nanosec)
+{
+	int ret;
+	struct timespec duration, remaining;
+
+	/* Construct the duration by dividing the given total (1s = 10^9ns). */
+	duration.tv_sec = nanosec / 1000000000ULL;
+	duration.tv_nsec = nanosec % 1000000000ULL;
+
+	while(1) {
+		ret = nanosleep(&duration, &remaining);
+
+		/* Continue sleeping if interrupted. */
+		if (ret == -1 && errno == EINTR) {
+			duration = remaining;
+			continue;
+		}
+
+		/* Either success or an error. */
+		break;
+	}
+
+	return ret;
+}
+#endif  /* GIT_WINDOWS_NATIVE */
+
 int xgethostname(char *buf, size_t len)
 {
 	/*
wrapper.h +1 -0
index 15ac3bab6e97..c39992893a81 100644
@@ -130,6 +130,7 @@ int warn_on_fopen_errors(const char *path);
 int open_nofollow(const char *path, int flags);
 
 void sleep_millisec(int millisec);
+int sleep_nanosec(uint64_t nanosec);
 
 enum {
 	/*
Signature · 1 line
2.53.0
#27 lore raw

PATCH 8/9 Documentation: document external notes command options

In reply to Siddh Raman Pant
Assisted-by Codex:gpt-5.5-xhigh-fast
---
 Documentation/config/notes.adoc        | 57 ++++++++++++++++++++++++++
 Documentation/git-format-patch.adoc    | 11 ++++-
 Documentation/git-range-diff.adoc      |  6 +++
 Documentation/pretty-options.adoc      |  9 ++++
 contrib/completion/git-completion.bash |  4 +-
 5 files changed, 84 insertions(+), 3 deletions(-)
Documentation/config/notes.adoc +57 -0
index b7e536496f51..b3ef3fa52950 100644
@@ -34,6 +34,63 @@ The effective value of `core.notesRef` (possibly overridden by
 `GIT_NOTES_REF`) is also implicitly added to the list of refs to be
 displayed.
 
+`notes.externalCommand`::
+	Command to invoke as a long-lived helper when showing commit messages
+	with the `git log` family of commands. Git sends one commit object ID
+	per request on the command's standard input:
++
+------------
+<hex-commit-id>
+------------
++
+For each request, the command must respond on its standard output with either
+`<hex-commit-id> missing` followed by a newline, or `<hex-commit-id> ok <n>`
+followed by a newline and exactly `<n>` bytes of UTF-8 note text followed by a
+newline. The command must respond to each request as it is received; Git does
+not send all commit object IDs before reading responses. Empty note text is not
+displayed. If Git cannot start or communicate with the command, or the command
+sends an invalid response, Git warns once and disables it for the rest of the
+command. External notes are only used while formatting output by default; see
+`notes.externalCommandForGrep` to include them when matching commits.
++
+This setting is only respected in protected configuration (see
+linkgit:git-config[1]). This prevents untrusted repositories from running
+arbitrary commands when notes are displayed.
++
+This setting does not take effect when:
++
+--
+* the value is empty;
+* `--no-notes` is given;
+* `--no-external-notes` is given; or
+* `--notes=<ref>` is given by itself without `--external-notes` or `--notes`.
+--
+
+`notes.externalCommandName`::
+	Name to use in the `Notes (<name>):` header for notes returned by
+	`notes.externalCommand`. Defaults to `external`. This setting is only
+	respected in protected configuration.
+
+`notes.externalCommandTimeoutMs`::
+	Number of milliseconds to wait when reading each response from
+	`notes.externalCommand`. Defaults to `100`. If the command does not
+	produce the expected response in time, Git warns once and disables it
+	for the rest of the command. A value of `0` disables timeout handling,
+	so reads can block until the command writes output or exits. This
+	setting is only	respected in protected configuration.
+
+`notes.externalCommandForGrep`::
+	Boolean indicating whether notes returned by `notes.externalCommand`
+	are included when matching commits with `--grep`, wherever notes would
+	normally participate in grep matching. Defaults to false. This does
+	not make hidden notes searchable in formats such as `--oneline` or
+	`--pretty=%s`; use `--notes` or `--external-notes` if those formats
+	should search notes too. When enabled, revision traversal may invoke
+	the external command for many commits that are not ultimately
+	displayed, which can be expensive for slow commands. The note output
+	can also change which commits match. This setting is only respected in
+	protected configuration.
+
 `notes.rewrite.<command>`::
 	When rewriting commits with _<command>_ (currently `amend` or
 	`rebase`), if this variable is `false`, git will not copy
Documentation/git-format-patch.adoc +10 -1
index 566238245028..472b37e5237a 100644
@@ -26,7 +26,7 @@ SYNOPSIS
 		   [--[no-]cover-letter] [--quiet]
 		   [--commit-list-format=<format-spec>]
 		   [--[no-]encode-email-headers]
-		   [--no-notes | --notes[=<ref>]]
+		   [--no-notes | --notes[=<ref>]] [--[no-]external-notes]
 		   [--interdiff=<previous>]
 		   [--range-diff=<previous> [--creation-factor=<percent>]]
 		   [--filename-max-length=<n>]
@@ -395,6 +395,15 @@ configuration options in linkgit:git-notes[1] to use this workflow).
 The default is `--no-notes`, unless the `format.notes` configuration is
 set.
 
+--external-notes::
+--no-external-notes::
+	Invoke or do not invoke `notes.externalCommand` to obtain external
+	notes. Like `--notes=<ref>`, `--external-notes` names an explicit
+	note source and by itself does not include the default notes refs.
+	Use `--external-notes --notes` to include the default notes refs
+	too, or combine `--external-notes` with `--notes=<ref>` to include
+	external notes with specific notes refs.
+
 --signature=<signature>::
 --no-signature::
 	Add a signature to each message produced. Per RFC 3676 the signature
Documentation/git-range-diff.adoc +6 -0
index 5cc5e2ed5673..1de23f300517 100644
@@ -12,6 +12,7 @@ git range-diff [--color=[<when>]] [--no-color] [<diff-options>]
 	[--no-dual-color] [--creation-factor=<factor>]
 	[--left-only | --right-only] [--diff-merges=<format>]
 	[--remerge-diff] [--no-notes | --notes[=<ref>]]
+	[--[no-]external-notes]
 	( <range1> <range2> | <rev1>...<rev2> | <base> <rev1> <rev2> )
 	[[--] <path>...]
 
@@ -101,6 +102,11 @@ diff.
 	This flag is passed to the `git log` program
 	(see linkgit:git-log[1]) that generates the patches.
 
+`--external-notes`::
+`--no-external-notes`::
+	This flag is passed to the `git log` program
+	(see linkgit:git-log[1]) that generates the patches.
+
 `<range1> <range2>`::
 	Compare the commits specified by the two ranges, where
 	_<range1>_ is considered an older version of _<range2>_.
Documentation/pretty-options.adoc +9 -0
index 658e462b2533..aad851c92cfd 100644
@@ -93,6 +93,15 @@ being displayed. Examples: "`--notes=foo`" will show only notes from
 	"`--notes --notes=foo --no-notes --notes=bar`" will only show notes
 	from `refs/notes/bar`.
 
+`--external-notes`::
+`--no-external-notes`::
+	Invoke or do not invoke `notes.externalCommand` to obtain external
+	notes. Like `--notes=<ref>`, `--external-notes` names an explicit
+	note source and by itself does not include the default notes refs.
+	Use `--external-notes --notes` to include the default notes refs
+	too, or combine `--external-notes` with `--notes=<ref>` to include
+	external notes with specific notes refs.
+
 `--show-notes-by-default`::
 	Show the default notes unless options for displaying specific
 	notes are given.
contrib/completion/git-completion.bash +2 -2
index a8e7c6ddbfb2..146444e65860 100644
@@ -2023,7 +2023,7 @@ _git_fetch ()
 
 __git_format_patch_extra_options="
 	--full-index --not --all --no-prefix --src-prefix=
-	--dst-prefix= --notes
+	--dst-prefix= --notes --external-notes --no-external-notes
 "
 
 _git_format_patch ()
@@ -2215,7 +2215,7 @@ __git_log_common_options="
 __git_log_gitk_options="
 	--dense --sparse --full-history
 	--simplify-merges --simplify-by-decoration
-	--left-right --notes --no-notes
+	--left-right --notes --no-notes --external-notes --no-external-notes
 "
 # Options that go well for log and shortlog (not gitk)
 __git_log_shortlog_options="
Signature · 1 line
2.53.0
#28 lore raw

PATCH 9/9 t: add tests for external notes command

In reply to Siddh Raman Pant
Assisted-by Codex:gpt-5.5-xhigh-fast
---
 t/helper/meson.build                        |   1 +
 t/helper/test-external-notes                |  64 +++
 t/helper/test-notes-external-config-reset.c |  20 +
 t/helper/test-tool.c                        |   1 +
 t/helper/test-tool.h                        |   1 +
 t/lib-notes.sh                              |  19 +
 t/t3206-range-diff.sh                       |  68 +++
 t/t3301-notes.sh                            | 437 ++++++++++++++++++++
 t/t6120-describe.sh                         |  17 +
 9 files changed, 628 insertions(+)
 create mode 100755 t/helper/test-external-notes
 create mode 100644 t/helper/test-notes-external-config-reset.c
 create mode 100644 t/lib-notes.sh
t/helper/meson.build +1 -0
index 675e64c0101b..739614b90e78 100644
@@ -35,6 +35,7 @@ test_tool_sources = [
   'test-mergesort.c',
   'test-mktemp.c',
   'test-name-hash.c',
+  'test-notes-external-config-reset.c',
   'test-online-cpus.c',
   'test-pack-deltas.c',
   'test-pack-mtimes.c',
t/helper/test-external-notes new file +64 -0

64 lines not on this page · raw message

t/helper/test-notes-external-config-reset.c new file +20 -0
new file mode 100644
index 000000000000..1c6b26e3b49a
@@ -0,0 +1,20 @@
+#include "test-tool.h"
+#include "notes-external.h"
+
+int cmd__notes_external_config_reset(int argc, const char **argv UNUSED)
+{
+	if (argc != 1)
+		die("usage: test-tool notes-external-config-reset");
+
+	set_external_notes_command("helper");
+	set_external_notes_command_name("label");
+	set_external_notes_command_timeout_ms(250);
+	set_external_notes_for_grep(1);
+	reset_external_notes_command();
+
+	printf("configured=%d\n", external_notes_command_configured());
+	printf("name=%s\n", external_notes_command_name());
+	printf("timeout_ms=%d\n", external_notes_command_timeout_ms());
+	printf("grep=%d\n", external_notes_for_grep_enabled());
+	return 0;
+}
t/helper/test-tool.c +1 -0
index a7abc618b388..31bb2d1dca47 100644
@@ -45,6 +45,7 @@ static struct test_cmd cmds[] = {
 	{ "mergesort", cmd__mergesort },
 	{ "mktemp", cmd__mktemp },
 	{ "name-hash", cmd__name_hash },
+	{ "notes-external-config-reset", cmd__notes_external_config_reset },
 	{ "online-cpus", cmd__online_cpus },
 	{ "pack-deltas", cmd__pack_deltas },
 	{ "pack-mtimes", cmd__pack_mtimes },
t/helper/test-tool.h +1 -0
index 7f150fa1eb9a..ff25f0a29cf2 100644
@@ -38,6 +38,7 @@ int cmd__match_trees(int argc, const char **argv);
 int cmd__mergesort(int argc, const char **argv);
 int cmd__mktemp(int argc, const char **argv);
 int cmd__name_hash(int argc, const char **argv);
+int cmd__notes_external_config_reset(int argc, const char **argv);
 int cmd__online_cpus(int argc, const char **argv);
 int cmd__pack_deltas(int argc, const char **argv);
 int cmd__pack_mtimes(int argc, const char **argv);
t/lib-notes.sh new file +19 -0
new file mode 100644
index 000000000000..07422540d58f
@@ -0,0 +1,19 @@
+# Helpers for scripts testing notes behavior.
+
+# notes.externalCommand is run through a shell, so quote the path.
+external_notes_command=$(
+	printf "%s\n" "$TEST_DIRECTORY/helper/test-external-notes" |
+	sed "s/'/'\\\\''/g; s/^/'/; s/$/'/"
+)
+
+# The helper above is a shell script. Few Windows CI tests (3 out of 10
+# in matrix) are spending more than the production default timeout just
+# starting the shell and exchanging the first response, so tests that
+# are not about timeout behavior fail. So let us opt into a wider 1s
+# deadline for Windows instead of 100ms.
+external_notes_command_timeout_config=
+if test_have_prereq MINGW
+then
+	_timeout_config="notes.externalCommandTimeoutMs=1000"
+	external_notes_command_timeout_config="-c $_timeout_config"
+fi
t/t3206-range-diff.sh +68 -0

86 lines not on this page · raw message

t/t3301-notes.sh +437 -0

455 lines not on this page · raw message

t/t6120-describe.sh +17 -0
index 8ee3d2c37d02..abbdb42dc9f7 100755
@@ -15,6 +15,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
 . ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-notes.sh
 
 check_describe () {
 	indir= &&
@@ -867,6 +868,22 @@ test_expect_success 'format-rev with %N (note)' '
 	test_cmp expect actual
 '
 
+test_expect_success 'format-rev with %N uses external notes' '
+	commit=$(git -C repo-format rev-parse HEAD) &&
+	rm -f repo-format/format-rev-external-notes-starts \
+		repo-format/format-rev-external-notes-requests &&
+	printf "%s\n" "$commit" >input &&
+	printf "%s\n\n" "$commit" >expect &&
+	TEST_EXTERNAL_NOTES_PREFIX=format-rev-external-notes \
+	git -C repo-format -c notes.externalCommand="$external_notes_command" \
+		$external_notes_command_timeout_config \
+		format-rev --stdin-mode=text --format="tformat:%N" \
+		<input >actual &&
+	test_line_count = 1 repo-format/format-rev-external-notes-starts &&
+	test_cmp input repo-format/format-rev-external-notes-requests &&
+	test_cmp expect actual
+'
+
 test_expect_success 'format-rev --notes<ref> (custom notes ref)' '
 	# One custom notes ref
 	test_when_finished "git -C repo-format notes remove" &&
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH 1/9] Documentation/git-range-diff: add missing notes options in synopsis

In reply to Siddh Raman Pant
Quoted 4 lines · Siddh Raman Pant
---
 Documentation/git-range-diff.adoc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

This has nothing to do with "external notes" topic, no?

Quoted 13 lines
Documentation/git-range-diff.adoc +1 -1
index 880557084533..5cc5e2ed5673 100644
@@ -11,7 +11,7 @@ SYNOPSIS
 git range-diff [--color=[<when>]] [--no-color] [<diff-options>]
 	[--no-dual-color] [--creation-factor=<factor>]
 	[--left-only | --right-only] [--diff-merges=<format>]
-	[--remerge-diff]
+	[--remerge-diff] [--no-notes | --notes[=<ref>]]
 	( <range1> <range2> | <rev1>...<rev2> | <base> <rev1> <rev2> )
 	[[--] <path>...]
#8 lore raw

Re: [PATCH 3/9] wrapper: add sleep_nanosec

In reply to Siddh Raman Pant
Quoted 2 lines · Siddh Raman Pant

---

The space above the signed-off-by line should be utilized to explain why we want this change. For the purpose of this series, why do we want to sleep at nanosecond precision?

Quoted 83 lines
 wrapper.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 wrapper.h |  1 +
 2 files changed, 50 insertions(+)
wrapper.c +49 -0
index 16f5a63fbb61..1349255f1eb4 100644
@@ -10,6 +10,7 @@
 #include "gettext.h"
 #include "strbuf.h"
 #include "trace2.h"
+#include <time.h>
 
 #ifdef HAVE_RTLGENRANDOM
 /* This is required to get access to RtlGenRandom. */
@@ -708,6 +709,54 @@ void sleep_millisec(int millisec)
 	poll(NULL, 0, millisec);
 }
 
+#ifdef GIT_WINDOWS_NATIVE
+/* No nanosleep() on Windows, so fall-back to using sleep_millisec(). */
+int sleep_nanosec(uint64_t nanosec)
+{
+	uint64_t ns_in_1ms = 1000000ULL;	/* 1 ms = 10^6 ns */
+
+	uint64_t millisec = nanosec / ns_in_1ms;
+	if (nanosec % ns_in_1ms)
+		millisec++;
+
+	/* Chunked sleep if we can't represent in integer. */
+	while (millisec > INT_MAX) {
+		sleep_millisec(INT_MAX);
+		millisec -= INT_MAX;
+	}
+
+	sleep_millisec((int)millisec);
+
+	return 0;
+}
+#else
+/* Not Windows, so use the more exact nanosleep(). */
+int sleep_nanosec(uint64_t nanosec)
+{
+	int ret;
+	struct timespec duration, remaining;
+
+	/* Construct the duration by dividing the given total (1s = 10^9ns). */
+	duration.tv_sec = nanosec / 1000000000ULL;
+	duration.tv_nsec = nanosec % 1000000000ULL;
+
+	while(1) {
+		ret = nanosleep(&duration, &remaining);
+
+		/* Continue sleeping if interrupted. */
+		if (ret == -1 && errno == EINTR) {
+			duration = remaining;
+			continue;
+		}
+
+		/* Either success or an error. */
+		break;
+	}
+
+	return ret;
+}
+#endif  /* GIT_WINDOWS_NATIVE */
+
 int xgethostname(char *buf, size_t len)
 {
 	/*
wrapper.h +1 -0
index 15ac3bab6e97..c39992893a81 100644
@@ -130,6 +130,7 @@ int warn_on_fopen_errors(const char *path);
 int open_nofollow(const char *path, int flags);
 
 void sleep_millisec(int millisec);
+int sleep_nanosec(uint64_t nanosec);
 
 enum {
 	/*
#22 lore raw

Re: [PATCH 7/9] notes: support an external command to display notes

In reply to Siddh Raman Pant
Quoted 8 lines · Siddh Raman Pant

This problem excaberates on scale.

One solution to this is a realtime fetch or faster updation via external means, but unfortunately we lose the coherence in the display of information, and the user would end up reinventing git log.

So let's add support for an external command to display the notes.

It is unclear how we would arrive at "So let's" from the previous paragraph. It is not limited to notes but multiple people updating the same thing racing against each other happens all the time in the main part of the history, no? Isn't a better solution for such racing situation usually based on a better merge support, I have to wonder?

Quoted 3 lines

We split the addition of documentation and tests from this commit for easier review. The new help text added in Documentation/ in the next commit should make the usage clear.

It is unclear why a large body of code that is not documented or whose uses are not illustrated by examples found in the test scripts is easier to review, though.

#23 lore raw

Re: [PATCH 7/9] notes: support an external command to display notes

Quoted 9 lines · Junio C Hamano
Quoted 7 lines · Siddh Raman Pant

This problem excaberates on scale.

One solution to this is a realtime fetch or faster updation via external means, but unfortunately we lose the coherence in the display of information, and the user would end up reinventing git log.

Quoted 8 lines
Quoted 1 line

So let's add support for an external command to display the notes.

It is unclear how we would arrive at "So let's" from the previous paragraph. It is not limited to notes but multiple people updating the same thing racing against each other happens all the time in the main part of the history, no? Isn't a better solution for such racing situation usually based on a better merge support, I have to wonder?

Sorry, I should have been clear.

The issue I meant to describe is not primarily about two people updating the same note object at the same time.

The workflow I have in mind is different. In kernel work, the same logical upstream fix can appear as different commit objects across many downstream branches, such as the stable branches and vendor-specific branches (based on which the released kernel is actually built). Different developers may be working on those branches in parallel, and a review decision recorded for one backport is useful context for the others.

Today, seeing that decision in ordinary history output requires first synchronizing the local notes ref, and then interpreting those notes for the branch being inspected. The latter step is workflow-specific and can be cheap, but keeping the local notes state fresh enough can be expensive in a large kernel repository with a large shared notes history (and if we are to extrapolate, a slow git server conn/ops can be a factor too).

That is the synchronization problem I was trying to describe: not that Git should solve all concurrent note updates, but that users can be looking at stale note-derived information simply because their local notes state has not caught up yet and catching up is expensive.

The intended role of the external command is to move that freshness policy out of Git's notes ref synchronization path. A site-specific helper can decide how to obtain current note text for the commit being displayed, such as consulting an external service, doing a targeted lookup, or using its own cache/update policy. Git still owns the coherent git log/show presentation; the helper only supplies the note text to display.

Quoted 7 lines
Quoted 3 lines

We split the addition of documentation and tests from this commit for easier review. The new help text added in Documentation/ in the next commit should make the usage clear.

It is unclear why a large body of code that is not documented or whose uses are not illustrated by examples found in the test scripts is easier to review, though.

Okay my bad. I'll squash them in v2 after this discussion, along with rewording the commit.

Thanks,
Siddh

#3 lore raw

Re: [PATCH 1/9] Documentation/git-range-diff: add missing notes options in synopsis

In reply to Junio C Hamano
Quoted 1 line · Junio C Hamano

This has nothing to do with "external notes" topic, no?

Yeah, but since I added the command line flag I found it doesn't mention the existing flags.

Fixing it in the "external notes" commit would be bad, so I put it before that, since it also then provides a logical place to add new flags.

Thanks,
Siddh

#9 lore raw

Re: [PATCH 3/9] wrapper: add sleep_nanosec

In reply to Junio C Hamano
Quoted 3 lines · Junio C Hamano

The space above the signed-off-by line should be utilized to explain why we want this change.  For the purpose of this series, why do we want to sleep at nanosecond precision?

The current time returned by getnanotime() is in nanoseconds which is used for deadline, so to avoid re-casting in helper code path we try to stay in nanosecond world. The caller can store in ns once and reuse it everytime.

Thanks,
Siddh

#4 lore raw

Re: [PATCH 1/9] Documentation/git-range-diff: add missing notes options in synopsis

In reply to Siddh Raman Pant
Quoted 9 lines · Siddh Raman Pant
Quoted 1 line · Junio C Hamano

This has nothing to do with "external notes" topic, no?

Yeah, but since I added the command line flag I found it doesn't mention the existing flags.

Fixing it in the "external notes" commit would be bad, so I put it before that, since it also then provides a logical place to add new flags.

What I meant was that it would have been better as a standalone patch that is unrelated to the (now) 8-patch topic for the external notes. That way, it can move faster without waiting for the rest.

Unless this patch has complex semantic or textual conflicts that makes it easier to manage together with the external notes series, that is. I think adding [--notes=...] to one existing line (this patch) and adding a new line with [--[no-]external] on it (the main part of the topic) can be done in parallel and it is not too much to ask for the integrator to merge them on the receiving end.

Thanks.

#24 lore raw

Re: [PATCH 7/9] notes: support an external command to display notes

In reply to Siddh Raman Pant
Quoted 20 lines · Siddh Raman Pant

git notes is a very very helpful feature to show user-supplied information about a commit alongside its message transparently.

For distributed teams working on large git repos (huge number of branches/refs, files, etc.) and using the notes feature to mark information on git commits, a TOCTOU race can happen due to very large size of the repo and notes ref:
- Person A updates a note for commit X.
- Person A pushes the notes but it takes some time.
- Person B fetches notes and doesn't find the updated note.
- Person B can come to know of it only when he overwrites it and encounters a push failure.

This problem excaberates on scale.

One solution to this is a realtime fetch or faster updation via external means, but unfortunately we lose the coherence in the display of information, and the user would end up reinventing git log.

Quoted 7 lines

So let's add support for an external command to display the notes.

We split the addition of documentation and tests from this commit for easier review. The new help text added in Documentation/ in the next commit should make the usage clear.

Assisted-by Codex:gpt-5.5-xhigh-fast

Just a question here: was this written in whole or in part by Codex, or was it just used as a reference to ask questions? I ask because the style of notes-external.c differs quite a bit from the style we use (for one, the horizontal rule comments) and we have this in SubmittingPatches:

The Developer's Certificate of Origin requires contributors to certify that they know the origin of their contributions to the project and that they have the right to submit it under the project's license. It's not yet clear that this can be legally satisfied when submitting significant amount of content that has been generated by AI tools.

[...]

To avoid these issues, we will reject anything that looks AI generated, that sounds overly formal or bloated, that looks like AI slop, that looks good on the surface but makes no sense, or that senders don’t understand or cannot explain.

I'll note that it also has a lot of global variables, which are common in the codebase but we're trying to move away from, and it's more verbose in commenting than we'd normally see elsewhere in the codebase.

Signature · 2 lines
brian m. carlson (they/them)
Toronto, Ontario, CA
#25 lore raw

Re: [PATCH 7/9] notes: support an external command to display notes

Quoted 6 lines · brian m. carlson
Quoted 1 line
Assisted-by Codex:gpt-5.5-xhigh-fast

Just a question here: was this written in whole or in part by Codex, or was it just used as a reference to ask questions? I ask because the style of notes-external.c differs quite a bit from the style we use (for one, the horizontal rule comments) and we have this in

AI tools typically don't generate comments in code like in this series, you can see by trying out for yourself. Each comment is hand-written by me. Sorry, I'll remove those lines in v2 after this discussion.

AI was used for review, and providing the initial skeletal, which I changed significantly.

Quoted 8 lines

SubmittingPatches:

The Developer's Certificate of Origin requires contributors to certify that they know the origin of their contributions to the project and that they have the right to submit it under the project's license. It's not yet clear that this can be legally satisfied when submitting significant amount of content that has been generated by AI tools.

Quoted 6 lines

[...]

To avoid these issues, we will reject anything that looks AI generated, that sounds overly formal or bloated, that looks like AI slop, that looks good on the surface but makes no sense, or that senders don’t understand or cannot explain.

Please tell me why this change is a slop and doesn't make sense.

If I wanted to mislead here, I would not have used the "Assisted-by" trailer, which is now being used in kernel land:

https://www.kernel.org/doc/html/latest/process/submitting-patches.html#using-assisted-by

There have already been commits in the git.git history having the Assisted-by trailer.

Quoted 2 lines

I'll note that it also has a lot of global variables, which are common in the codebase but we're trying to move away from,

Is there a new facility to store the config without a global variable?

If the issue is the number, I can make a housing struct if you want.

Quoted 2 lines

and it's more
verbose in commenting than we'd normally see elsewhere in the codebase.

I added comments to explain the code clearly as it's being followed, especially since this is a new feature and I wanted the intent to be clear.

If you could tell me which comments to remove, that would be great.

Thanks,
Siddh

#5 lore raw

Re: [PATCH 1/9] Documentation/git-range-diff: add missing notes options in synopsis

In reply to Junio C Hamano
Quoted 16 lines · Junio C Hamano
Quoted 9 lines · Siddh Raman Pant
Quoted 1 line · Junio C Hamano

This has nothing to do with "external notes" topic, no?

Yeah, but since I added the command line flag I found it doesn't mention the existing flags.

Fixing it in the "external notes" commit would be bad, so I put it before that, since it also then provides a logical place to add new flags.

What I meant was that it would have been better as a standalone patch that is unrelated to the (now) 8-patch topic for the external notes. That way, it can move faster without waiting for the rest.

Quoted 6 lines

Unless this patch has complex semantic or textual conflicts that makes it easier to manage together with the external notes series, that is. I think adding [--notes=...] to one existing line (this patch) and adding a new line with [--[no-]external] on it (the main part of the topic) can be done in parallel and it is not too much to ask for the integrator to merge them on the receiving end.

Ok sure, I'll send it as a standalone patch.

Thanks,
Siddh

#11 lore raw

Re: [PATCH 4/9] run-command: add support for timeout in command finisher

In reply to Siddh Raman Pant

Am 19.05.26 um 18:30 schrieb Siddh Raman Pant:

Quoted 5 lines

A called command may not respond to the initial signal and will get stuck in finish_command() -> wait_or_whine().

So let's add timeout support into the finisher so that if a deadline occurs, we can send a force-kill signal.

This is extremely suspicious. A communication protocl with a child program that requires to kill the child looks like a design error. A band-aid like this timeout should not be necessary for a well-behaved child process.

If the (your?) problem is that the child process is actually not well-behaved, then I suggest to use a middle-man as child process that behaves well from the point of view of the git process, but can punish the ill-behaved downstream process when needed.

Please, do not add this infrastructure to core Git, and instead fix the communication protocol.

Quoted 4 lines

The force-kill signal is in the argument because a program may trap a signal, so it is the responsibility of caller to pass the correct kill signal.

-- Hannes

#12 lore raw

Re: [PATCH 4/9] run-command: add support for timeout in command finisher

Quoted 3 lines · Johannes Sixt

Please, do not add this infrastructure to core Git, and instead fix the communication protocol.

there is nothing to fix here. proper error handling including timeout handling should just be part of every protocol handler, and in the case of child processes, forcible termination is part of that.

one can ignore the issue, in which case termination is left to the user by ctrl-c'ing the whole process group. this isn't very user-friendly, because it doesn't report the problem, and it may leave hung processes behind. it is also extremely bad if keeping the parent process alive is a lot more important than the child process, but this doesn't appear to apply to the particular use case.

adding a proxy doesn't fix the problem, it just adds another point of failure.

#13 lore raw

Re: [PATCH 4/9] run-command: add support for timeout in command finisher

In reply to Johannes Sixt
Quoted 4 lines · Johannes Sixt

This is extremely suspicious. A communication protocl with a child program that requires to kill the child looks like a design error. A band-aid like this timeout should not be necessary for a well-behaved child process.

I do not think this is a protocol design error. The normal protocol does not require killing the helper: git sends one object id, the helper sends one bounded response, and the helper exits when git closes its pipes.

The timeout is for the failure path, where the external helper has already stopped following that protocol or is blocked on something outside git's control. Since git starts the helper and puts it on the log/grep path, git also needs a bounded way to recover when that helper does not make progress. Otherwise an optional note source can prevent the main git command from completing.

Quoted 4 lines

If the (your?) problem is that the child process is actually not well-behaved, then I suggest to use a middle-man as child process that behaves well from the point of view of the git process, but can punish the ill-behaved downstream process when needed.

A middle-man would need the same timeout/termination/reaping logic, and git would still need to handle the middle-man itself hanging / failing. So I don't think it removes the problem, it just makes each user or deployment carry that process-supervision logic outside git.

External notes are additive. If the helper misbehaves, the intended behavior is to warn once, disable that source for the rest of the process, and let git continue without those notes. That seems preferable to leaving git stuck in finish_command().

Thanks,
Siddh

#14 lore raw

Re: [PATCH 4/9] run-command: add support for timeout in command finisher

Am 21.05.26 um 11:59 schrieb Siddh Raman Pant:

Quoted 6 lines

The timeout is for the failure path, where the external helper has already stopped following that protocol or is blocked on something outside git's control. Since git starts the helper and puts it on the log/grep path, git also needs a bounded way to recover when that helper does not make progress. Otherwise an optional note source can prevent the main git command from completing.

That Git communicates with a process that looks like it stopped is the normal case, for example:

- Output is sent to the pager. The user can take their time to study the output. All the while, git waits patiently for the user to advance the pager.

- Git fetch transfers large amounts of data across the network. Most of the time it waits for data to arrive and does nothing. The peer process looks like it hangs. Git does not decide to kill the connection at any time. It is the user's decision to do so.

If the notes provider hangs, then it is not on Git to decide when it has waited long enough.

-- Hannes

#26 lore raw

Re: [PATCH 7/9] notes: support an external command to display notes

In reply to Siddh Raman Pant
Quoted 11 lines · Siddh Raman Pant
Quoted 6 lines · brian m. carlson
Quoted 1 line
Assisted-by Codex:gpt-5.5-xhigh-fast

Just a question here: was this written in whole or in part by Codex, or was it just used as a reference to ask questions? I ask because the style of notes-external.c differs quite a bit from the style we use (for one, the horizontal rule comments) and we have this in

AI tools typically don't generate comments in code like in this series, you can see by trying out for yourself. Each comment is hand-written by me. Sorry, I'll remove those lines in v2 after this discussion.

I've actually seen AI tools do things very similar to what you've written.

Quoted 8 lines
Quoted 8 lines

SubmittingPatches:

The Developer's Certificate of Origin requires contributors to certify that they know the origin of their contributions to the project and that they have the right to submit it under the project's license. It's not yet clear that this can be legally satisfied when submitting significant amount of content that has been generated by AI tools.

Quoted 8 lines
Quoted 6 lines

[...]

To avoid these issues, we will reject anything that looks AI generated, that sounds overly formal or bloated, that looks like AI slop, that looks good on the surface but makes no sense, or that senders don’t understand or cannot explain.

Please tell me why this change is a slop and doesn't make sense.

I didn't say this was slop and didn't make sense. I quoted the portion that says that we don't accept anything AI generated, including for license reasons. There's still very little clarity about whether AI code is a derivative work of the training set or whether it can be copyrightable at all, very especially on a worldwide basis. We don't want to end up with a legal or license problem that the DCO was intended to solve.

Quoted 4 lines

If I wanted to mislead here, I would not have used the "Assisted-by" trailer, which is now being used in kernel land:

https://www.kernel.org/doc/html/latest/process/submitting-patches.html#using-assisted-by

The kernel and Git do different things. Linux generally allows AI and we generally restrict its use quite heavily. Linux tries to never break dependent projects and we don't have that policy.

I appreciate the header being included and agree that it should be, but it's important we ask questions about the provenance of the code when AI is used because many people do not read SubmittingPatches (or contributing documentation in general).

Quoted 6 lines
Quoted 2 lines

I'll note that it also has a lot of global variables, which are common in the codebase but we're trying to move away from,

Is there a new facility to store the config without a global variable?

If the issue is the number, I can make a housing struct if you want.

We'd typically use repo_config_get_string or such to fetch the configuration these days. If you don't want to fetch it multiple times, we'd generally read all the config and put it in a struct that we'd initialize with a function at a suitable time.

There's effort to avoid the global variables because they don't work well in libraries and we want to allow libgit.a to be used more generally. In addition, Rust considers static mutable variables to be unsafe, so as we add more Rust, we'll need to minimize the use of any globals.

Quoted 5 lines

I added comments to explain the code clearly as it's being followed, especially since this is a new feature and I wanted the intent to be clear.

If you could tell me which comments to remove, that would be great.

I don't think it's necessarily a problem to have the comments, but it is uncommon in our codebase, which is what drew my attention.

Signature · 2 lines
brian m. carlson (they/them)
Toronto, Ontario, CA
#15 lore raw

Re: [PATCH 4/9] run-command: add support for timeout in command finisher

In reply to Johannes Sixt
Quoted 15 lines · Johannes Sixt

Am 21.05.26 um 11:59 schrieb Siddh Raman Pant:

Quoted 6 lines

The timeout is for the failure path, where the external helper has already stopped following that protocol or is blocked on something outside git's control. Since git starts the helper and puts it on the log/grep path, git also needs a bounded way to recover when that helper does not make progress. Otherwise an optional note source can prevent the main git command from completing.

That Git communicates with a process that looks like it stopped is the normal case, for example:

- Output is sent to the pager. The user can take their time to study the output. All the while, git waits patiently for the user to advance the pager.

Quoted 7 lines

- Git fetch transfers large amounts of data across the network. Most of the time it waits for data to arrive and does nothing. The peer process looks like it hangs. Git does not decide to kill the connection at any time. It is the user's decision to do so.

If the notes provider hangs, then it is not on Git to decide when it has waited long enough.

It is often the sticking sore point that there is no good timeout value that suites for everybody.

If a protocol builds its own way to declare "this backend is slow, so please do not consider less than 3 seconds of nonaction something to worry about but kill it off if you waited more than that" to make the receiving/waiting end responsible for managing timeout, that might be workable, but it certainly feels like a kludge. The protocol can instead allow an "error - for your particular request, we couldn't come up with an answer within a reasonable time limit" response (in practice, "within time limit" does not have to be the only reason for such an error) to be returned, I think.

#17 lore raw

Re: [PATCH 4/9] run-command: add support for timeout in command finisher

In reply to Johannes Sixt
Quoted 15 lines · Johannes Sixt

Am 21.05.26 um 11:59 schrieb Siddh Raman Pant:

Quoted 6 lines

The timeout is for the failure path, where the external helper has already stopped following that protocol or is blocked on something outside git's control. Since git starts the helper and puts it on the log/grep path, git also needs a bounded way to recover when that helper does not make progress. Otherwise an optional note source can prevent the main git command from completing.

That Git communicates with a process that looks like it stopped is the normal case, for example:

- Output is sent to the pager. The user can take their time to study the output. All the while, git waits patiently for the user to advance the pager.

Quoted 7 lines

- Git fetch transfers large amounts of data across the network. Most of the time it waits for data to arrive and does nothing. The peer process looks like it hangs. Git does not decide to kill the connection at any time. It is the user's decision to do so.

If the notes provider hangs, then it is not on Git to decide when it has waited long enough.

Yeah, I agree with your point of view. If I understand this patch series correctly, it is about adding an external process to map commit ids to note data. So I can think of some existing features that are quite close to that in nature, none of which use timeouts:

- textconv filters and external diffs which process data in the middle of a git-log invocation

- long-lived clean/smudge filters map blobs to arbitrarily large text

- cat-file's batch mode maps object ids to user-specified data about that object

As you note, it's up to the command to be well-behaved. Git should notice and respond appropriately if the command closes the pipe, of course. Sometimes a timeout can help with a poorly behaved command, but IMHO it is not worth the cost of non-determinism that it brings.

Moreover, the bits touching run-command here make me nervous, especially after the challenges we saw in the child-cleanup topic that was reverted just after v2.54. There is often a shell interposed between Git and the sub-command, and we don't always know how the shell will react to signals. Using SIGKILL will eventually get us _something_ to wait() on, but it might not even be the process we care about!

I don't really care much about this external-notes feature one way or the other, but if we are going to do it, I don't see any reason why it would not behave like all of the other similar parts of Git.

-Peff

#16 lore raw

Re: [PATCH 4/9] run-command: add support for timeout in command finisher

In reply to Junio C Hamano
Quoted 9 lines · Junio C Hamano

If a protocol builds its own way to declare "this backend is slow, so please do not consider less than 3 seconds of nonaction something to worry about but kill it off if you waited more than that" to make the receiving/waiting end responsible for managing timeout, that might be workable, but it certainly feels like a kludge. The protocol can instead allow an "error - for your particular request, we couldn't come up with an answer within a reasonable time limit" response (in practice, "within time limit" does not have to be the only reason for such an error) to be returned, I think.

I think we are confusing two different commits here.

The response read deadline is the next commit. This commit is about force-killing a process if it doesn't respond to the initial termination signal.

Thanks,
Siddh

#18 lore raw

Re: [PATCH 4/9] run-command: add support for timeout in command finisher

In reply to Jeff King
Quoted 50 lines · Jeff King
Quoted 15 lines · Johannes Sixt

Am 21.05.26 um 11:59 schrieb Siddh Raman Pant:

Quoted 6 lines

The timeout is for the failure path, where the external helper has already stopped following that protocol or is blocked on something outside git's control. Since git starts the helper and puts it on the log/grep path, git also needs a bounded way to recover when that helper does not make progress. Otherwise an optional note source can prevent the main git command from completing.

That Git communicates with a process that looks like it stopped is the normal case, for example:

- Output is sent to the pager. The user can take their time to study the output. All the while, git waits patiently for the user to advance the pager.

Quoted 7 lines

- Git fetch transfers large amounts of data across the network. Most of the time it waits for data to arrive and does nothing. The peer process looks like it hangs. Git does not decide to kill the connection at any time. It is the user's decision to do so.

If the notes provider hangs, then it is not on Git to decide when it has waited long enough.

Yeah, I agree with your point of view. If I understand this patch series correctly, it is about adding an external process to map commit ids to note data. So I can think of some existing features that are quite close to that in nature, none of which use timeouts:

- textconv filters and external diffs which process data in the middle of a git-log invocation

- long-lived clean/smudge filters map blobs to arbitrarily large text

- cat-file's batch mode maps object ids to user-specified data about that object

As you note, it's up to the command to be well-behaved. Git should notice and respond appropriately if the command closes the pipe, of course. Sometimes a timeout can help with a poorly behaved command, but IMHO it is not worth the cost of non-determinism that it brings.

Moreover, the bits touching run-command here make me nervous, especially after the challenges we saw in the child-cleanup topic that was reverted just after v2.54. There is often a shell interposed between Git and the sub-command, and we don't always know how the shell will react to signals. Using SIGKILL will eventually get us _something_ to wait() on, but it might not even be the process we care about!

Quoted 5 lines

I don't really care much about this external-notes feature one way or the other, but if we are going to do it, I don't see any reason why it would not behave like all of the other similar parts of Git.

-Peff

Okay, since the consensus here is pretty clear, I will remove this commit and send a v2.

Thanks,
Siddh