1
#include "cache.h"
2
+#include "pack.h"
3
#include "refs.h"
4
#include "pkt-line.h"
5
#include "run-command.h"
8
9
static const char receive_pack_usage[] = "git-receive-pack <git-dir>";
10
10
-static const char *unpacker[] = { "unpack-objects", NULL };
11
-
11
static int deny_non_fast_forwards = 0;
12
+static int unpack_limit = 5000;
13
static int report_status;
14
15
static char capabilities[] = "report-status";
25
return 0;
26
}
27
28
+ if (strcmp(var, "receive.unpacklimit") == 0)
29
+ {
30
+ unpack_limit = git_config_int(var, value);
31
+ return 0;
32
+ }
33
+
34
return 0;
35
}
36
233
}
234
}
235
236
+static const char *parse_pack_header(struct pack_header *hdr)
237
+{
238
+ char *c = (char*)hdr;
239
+ ssize_t remaining = sizeof(struct pack_header);
240
+ do {
241
+ ssize_t r = xread(0, c, remaining);
242
+ if (r <= 0)
243
+ return "eof before pack header was fully read";
244
+ remaining -= r;
245
+ c += r;
246
+ } while (remaining > 0);
247
+ if (hdr->hdr_signature != htonl(PACK_SIGNATURE))
248
+ return "protocol error (pack signature mismatch detected)";
249
+ if (!pack_version_ok(hdr->hdr_version))
250
+ return "protocol error (pack version unsupported)";
251
+ return NULL;
252
+}
253
+
254
static const char *unpack(void)
255
{
232
- int code = run_command_v_opt(1, unpacker, RUN_GIT_CMD);
256
+ struct pack_header hdr;
257
+ const char *hdr_err;
258
+ char hdr_arg[38];
259
+ int code;
260
+
261
+ hdr_err = parse_pack_header(&hdr);
262
+ if (hdr_err)
263
+ return hdr_err;
264
+ snprintf(hdr_arg, sizeof(hdr_arg), "--pack_header=%u,%u",
265
+ ntohl(hdr.hdr_version), ntohl(hdr.hdr_entries));
266
+
267
+ if (ntohl(hdr.hdr_entries) < unpack_limit) {
268
+ const char *unpacker[3];
269
+ unpacker[0] = "unpack-objects";
270
+ unpacker[1] = hdr_arg;
271
+ unpacker[2] = NULL;
272
+ code = run_command_v_opt(1, unpacker, RUN_GIT_CMD);
273
+ } else {
274
+ const char *keeper[6];
275
+ char my_host[255], keep_arg[128 + 255];
276
+
277
+ if (gethostname(my_host, sizeof(my_host)))
278
+ strcpy(my_host, "localhost");
279
+ snprintf(keep_arg, sizeof(keep_arg),
280
+ "--keep=receive-pack %i on %s",
281
+ getpid(), my_host);
282
+
283
+ keeper[0] = "index-pack";
284
+ keeper[1] = "--stdin";
285
+ keeper[2] = "--fix-thin";
286
+ keeper[3] = hdr_arg;
287
+ keeper[4] = keep_arg;
288
+ keeper[5] = NULL;
289
+ code = run_command_v_opt(1, keeper, RUN_GIT_CMD);
290
+ if (!code)
291
+ reprepare_packed_git();
292
+ }
293
294
switch (code) {
235
- case 0:
236
- return NULL;
237
- case -ERR_RUN_COMMAND_FORK:
238
- return "unpack fork failed";
239
- case -ERR_RUN_COMMAND_EXEC:
240
- return "unpack execute failed";
241
- case -ERR_RUN_COMMAND_WAITPID:
242
- return "waitpid failed";
243
- case -ERR_RUN_COMMAND_WAITPID_WRONG_PID:
244
- return "waitpid is confused";
245
- case -ERR_RUN_COMMAND_WAITPID_SIGNAL:
246
- return "unpacker died of signal";
247
- case -ERR_RUN_COMMAND_WAITPID_NOEXIT:
248
- return "unpacker died strangely";
249
- default:
250
- return "unpacker exited with error code";
295
+ case 0:
296
+ return NULL;
297
+ case -ERR_RUN_COMMAND_FORK:
298
+ return "unpack fork failed";
299
+ case -ERR_RUN_COMMAND_EXEC:
300
+ return "unpack execute failed";
301
+ case -ERR_RUN_COMMAND_WAITPID:
302
+ return "waitpid failed";
303
+ case -ERR_RUN_COMMAND_WAITPID_WRONG_PID:
304
+ return "waitpid is confused";
305
+ case -ERR_RUN_COMMAND_WAITPID_SIGNAL:
306
+ return "unpacker died of signal";
307
+ case -ERR_RUN_COMMAND_WAITPID_NOEXIT:
308
+ return "unpacker died strangely";
309
+ default:
310
+ return "unpacker exited with error code";
311
}
312
}
313