Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-10-30 23:10:36 +0400
committerRussell Belfer <rb@github.com>2012-10-30 23:11:23 +0400
commit744cc03e2b6d77712bfcb504c272d2e646da650c (patch)
tree6dd5c8cf23e02cf4a5b96800e19dc9749d08cc75 /src/filebuf.c
parentefde422553e1181933d0bc9d7112740e858a847b (diff)
Add git_config_refresh() API to reload config
This adds a new API that allows users to reload the config if the file has changed on disk. A new config callback function to refresh the config was added. The modified time and file size are used to test if the file needs to be reloaded (and are now stored in the disk backend object). In writing tests, just using mtime was a problem / race, so I wanted to check file size as well. To support that, I extended `git_futils_readbuffer_updated` to optionally check file size in addition to mtime, and I added a new function `git_filebuf_stats` to fetch the mtime and size for an open filebuf (so that the config could be easily refreshed after a write). Lastly, I moved some similar file checking code for attributes into filebuf. It is still only being used for attrs, but it seems potentially reusable, so I thought I'd move it over.
Diffstat (limited to 'src/filebuf.c')
-rw-r--r--src/filebuf.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/filebuf.c b/src/filebuf.c
index b9b908c8d..5e5db0db6 100644
--- a/src/filebuf.c
+++ b/src/filebuf.c
@@ -466,3 +466,26 @@ int git_filebuf_printf(git_filebuf *file, const char *format, ...)
return res;
}
+int git_filebuf_stats(time_t *mtime, size_t *size, git_filebuf *file)
+{
+ int res;
+ struct stat st;
+
+ if (file->fd_is_open)
+ res = p_fstat(file->fd, &st);
+ else
+ res = p_stat(file->path_original, &st);
+
+ if (res < 0) {
+ giterr_set(GITERR_OS, "Could not get stat info for '%s'",
+ file->path_original);
+ return res;
+ }
+
+ if (mtime)
+ *mtime = st.st_mtime;
+ if (size)
+ *size = (size_t)st.st_size;
+
+ return 0;
+}