Skip to content

Commit 5f8a0de

Browse files
committed
Merge branch 'sp/push-sideband'
* sp/push-sideband: receive-pack: Send internal errors over side-band #2 t5401: Use a bare repository for the remote peer receive-pack: Send hook output over side band #2 receive-pack: Wrap status reports inside side-band-64k receive-pack: Refactor how capabilities are shown to the client send-pack: demultiplex a sideband stream with status data run-command: support custom fd-set in async run-command: Allow stderr to be a caller supplied pipe
2 parents 25666af + cc8eb64 commit 5f8a0de

File tree

10 files changed

+370
-134
lines changed

10 files changed

+370
-134
lines changed

Documentation/technical/api-run-command.txt

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ The functions above do the following:
6464
`start_async`::
6565

6666
Run a function asynchronously. Takes a pointer to a `struct
67-
async` that specifies the details and returns a pipe FD
68-
from which the caller reads. See below for details.
67+
async` that specifies the details and returns a set of pipe FDs
68+
for communication with the function. See below for details.
6969

7070
`finish_async`::
7171

@@ -135,7 +135,7 @@ stderr as follows:
135135

136136
.in: The FD must be readable; it becomes child's stdin.
137137
.out: The FD must be writable; it becomes child's stdout.
138-
.err > 0 is not supported.
138+
.err: The FD must be writable; it becomes child's stderr.
139139

140140
The specified FD is closed by start_command(), even if it fails to
141141
run the sub-process!
@@ -180,17 +180,47 @@ The caller:
180180
struct async variable;
181181
2. initializes .proc and .data;
182182
3. calls start_async();
183-
4. processes the data by reading from the fd in .out;
184-
5. closes .out;
183+
4. processes communicates with proc through .in and .out;
184+
5. closes .in and .out;
185185
6. calls finish_async().
186186

187+
The members .in, .out are used to provide a set of fd's for
188+
communication between the caller and the callee as follows:
189+
190+
. Specify 0 to have no file descriptor passed. The callee will
191+
receive -1 in the corresponding argument.
192+
193+
. Specify < 0 to have a pipe allocated; start_async() replaces
194+
with the pipe FD in the following way:
195+
196+
.in: Returns the writable pipe end into which the caller
197+
writes; the readable end of the pipe becomes the function's
198+
in argument.
199+
200+
.out: Returns the readable pipe end from which the caller
201+
reads; the writable end of the pipe becomes the function's
202+
out argument.
203+
204+
The caller of start_async() must close the returned FDs after it
205+
has completed reading from/writing from them.
206+
207+
. Specify a file descriptor > 0 to be used by the function:
208+
209+
.in: The FD must be readable; it becomes the function's in.
210+
.out: The FD must be writable; it becomes the function's out.
211+
212+
The specified FD is closed by start_async(), even if it fails to
213+
run the function.
214+
187215
The function pointer in .proc has the following signature:
188216

189-
int proc(int fd, void *data);
217+
int proc(int in, int out, void *data);
190218

191-
. fd specifies a writable file descriptor to which the function must
192-
write the data that it produces. The function *must* close this
193-
descriptor before it returns.
219+
. in, out specifies a set of file descriptors to which the function
220+
must read/write the data that it needs/produces. The function
221+
*must* close these descriptors before it returns. A descriptor
222+
may be -1 if the caller did not configure a descriptor for that
223+
direction.
194224

195225
. data is the value that the caller has specified in the .data member
196226
of struct async.
@@ -205,8 +235,8 @@ because this facility is implemented by a pipe to a forked process on
205235
UNIX, but by a thread in the same address space on Windows:
206236

207237
. It cannot change the program's state (global variables, environment,
208-
etc.) in a way that the caller notices; in other words, .out is the
209-
only communication channel to the caller.
238+
etc.) in a way that the caller notices; in other words, .in and .out
239+
are the only communication channels to the caller.
210240

211241
. It must not change the program's state that the caller of the
212242
facility also uses.

builtin-fetch-pack.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,12 +586,12 @@ static int everything_local(struct ref **refs, int nr_match, char **match)
586586
return retval;
587587
}
588588

589-
static int sideband_demux(int fd, void *data)
589+
static int sideband_demux(int in, int out, void *data)
590590
{
591591
int *xd = data;
592592

593-
int ret = recv_sideband("fetch-pack", xd[0], fd);
594-
close(fd);
593+
int ret = recv_sideband("fetch-pack", xd[0], out);
594+
close(out);
595595
return ret;
596596
}
597597

@@ -613,6 +613,7 @@ static int get_pack(int xd[2], char **pack_lockfile)
613613
*/
614614
demux.proc = sideband_demux;
615615
demux.data = xd;
616+
demux.out = -1;
616617
if (start_async(&demux))
617618
die("fetch-pack: unable to fork off sideband"
618619
" demultiplexer");

0 commit comments

Comments
 (0)