check_connected: relay errors to alternate descriptor
Unless the "quiet" flag is given, check_connected sends any errors to the stderr of the caller (because the child rev-list inherits that descriptor). However, server-side callers may want to send these over a sideband channel instead. Let's make that possible. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jul 15, 2016 at 06:32 UTC
e0331849a081fe4919f4130540165ce7d7355748
2 files changed
+16
-2
connected.c
+9
-2
@@ -31,8 +31,11 @@ int check_connected(sha1_iterate_fn fn, void *cb_data,
31
opt = &defaults;
32
transport = opt->transport;
33
34
- if (fn(cb_data, sha1))
34
+ if (fn(cb_data, sha1)) {
35
+ if (opt->err_fd)
36
+ close(opt->err_fd);
37
return err;
38
+ }
39
40
if (transport && transport->smart_options &&
41
transport->smart_options->self_contained_and_connected &&
@@ -59,7 +62,11 @@ int check_connected(sha1_iterate_fn fn, void *cb_data,
62
rev_list.git_cmd = 1;
63
rev_list.in = -1;
64
rev_list.no_stdout = 1;
62
- rev_list.no_stderr = opt->quiet;
65
+ if (opt->err_fd)
66
+ rev_list.err = opt->err_fd;
67
+ else
68
+ rev_list.no_stderr = opt->quiet;
69
+
70
if (start_command(&rev_list))
71
return error(_("Could not run 'git rev-list'"));
72
connected.h
+7
@@ -23,6 +23,13 @@ struct check_connected_options {
23
24
/* Transport whose objects we are checking, if available. */
25
struct transport *transport;
26
+
27
+ /*
28
+ * If non-zero, send error messages to this descriptor rather
29
+ * than stderr. The descriptor is closed before check_connected
30
+ * returns.
31
+ */
32
+ int err_fd;
33
};
34
35
#define CHECK_CONNECTED_INIT { 0 }