@matheusbsbs / matheus-bagliano / commits / fc04c412d8
Fork 0

Teach receive-pack how to keep pack files based on object count.

Since keeping a pushed pack or exploding it into loose objects should be a local repository decision this teaches receive-pack to decide if it should call unpack-objects or index-pack --stdin --fix-thin based on the setting of receive.unpackLimit and the number of objects contained in the received pack. If the number of objects (hdr_entries) in the received pack is below the value of receive.unpackLimit (which is 5000 by default) then we unpack-objects as we have in the past. If the hdr_entries >= receive.unpackLimit then we call index-pack and ask it to include our pid and hostname in the .keep file to make it easier to identify why a given pack has been kept in the repository. Currently this leaves every received pack as a kept pack. We really don't want that as received packs will tend to be small. Instead we want to delete the .keep file automatically after all refs have been updated. That is being left as room for future improvement. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Shawn Pearce committed Nov 1, 2006 at 17:06 UTC fc04c412d8d2412e97bb2a664a1746e333dfd9ae
4 files changed +91 -21
Documentation/config.txt
+10 -1
@@ -301,7 +301,16 @@ imap::
301 The configuration variables in the 'imap' section are described
302 in gitlink:git-imap-send[1].
303
304 -receive.denyNonFastforwads::
304 +receive.unpackLimit::
305 + If the number of objects received in a push is below this
306 + limit then the objects will be unpacked into loose object
307 + files. However if the number of received objects equals or
308 + exceeds this limit then the received pack will be stored as
309 + a pack, after adding any missing delta bases. Storing the
310 + pack from a push can make the push operation complete faster,
311 + especially on slow filesystems.
312 +
313 +receive.denyNonFastForwards::
314 If set to true, git-receive-pack will deny a ref update which is
315 not a fast forward. Use this to prevent such an update via a push,
316 even if that push is forced. This configuration variable is
cache.h
+1
@@ -376,6 +376,7 @@ extern struct packed_git *parse_pack_index_file(const unsigned char *sha1,
376 char *idx_path);
377
378 extern void prepare_packed_git(void);
379 +extern void reprepare_packed_git(void);
380 extern void install_packed_git(struct packed_git *pack);
381
382 extern struct packed_git *find_sha1_pack(const unsigned char *sha1,
receive-pack.c
+79 -19
@@ -1,4 +1,5 @@
1 #include "cache.h"
2 +#include "pack.h"
3 #include "refs.h"
4 #include "pkt-line.h"
5 #include "run-command.h"
@@ -7,9 +8,8 @@
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,6 +25,12 @@ static int receive_pack_config(const char *var, const char *value)
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
@@ -227,27 +233,81 @@ static void read_head_info(void)
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
sha1_file.c
+1 -1
@@ -663,7 +663,7 @@ void prepare_packed_git(void)
663 prepare_packed_git_run_once = 1;
664 }
665
666 -static void reprepare_packed_git(void)
666 +void reprepare_packed_git(void)
667 {
668 prepare_packed_git_run_once = 0;
669 prepare_packed_git();