summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b75aaa5)
raw | patch | inline | side by side (parent: b75aaa5)
author | Nicolas Pitre <nico@cam.org> | |
Thu, 13 Mar 2008 18:59:29 +0000 (14:59 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Fri, 14 Mar 2008 05:51:30 +0000 (22:51 -0700) |
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>
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>
builtin-pack-objects.c | patch | blob | history | |
git-compat-util.h | patch | blob | history |
diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index f504cff7566159332c89f830a871da0ea05868fe..777f272668c39931b330be555f41399adfbce397 100644 (file)
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
struct pack_header hdr;
int do_progress = progress >> pack_to_stdout;
uint32_t nr_remaining = nr_result;
+ time_t last_mtime = 0;
if (do_progress)
progress_state = start_progress("Writing objects", nr_result);
if (!pack_to_stdout) {
mode_t mode = umask(0);
+ struct stat st;
char *idx_tmp_name, tmpname[PATH_MAX];
umask(mode);
idx_tmp_name = write_idx_file(NULL, written_list,
nr_written, sha1);
+
snprintf(tmpname, sizeof(tmpname), "%s-%s.pack",
base_name, sha1_to_hex(sha1));
if (adjust_perm(pack_tmp_name, mode))
if (rename(pack_tmp_name, tmpname))
die("unable to rename temporary pack file: %s",
strerror(errno));
+
+ /*
+ * Packs are runtime accessed in their mtime
+ * order since newer packs are more likely to contain
+ * younger objects. So if we are creating multiple
+ * packs then we should modify the mtime of later ones
+ * to preserve this property.
+ */
+ if (stat(tmpname, &st) < 0) {
+ warning("failed to stat %s: %s",
+ tmpname, strerror(errno));
+ } else if (!last_mtime) {
+ last_mtime = st.st_mtime;
+ } else {
+ struct utimbuf utb;
+ utb.actime = st.st_atime;
+ utb.modtime = --last_mtime;
+ if (utime(tmpname, &utb) < 0)
+ warning("failed utime() on %s: %s",
+ tmpname, strerror(errno));
+ }
+
snprintf(tmpname, sizeof(tmpname), "%s-%s.idx",
base_name, sha1_to_hex(sha1));
if (adjust_perm(idx_tmp_name, mode))
if (rename(idx_tmp_name, tmpname))
die("unable to rename temporary index file: %s",
strerror(errno));
+
free(idx_tmp_name);
free(pack_tmp_name);
puts(sha1_to_hex(sha1));
diff --git a/git-compat-util.h b/git-compat-util.h
index 73968e02b024f22068eb5500033f7a2f41d31e8f..a18235e6d053322a85805d1b07b631c6739deb93 100644 (file)
--- a/git-compat-util.h
+++ b/git-compat-util.h
#include <sys/poll.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
+#include <utime.h>
#ifndef NO_SYS_SELECT_H
#include <sys/select.h>
#endif