upload-pack: prepare for sideband message support.
This does not implement sideband for propagating the status to the downloader yet, but add code to capture the standard error output from the pack-objects process in preparation for sending it off to the client when the protocol extension allows us to do so. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jun 20, 2006 at 22:48 UTC
363b7817e017b7c7e27a925d766c4d9bacfe4471
2 files changed
+43
-7
pack-objects.c
+4
@@ -1221,6 +1221,10 @@ int main(int argc, char **argv)
1221
local = 1;
1222
continue;
1223
}
1224
+ if (!strcmp("--progress", arg)) {
1225
+ progress = 1;
1226
+ continue;
1227
+ }
1228
if (!strcmp("--incremental", arg)) {
1229
incremental = 1;
1230
continue;
upload-pack.c
+39
-7
@@ -36,11 +36,13 @@ static int strip(char *line, int len)
36
37
static void create_pack_file(void)
38
{
39
- /* Pipes between rev-list to pack-objects and pack-objects to us. */
40
- int lp_pipe[2], pu_pipe[2];
39
+ /* Pipes between rev-list to pack-objects, pack-objects to us
40
+ * and pack-objects error stream for progress bar.
41
+ */
42
+ int lp_pipe[2], pu_pipe[2], pe_pipe[2];
43
pid_t pid_rev_list, pid_pack_objects;
44
int create_full_pack = (nr_our_refs == nr_needs && !nr_has);
43
- char data[8193];
45
+ char data[8193], progress[128];
46
int buffered = -1;
47
48
if (pipe(lp_pipe) < 0)
@@ -95,6 +97,8 @@ static void create_pack_file(void)
97
98
if (pipe(pu_pipe) < 0)
99
die("git-upload-pack: unable to create pipe");
100
+ if (pipe(pe_pipe) < 0)
101
+ die("git-upload-pack: unable to create pipe");
102
pid_pack_objects = fork();
103
if (pid_pack_objects < 0) {
104
/* daemon sets things up to ignore TERM */
@@ -104,12 +108,15 @@ static void create_pack_file(void)
108
if (!pid_pack_objects) {
109
dup2(lp_pipe[0], 0);
110
dup2(pu_pipe[1], 1);
111
+ dup2(pe_pipe[1], 2);
112
113
close(lp_pipe[0]);
114
close(lp_pipe[1]);
115
close(pu_pipe[0]);
116
close(pu_pipe[1]);
112
- execl_git_cmd("pack-objects", "--stdout", NULL);
117
+ close(pe_pipe[0]);
118
+ close(pe_pipe[1]);
119
+ execl_git_cmd("pack-objects", "--stdout", "--progress", NULL);
120
kill(pid_rev_list, SIGKILL);
121
die("git-upload-pack: unable to exec git-pack-objects");
122
}
@@ -117,20 +124,23 @@ static void create_pack_file(void)
124
close(lp_pipe[0]);
125
close(lp_pipe[1]);
126
120
- /* We read from pu_pipe[0] to capture the pack data.
127
+ /* We read from pe_pipe[0] to capture stderr output for
128
+ * progress bar, and pu_pipe[0] to capture the pack data.
129
*/
130
+ close(pe_pipe[1]);
131
close(pu_pipe[1]);
132
133
while (1) {
134
const char *who;
135
+ char *cp;
136
struct pollfd pfd[2];
137
pid_t pid;
138
int status;
139
ssize_t sz;
130
- int pu, pollsize;
140
+ int pe, pu, pollsize;
141
142
pollsize = 0;
133
- pu = -1;
143
+ pe = pu = -1;
144
145
if (0 <= pu_pipe[0]) {
146
pfd[pollsize].fd = pu_pipe[0];
@@ -138,6 +148,12 @@ static void create_pack_file(void)
148
pu = pollsize;
149
pollsize++;
150
}
151
+ if (0 <= pe_pipe[0]) {
152
+ pfd[pollsize].fd = pe_pipe[0];
153
+ pfd[pollsize].events = POLLIN;
154
+ pe = pollsize;
155
+ pollsize++;
156
+ }
157
158
if (pollsize) {
159
if (poll(pfd, pollsize, -1) < 0) {
@@ -187,6 +203,22 @@ static void create_pack_file(void)
203
if (sz < 0)
204
goto fail;
205
}
206
+ if (0 <= pe && (pfd[pe].revents & (POLLIN|POLLHUP))) {
207
+ /* Status ready; we do not use it for now,
208
+ * but later we will add side-band to send it
209
+ * to the other side.
210
+ */
211
+ sz = read(pe_pipe[0], progress,
212
+ sizeof(progress));
213
+ if (0 < sz)
214
+ write(2, progress, sz);
215
+ else if (sz == 0) {
216
+ close(pe_pipe[0]);
217
+ pe_pipe[0] = -1;
218
+ }
219
+ else
220
+ goto fail;
221
+ }
222
}
223
224
/* See if the children are still there */