diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/fileops.c | 9 | ||||
-rw-r--r-- | src/fileops.h | 5 | ||||
-rw-r--r-- | src/odb_loose.c | 2 | ||||
-rw-r--r-- | src/odb_pack.c | 15 | ||||
-rw-r--r-- | src/pack.h | 2 |
5 files changed, 23 insertions, 10 deletions
diff --git a/src/fileops.c b/src/fileops.c index ce64934ea..fcc0301f9 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -837,16 +837,13 @@ int git_futils_cp(const char *from, const char *to, mode_t filemode) return cp_by_fd(ifd, ofd, true); } -int git_futils_touch(const char *path) +int git_futils_touch(const char *path, time_t *when) { struct p_timeval times[2]; - time_t now = time(NULL); int ret; - times[0].tv_sec = now; - times[0].tv_usec = 0; - times[1].tv_sec = now; - times[1].tv_usec = 0; + times[0].tv_sec = times[1].tv_sec = when ? *when : time(NULL); + times[0].tv_usec = times[1].tv_usec = 0; ret = p_utimes(path, times); diff --git a/src/fileops.h b/src/fileops.h index e055400be..54e3bd4e4 100644 --- a/src/fileops.h +++ b/src/fileops.h @@ -185,9 +185,10 @@ extern int git_futils_cp( mode_t filemode); /** - * Set the files atime and mtime to the current time. + * Set the files atime and mtime to the given time, or the current time + * if `ts` is NULL. */ -extern int git_futils_touch(const char *path); +extern int git_futils_touch(const char *path, time_t *when); /** * Flags that can be passed to `git_futils_cp_r`. diff --git a/src/odb_loose.c b/src/odb_loose.c index 1653e2783..f312b9c9c 100644 --- a/src/odb_loose.c +++ b/src/odb_loose.c @@ -929,7 +929,7 @@ static int loose_backend__freshen( if (object_file_name(&path, backend, oid) < 0) return -1; - error = git_futils_touch(path.ptr); + error = git_futils_touch(path.ptr, NULL); git_buf_free(&path); return error; diff --git a/src/odb_pack.c b/src/odb_pack.c index 3b52b6be6..b80d0337a 100644 --- a/src/odb_pack.c +++ b/src/odb_pack.c @@ -20,6 +20,9 @@ #include "git2/odb_backend.h" +/* re-freshen pack files no more than every 2 seconds */ +#define FRESHEN_FREQUENCY 2 + struct pack_backend { git_odb_backend parent; git_vector packs; @@ -367,12 +370,22 @@ static int pack_backend__freshen( git_odb_backend *backend, const git_oid *oid) { struct git_pack_entry e; + time_t now; int error; if ((error = pack_entry_find(&e, (struct pack_backend *)backend, oid)) < 0) return error; - return git_futils_touch(e.p->pack_name); + now = time(NULL); + + if (e.p->last_freshen > now - FRESHEN_FREQUENCY) + return 0; + + if ((error = git_futils_touch(e.p->pack_name, &now)) < 0) + return error; + + e.p->last_freshen = now; + return 0; } static int pack_backend__read( diff --git a/src/pack.h b/src/pack.h index d15247b74..5302db5b7 100644 --- a/src/pack.h +++ b/src/pack.h @@ -102,6 +102,8 @@ struct git_pack_file { git_pack_cache bases; /* delta base cache */ + time_t last_freshen; /* last time the packfile was freshened */ + /* something like ".git/objects/pack/xxxxx.pack" */ char pack_name[GIT_FLEX_ARRAY]; /* more */ }; |