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

pack-objects: proper pack time stamping with --max-pack-size

Runtime pack access is done in the pack file mtime order since recent packs are more likely to contain frequently used objects than old packs. However the --max-pack-size option can produce multiple packs with mtime in the reversed order as newer objects are always written first. Let's modify mtime of later pack files (when any) so they appear older than preceding ones when a repack creates multiple packs. Signed-off-by: Nicolas Pitre <nico@cam.org>

Nicolas Pitre committed Mar 13, 2008 at 14:59 UTC f746bae84e4746a861d9ebed29fd9255e5cd929f
2 files changed +27
builtin-pack-objects.c
+26
@@ -454,6 +454,7 @@ static void write_pack_file(void)
454 struct pack_header hdr;
455 int do_progress = progress >> pack_to_stdout;
456 uint32_t nr_remaining = nr_result;
457 + time_t last_mtime = 0;
458
459 if (do_progress)
460 progress_state = start_progress("Writing objects", nr_result);
@@ -504,6 +505,7 @@ static void write_pack_file(void)
505
506 if (!pack_to_stdout) {
507 mode_t mode = umask(0);
508 + struct stat st;
509 char *idx_tmp_name, tmpname[PATH_MAX];
510
511 umask(mode);
@@ -511,6 +513,7 @@ static void write_pack_file(void)
513
514 idx_tmp_name = write_idx_file(NULL, written_list,
515 nr_written, sha1);
516 +
517 snprintf(tmpname, sizeof(tmpname), "%s-%s.pack",
518 base_name, sha1_to_hex(sha1));
519 if (adjust_perm(pack_tmp_name, mode))
@@ -519,6 +522,28 @@ static void write_pack_file(void)
522 if (rename(pack_tmp_name, tmpname))
523 die("unable to rename temporary pack file: %s",
524 strerror(errno));
525 +
526 + /*
527 + * Packs are runtime accessed in their mtime
528 + * order since newer packs are more likely to contain
529 + * younger objects. So if we are creating multiple
530 + * packs then we should modify the mtime of later ones
531 + * to preserve this property.
532 + */
533 + if (stat(tmpname, &st) < 0) {
534 + warning("failed to stat %s: %s",
535 + tmpname, strerror(errno));
536 + } else if (!last_mtime) {
537 + last_mtime = st.st_mtime;
538 + } else {
539 + struct utimbuf utb;
540 + utb.actime = st.st_atime;
541 + utb.modtime = --last_mtime;
542 + if (utime(tmpname, &utb) < 0)
543 + warning("failed utime() on %s: %s",
544 + tmpname, strerror(errno));
545 + }
546 +
547 snprintf(tmpname, sizeof(tmpname), "%s-%s.idx",
548 base_name, sha1_to_hex(sha1));
549 if (adjust_perm(idx_tmp_name, mode))
@@ -527,6 +552,7 @@ static void write_pack_file(void)
552 if (rename(idx_tmp_name, tmpname))
553 die("unable to rename temporary index file: %s",
554 strerror(errno));
555 +
556 free(idx_tmp_name);
557 free(pack_tmp_name);
558 puts(sha1_to_hex(sha1));
git-compat-util.h
+1
@@ -68,6 +68,7 @@
68 #include <sys/poll.h>
69 #include <sys/socket.h>
70 #include <sys/ioctl.h>
71 +#include <utime.h>
72 #ifndef NO_SYS_SELECT_H
73 #include <sys/select.h>
74 #endif