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/fileops.h
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/fileops.h')
-rw-r--r--src/fileops.h25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/fileops.h b/src/fileops.h
index 19f7ffd54..6437ccc45 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -18,7 +18,8 @@
* Read whole files into an in-memory buffer for processing
*/
extern int git_futils_readbuffer(git_buf *obj, const char *path);
-extern int git_futils_readbuffer_updated(git_buf *obj, const char *path, time_t *mtime, int *updated);
+extern int git_futils_readbuffer_updated(
+ git_buf *obj, const char *path, time_t *mtime, size_t *size, int *updated);
extern int git_futils_readbuffer_fd(git_buf *obj, git_file fd, size_t len);
/**
@@ -266,4 +267,26 @@ extern int git_futils_find_system_file(git_buf *path, const char *filename);
*/
extern int git_futils_fake_symlink(const char *new, const char *old);
+
+typedef struct {
+ git_time_t seconds;
+ git_off_t size;
+ unsigned int ino;
+} git_futils_stat_sig;
+
+/**
+ * Compare stat information for file with reference info.
+ *
+ * Use this as a way to track if a file has changed on disk. This will
+ * return GIT_ENOTFOUND if the file doesn't exist, 0 if the file is up-to-date
+ * with regards to the signature, and 1 if the file needs to reloaded. When
+ * a 1 is returned, the signature will also be updated with the latest data.
+ *
+ * @param sig stat signature structure
+ * @param path path to be statted
+ * @return 0 if up-to-date, 1 if out-of-date, <0 on error
+ */
+extern int git_futils_stat_sig_needs_reload(
+ git_futils_stat_sig *sig, const char *path);
+
#endif /* INCLUDE_fileops_h__ */